Search in sources :

Example 1 with UserAdminUserAdminException

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;
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) UserRolePermissionType(com.wso2telco.core.userprofile.util.UserRolePermissionType) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) UserAdminStub(org.wso2.carbon.user.mgt.stub.UserAdminStub) HashMap(java.util.HashMap) UserRoleProsser(com.wso2telco.core.userprofile.prosser.UserRoleProsser) APIConstants(org.wso2.carbon.apimgt.impl.APIConstants) HashSet(java.util.HashSet) CarbonUtils(org.wso2.carbon.utils.CarbonUtils) UIPermissionNode(org.wso2.carbon.user.mgt.stub.types.carbon.UIPermissionNode) Map(java.util.Map) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException) AdminServicePath(com.wso2telco.core.userprofile.util.AdminServicePath) Iterator(java.util.Iterator) Set(java.util.Set) GenaralError(com.wso2telco.core.dbutils.exception.GenaralError) HTTPConstants(org.apache.axis2.transport.http.HTTPConstants) RemoteException(java.rmi.RemoteException) List(java.util.List) HostObjectComponent(org.wso2.carbon.apimgt.hostobjects.internal.HostObjectComponent) BusinessException(com.wso2telco.core.dbutils.exception.BusinessException) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) AxisFault(org.apache.axis2.AxisFault) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) UIPermissionNode(org.wso2.carbon.user.mgt.stub.types.carbon.UIPermissionNode) BusinessException(com.wso2telco.core.dbutils.exception.BusinessException) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException) UserRoleProsser(com.wso2telco.core.userprofile.prosser.UserRoleProsser) RemoteException(java.rmi.RemoteException)

Aggregations

BusinessException (com.wso2telco.core.dbutils.exception.BusinessException)1 GenaralError (com.wso2telco.core.dbutils.exception.GenaralError)1 UserRoleProsser (com.wso2telco.core.userprofile.prosser.UserRoleProsser)1 AdminServicePath (com.wso2telco.core.userprofile.util.AdminServicePath)1 UserRolePermissionType (com.wso2telco.core.userprofile.util.UserRolePermissionType)1 RemoteException (java.rmi.RemoteException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AxisFault (org.apache.axis2.AxisFault)1 HTTPConstants (org.apache.axis2.transport.http.HTTPConstants)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1