use of org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException in project core-util by WSO2Telco.
the class WSO2PermissionBuilder method build.
/**
* This will build the permision tree using given users name
*/
public Map<String, Object> build(final String userName) throws BusinessException {
Map<String, Object> permisionTree = Collections.emptyMap();
RetunEntitiy retunItem = new RetunEntitiy();
try {
UserRoleProsser userRoleRetriever = new UserRoleProsser();
UIPermissionNode uiPermissionTree = null;
List<String> currentUserRoleList = userRoleRetriever.getRolesByUserName(userName);
/**
* None of the roles are assign for the user
*/
if (currentUserRoleList.isEmpty()) {
throw new BusinessException("No roles assigned for user :" + userName);
}
for (Iterator<String> iterator = currentUserRoleList.iterator(); iterator.hasNext(); ) {
String roleName = iterator.next();
UIPermissionNode rolePermissions = userAdminStub.getRolePermissions(roleName);
/**
* if the permission node is empty
*/
if (rolePermissions == null || rolePermissions.getNodeList() == null) {
continue;
}
/**
* filter out ui permission only
*/
Optional<UIPermissionNode> optNode = Arrays.stream(rolePermissions.getNodeList()).filter(rowItem -> rowItem.getDisplayName().equalsIgnoreCase(UserRolePermissionType.UI_PERMISSION.getTObject())).findFirst();
/**
* check for existence of node
*/
if (optNode.isPresent()) {
uiPermissionTree = optNode.get();
if (uiPermissionTree.getNodeList() != null && uiPermissionTree.getNodeList().length > 0) {
retunItem = popUserRolePermissions(uiPermissionTree.getNodeList());
if (retunItem.atLeastOneSelected) {
break;
}
} else {
/**
* if the current role does not contain Ui permission then continue
*/
continue;
}
}
}
if (retunItem.returnMap.isEmpty()) {
throw new BusinessException(UserRolePermissionType.UI_PERMISSION.getTObject() + " not assigned for the user :" + userName + " , assigned roles :[ " + StringUtils.join(currentUserRoleList, ",") + "]");
}
} catch (RemoteException | UserAdminUserAdminException e) {
log.error("UIPermission.build", e);
throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR);
}
if (retunItem.returnMap.isEmpty()) {
log.warn(" No ui permission tree found for " + userName);
return Collections.emptyMap();
} else {
return retunItem.returnMap;
}
}
Aggregations