本文整理汇总了Java中org.opendaylight.controller.sal.authorization.UserLevel类的典型用法代码示例。如果您正苦于以下问题:Java UserLevel类的具体用法?Java UserLevel怎么用?Java UserLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserLevel类属于org.opendaylight.controller.sal.authorization包,在下文中一共展示了UserLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveLocalUserConfig
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@RequestMapping(value = "/users", method = RequestMethod.POST)
@ResponseBody
public String saveLocalUserConfig(
@RequestParam(required = true) String json,
@RequestParam(required = true) String action,
HttpServletRequest request) {
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager == null) {
return "Internal Error";
}
if (!authorize(userManager, UserLevel.NETWORKADMIN, request)) {
return "Operation not permitted";
}
Gson gson = new Gson();
UserConfig config = gson.fromJson(json, UserConfig.class);
Status result = (action.equals("add")) ? userManager
.addLocalUser(config) : userManager.removeLocalUser(config);
return result.getDescription();
}
示例2: removeLocalUser
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@RequestMapping(value = "/users/{username}", method = RequestMethod.POST)
@ResponseBody
public String removeLocalUser(@PathVariable("username") String userName,
HttpServletRequest request) {
String username = request.getUserPrincipal().getName();
if (username.equals(userName)) {
return "Invalid Request: User cannot delete itself";
}
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager == null) {
return "Internal Error";
}
if (!authorize(userManager, UserLevel.NETWORKADMIN, request)) {
return "Operation not permitted";
}
return userManager.removeLocalUser(userName).getDescription();
}
示例3: changePassword
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@RequestMapping(value = "/users/password/{username}", method = RequestMethod.POST)
@ResponseBody
public Status changePassword(@PathVariable("username") String username, HttpServletRequest request,
@RequestParam("currentPassword") String currentPassword, @RequestParam("newPassword") String newPassword) {
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager == null) {
return new Status(StatusCode.GONE, "User Manager not found");
}
if (!authorize(userManager, UserLevel.NETWORKADMIN, request)) {
return new Status(StatusCode.FORBIDDEN, "Operation not permitted");
}
if (newPassword.isEmpty()) {
return new Status(StatusCode.BADREQUEST, "Empty passwords not allowed");
}
Status status = userManager.changeLocalUserPassword(username, currentPassword, newPassword);
return status;
}
示例4: testGetUserLevel
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Test
public void testGetUserLevel() {
List<String> roles = new ArrayList<String>(2);
roles.add(UserLevel.SYSTEMADMIN.toString());
roles.add("App1_supervisor");
um.addLocalUser(new UserConfig("Jack", "password", roles));
um.authenticate("Jack", "password");
roles.clear();
roles.add("App2Admin");
roles.add(UserLevel.NETWORKOPERATOR.toString());
um.addLocalUser(new UserConfig("John", "password", roles));
// Run the check on authenticated user
Assert.assertTrue(um.getUserLevel("Jack") == UserLevel.SYSTEMADMIN);
// Run the check on configured users
Assert.assertTrue(um.getUserLevel("John") == UserLevel.NETWORKOPERATOR);
// Run the check on local authorized users
Assert.assertTrue(um.getUserLevel("Andrew") == UserLevel.NETWORKOPERATOR);
// Non locally known user
Assert.assertTrue(um.getUserLevel("Tom") == UserLevel.NOUSER);
}
示例5: save
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody
public String save(HttpServletRequest request) {
String username = request.getUserPrincipal().getName();
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager == null) {
return "User Manager is not available";
}
UserLevel level = userManager.getUserLevel(username);
if (level == UserLevel.NETWORKOPERATOR) {
return "Save not permitted for Operator";
}
Status status = new Status(StatusCode.UNAUTHORIZED,
"Operation not allowed for current user");
if (level == UserLevel.NETWORKADMIN || level == UserLevel.SYSTEMADMIN) {
IConfigurationService configService = (IConfigurationService) ServiceHelper
.getGlobalInstance(IConfigurationService.class, this);
if (configService != null) {
status = configService.saveConfigurations();
}
}
return status.getDescription();
}
示例6: authorize
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
/**
* Is the operation permitted for the given level
*
* @param level
*/
private boolean authorize(IUserManager userManager, UserLevel level,
HttpServletRequest request) {
String username = request.getUserPrincipal().getName();
UserLevel userLevel = userManager.getUserLevel(username);
return userLevel.toNumber() <= level.toNumber();
}
示例7: getPrincipal
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Override
protected Principal getPrincipal(String username) {
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);
if (userManager != null) {
List<String> controllerRoles = new ArrayList<String>();
for (UserLevel level : userManager.getUserLevels(username)) {
controllerRoles.add(level.toString());
}
return new GenericPrincipal(username, "", controllerRoles);
} else {
throw new RuntimeException("User Manager reference is null");
}
}
示例8: testGetGrantedAuthorities
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Test
public void testGetGrantedAuthorities() {
List<GrantedAuthority> gaList = user
.getGrantedAuthorities(UserLevel.NETWORKOPERATOR);
Assert.assertTrue(gaList.get(0).getAuthority()
.equals("ROLE_NETWORK-OPERATOR"));
}
示例9: AuthorizationConfigTest
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Test
public void AuthorizationConfigTest() {
AuthorizationConfig authConfig;
List<String> roles = new ArrayList<String>();
// test isValid
roles.add(UserLevel.SYSTEMADMIN.toString());
authConfig = new AuthorizationConfig(null, roles);
assertFalse(authConfig.validate().isSuccess());
authConfig = new AuthorizationConfig("admin", new ArrayList<String>());
assertFalse(authConfig.validate().isSuccess());
authConfig = new AuthorizationConfig("admin", roles);
assertTrue(authConfig.validate().isSuccess());
}
示例10: isRoleInUse
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Override
public boolean isRoleInUse(String role) {
if (role == null || role.isEmpty()) {
return false;
}
// Check against controller roles
if (role.equals(UserLevel.SYSTEMADMIN.toString())
|| role.equals(UserLevel.NETWORKADMIN.toString())
|| role.equals(UserLevel.NETWORKOPERATOR.toString())) {
return true;
}
// Check if container roles
if (containerAuthorizationClient != null) {
if (containerAuthorizationClient.isApplicationRole(role)) {
return true;
}
}
// Finally if application role
if (applicationAuthorizationClients != null) {
for (IResourceAuthorization client : this.applicationAuthorizationClients) {
if (client.isApplicationRole(role)) {
return true;
}
}
}
return false;
}
示例11: testAuthenticateStringString
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
/**
* Test method for
* {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#authenticate(java.lang.String, java.lang.String)}
* .
*/
@Test
public void testAuthenticateStringString() {
List<String> roles = new ArrayList<String>(1);
roles.add(UserLevel.SYSTEMADMIN.toString());
UserConfig uc = new UserConfig("administrator", "admin", roles);
um.addLocalUser(uc);
AuthResultEnum authResult = um.authenticate("administrator", "admin");
assertEquals(authResult, AuthResultEnum.AUTH_ACCEPT_LOC);
}
示例12: testAddRemoveLocalUser
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
/**
* Test method for
* {@link org.opendaylight.controller.usermanager.internal.UserManagerImpl#addRemoveLocalUser(org.opendaylight.controller.usermanager.org.opendaylight.controller.usermanager.internal.UserConfig, boolean)}
* .
*/
@Test
public void testAddRemoveLocalUser() {
List<String> roles = new ArrayList<String>(1);
roles.add(UserLevel.SYSTEMADMIN.toString());
UserConfig uc = new UserConfig("sysadmin", "7029,7455,8165,7029,7881",
roles);
um.addLocalUser(uc);
assertTrue(um.getLocalUserList().contains(uc));
um.removeLocalUser(uc);
assertFalse(um.getLocalUserList().contains(uc));
}
示例13: isAuthorized
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
@Override
public boolean isAuthorized(UserLevel userLevel) {
return userLevel.ordinal() <= AUTH_LEVEL.ordinal();
}
示例14: getGrantedAuthorities
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
public List<GrantedAuthority> getGrantedAuthorities(UserLevel usrLvl) {
List<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority(new ODLUserLevel(usrLvl)
.getAuthority()));
return roles;
}
示例15: ODLUserLevel
import org.opendaylight.controller.sal.authorization.UserLevel; //导入依赖的package包/类
public ODLUserLevel(UserLevel userLevel) {
this.userLevel = userLevel;
}