本文整理汇总了Java中org.wso2.carbon.user.api.UserStoreManager.getRoleListOfUser方法的典型用法代码示例。如果您正苦于以下问题:Java UserStoreManager.getRoleListOfUser方法的具体用法?Java UserStoreManager.getRoleListOfUser怎么用?Java UserStoreManager.getRoleListOfUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.user.api.UserStoreManager
的用法示例。
在下文中一共展示了UserStoreManager.getRoleListOfUser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerApiAccessRoles
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
public static void registerApiAccessRoles(String user) {
UserStoreManager userStoreManager = null;
try {
userStoreManager = getUserStoreManager();
String[] userList = new String[]{user};
if (userStoreManager != null) {
String rolesOfUser[] = userStoreManager.getRoleListOfUser(user);
if (!userStoreManager.isExistingRole(Constants.DEFAULT_ROLE_NAME)) {
userStoreManager.addRole(Constants.DEFAULT_ROLE_NAME, userList, Constants.DEFAULT_PERMISSION);
} else if (rolesOfUser != null && Arrays.asList(rolesOfUser).contains(Constants.DEFAULT_ROLE_NAME)) {
return;
} else {
userStoreManager.updateUserListOfRole(Constants.DEFAULT_ROLE_NAME, new String[0], userList);
}
}
} catch (UserStoreException e) {
log.error("Error while creating a role and adding a user for virtual_firealarm.", e);
}
}
示例2: getRefinedListOfRolesOfUser
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* Get the List of userRoles except the Internal/everyone role
*
* @param userStoreManager UserStoreManager
* @param username Username of the user
* @return String[]
* @throws UserManagerException
*/
private static String[] getRefinedListOfRolesOfUser(UserStoreManager userStoreManager, String username)
throws UserManagerException {
ArrayList<String> rolesWithoutEveryoneRole = new ArrayList<String>();
try {
String[] allUserRoles = userStoreManager.getRoleListOfUser(username);
for (String role : allUserRoles) {
if (!role.equals(INTERNAL_EVERYONE_ROLE)) {
rolesWithoutEveryoneRole.add(role);
}
}
String[] rolesWithoutEveryoneRoleArray = new String[rolesWithoutEveryoneRole.size()];
return rolesWithoutEveryoneRole.toArray(rolesWithoutEveryoneRoleArray);
} catch (UserStoreException e) {
String msg = "Error in listing the roles of user " + username + " in User Store";
log.error(msg, e);
throw new UserManagerException(msg, e);
}
}
示例3: isUserAuthorized
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
/**
* @param applicationName
* @param username
* @return
* @throws IdentityApplicationManagementException
*/
public static boolean isUserAuthorized(String applicationName, String username)
throws IdentityApplicationManagementException {
String applicationRoleName = getAppRoleName(applicationName);
try {
if (log.isDebugEnabled()) {
log.debug("Checking whether user has role : " + applicationRoleName + " by retrieving role list of " +
"user : " + username);
}
UserStoreManager userStoreManager = CarbonContext.getThreadLocalCarbonContext().getUserRealm()
.getUserStoreManager();
if (userStoreManager instanceof AbstractUserStoreManager) {
return ((AbstractUserStoreManager) userStoreManager).isUserInRole(username, applicationRoleName);
}
String[] userRoles = userStoreManager.getRoleListOfUser(username);
for (String userRole : userRoles) {
if (applicationRoleName.equals(userRole)) {
return true;
}
}
} catch (UserStoreException e) {
throw new IdentityApplicationManagementException("Error while checking authorization for user: " +
username + " for application: " + applicationName, e);
}
return false;
}
示例4: getFilteredRoles
import org.wso2.carbon.user.api.UserStoreManager; //导入方法依赖的package包/类
private List<String> getFilteredRoles(UserStoreManager userStoreManager, String username)
throws UserStoreException {
String[] roleListOfUser;
roleListOfUser = userStoreManager.getRoleListOfUser(username);
List<String> filteredRoles = new ArrayList<>();
for (String role : roleListOfUser) {
if (!(role.startsWith("Internal/") || role.startsWith("Authentication/"))) {
filteredRoles.add(role);
}
}
return filteredRoles;
}