Search in sources :

Example 1 with UserStoreInfo

use of org.wso2.carbon.user.mgt.common.UserStoreInfo in project carbon-identity-framework by wso2.

the class UserRealmProxy method getUserRealmInfo.

public UserRealmInfo getUserRealmInfo() throws UserAdminException {
    UserRealmInfo userRealmInfo = new UserRealmInfo();
    String userName = CarbonContext.getThreadLocalCarbonContext().getUsername();
    try {
        RealmConfiguration realmConfig = realm.getRealmConfiguration();
        if (realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/users", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/passwords", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/usermgt/view", CarbonConstants.UI_PERMISSION_ACTION) || realm.getAuthorizationManager().isUserAuthorized(userName, "/permission/admin/manage/identity/rolemgt/view", CarbonConstants.UI_PERMISSION_ACTION)) {
            userRealmInfo.setAdminRole(realmConfig.getAdminRoleName());
            userRealmInfo.setAdminUser(realmConfig.getAdminUserName());
            userRealmInfo.setEveryOneRole(realmConfig.getEveryOneRoleName());
            ClaimMapping[] defaultClaims = realm.getClaimManager().getAllClaimMappings(UserCoreConstants.DEFAULT_CARBON_DIALECT);
            if (ArrayUtils.isNotEmpty(defaultClaims)) {
                Arrays.sort(defaultClaims, new ClaimMappingsComparator());
            }
            List<String> fullClaimList = new ArrayList<String>();
            List<String> requiredClaimsList = new ArrayList<String>();
            List<String> defaultClaimList = new ArrayList<String>();
            for (ClaimMapping claimMapping : defaultClaims) {
                Claim claim = claimMapping.getClaim();
                fullClaimList.add(claim.getClaimUri());
                if (claim.isRequired()) {
                    requiredClaimsList.add(claim.getClaimUri());
                }
                if (claim.isSupportedByDefault()) {
                    defaultClaimList.add(claim.getClaimUri());
                }
            }
            userRealmInfo.setUserClaims(fullClaimList.toArray(new String[fullClaimList.size()]));
            userRealmInfo.setRequiredUserClaims(requiredClaimsList.toArray(new String[requiredClaimsList.size()]));
            userRealmInfo.setDefaultUserClaims(defaultClaimList.toArray(new String[defaultClaimList.size()]));
        }
        List<UserStoreInfo> storeInfoList = new ArrayList<UserStoreInfo>();
        List<String> domainNames = new ArrayList<String>();
        RealmConfiguration secondaryConfig = realmConfig;
        UserStoreManager secondaryManager = realm.getUserStoreManager();
        while (true) {
            secondaryConfig = secondaryManager.getRealmConfiguration();
            UserStoreInfo userStoreInfo = getUserStoreInfo(secondaryConfig, secondaryManager);
            if (secondaryConfig.isPrimary()) {
                userRealmInfo.setPrimaryUserStoreInfo(userStoreInfo);
            }
            storeInfoList.add(userStoreInfo);
            userRealmInfo.setBulkImportSupported(secondaryManager.isBulkImportSupported());
            String domainName = secondaryConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
            if (domainName != null && domainName.trim().length() > 0) {
                domainNames.add(domainName.toUpperCase());
            }
            secondaryManager = secondaryManager.getSecondaryUserStoreManager();
            if (secondaryManager == null) {
                break;
            }
        }
        if (storeInfoList.size() > 1) {
            userRealmInfo.setMultipleUserStore(true);
        }
        userRealmInfo.setUserStoresInfo(storeInfoList.toArray(new UserStoreInfo[storeInfoList.size()]));
        userRealmInfo.setDomainNames(domainNames.toArray(new String[domainNames.size()]));
        String itemsPerPageString = realmConfig.getRealmProperty("MaxItemsPerUserMgtUIPage");
        int itemsPerPage = 15;
        try {
            itemsPerPage = Integer.parseInt(itemsPerPageString);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Error parsing number of items per page, using default value", e);
            }
        }
        userRealmInfo.setMaxItemsPerUIPage(itemsPerPage);
        String maxPageInCacheString = realmConfig.getRealmProperty("MaxUserMgtUIPagesInCache");
        int maxPagesInCache = 6;
        try {
            maxPagesInCache = Integer.parseInt(maxPageInCacheString);
        } catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Error parsing number of maximum pages in cache, using default value", e);
            }
        }
        userRealmInfo.setMaxUIPagesInCache(maxPagesInCache);
        String enableUIPageCacheString = realmConfig.getRealmProperty("EnableUserMgtUIPageCache");
        boolean enableUIPageCache = true;
        if (FALSE.equals(enableUIPageCacheString)) {
            enableUIPageCache = false;
        }
        userRealmInfo.setEnableUIPageCache(enableUIPageCache);
    } catch (Exception e) {
        // previously logged so logging not needed
        throw new UserAdminException(e.getMessage(), e);
    }
    return userRealmInfo;
}
Also used : UserStoreInfo(org.wso2.carbon.user.mgt.common.UserStoreInfo) ArrayList(java.util.ArrayList) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) UserStoreManager(org.wso2.carbon.user.core.UserStoreManager) JDBCUserStoreManager(org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) RegistryException(org.wso2.carbon.registry.api.RegistryException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) ClaimMapping(org.wso2.carbon.user.api.ClaimMapping) UserRealmInfo(org.wso2.carbon.user.mgt.common.UserRealmInfo) Claim(org.wso2.carbon.user.api.Claim)

Example 2 with UserStoreInfo

use of org.wso2.carbon.user.mgt.common.UserStoreInfo in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceClient method getUserStoreDomains.

/**
 * Get User Store Domains
 *
 * @return
 * @throws AxisFault
 */
public String[] getUserStoreDomains() throws AxisFault {
    try {
        List<String> readWriteDomainNames = new ArrayList<String>();
        UserStoreInfo[] storesInfo = userAdminStub.getUserRealmInfo().getUserStoresInfo();
        for (UserStoreInfo storeInfo : storesInfo) {
            if (!storeInfo.getReadOnly()) {
                readWriteDomainNames.add(storeInfo.getDomainName());
            }
        }
        return readWriteDomainNames.toArray(new String[readWriteDomainNames.size()]);
    } catch (RemoteException | UserAdminUserAdminException e) {
        throw new AxisFault("Error occurred while retrieving Read-Write User Store Domain IDs for logged-in" + " user's tenant realm");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) UserStoreInfo(org.wso2.carbon.user.mgt.stub.types.carbon.UserStoreInfo) ArrayList(java.util.ArrayList) UserAdminUserAdminException(org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException) RemoteException(java.rmi.RemoteException)

Example 3 with UserStoreInfo

use of org.wso2.carbon.user.mgt.common.UserStoreInfo in project carbon-identity-framework by wso2.

the class UserRealmProxy method getUserStoreInfo.

private UserStoreInfo getUserStoreInfo(RealmConfiguration realmConfig, UserStoreManager manager) throws UserAdminException {
    try {
        UserStoreInfo info = new UserStoreInfo();
        info.setReadOnly(manager.isReadOnly());
        boolean readRolesEnabled = Boolean.parseBoolean(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.READ_GROUPS_ENABLED));
        info.setReadGroupsEnabled(readRolesEnabled);
        boolean writeRolesEnabled = Boolean.parseBoolean(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.WRITE_GROUPS_ENABLED));
        info.setWriteGroupsEnabled(!manager.isReadOnly() && readRolesEnabled && writeRolesEnabled);
        info.setPasswordsExternallyManaged(realmConfig.isPasswordsExternallyManaged());
        info.setPasswordRegEx(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_JS_REG_EX));
        info.setPasswordRegExViolationErrorMsg(realmConfig.getUserStoreProperty("PasswordJavaRegExViolationErrorMsg"));
        // TODO  Need to get value from UserCoreConstants.RealmConfig.PROPERTY_PASSWORD_ERROR_MSG
        info.setUsernameRegExViolationErrorMsg(realmConfig.getUserStoreProperty("UsernameJavaRegExViolationErrorMsg"));
        // TODO  Need to get value from UserCoreConstants.RealmConfig.PROPERTY_PASSWORD_ERROR_MSG
        info.setUserNameRegEx(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_USER_NAME_JS_REG_EX));
        info.setRoleNameRegEx(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_ROLE_NAME_JS_REG_EX));
        info.setExternalIdP(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_EXTERNAL_IDP));
        info.setBulkImportSupported(this.isBulkImportSupported(realmConfig));
        info.setDomainName(realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
        boolean caseSensitiveUsername = IdentityUtil.isUserStoreCaseSensitive(manager);
        info.setCaseSensitiveUsername(caseSensitiveUsername);
        return info;
    } catch (UserStoreException e) {
        // previously logged so logging not needed
        String domainName = manager.getRealmConfiguration().getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
        String errorMsg = "Error while getting user realm information for domain '" + domainName + "' : " + e.getMessage();
        throw new UserAdminException(errorMsg, e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new UserAdminException(e.getMessage(), e);
    }
}
Also used : UserStoreInfo(org.wso2.carbon.user.mgt.common.UserStoreInfo) UserStoreException(org.wso2.carbon.user.core.UserStoreException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) UserAdminException(org.wso2.carbon.user.mgt.common.UserAdminException) RegistryException(org.wso2.carbon.registry.api.RegistryException) UserStoreException(org.wso2.carbon.user.core.UserStoreException)

Example 4 with UserStoreInfo

use of org.wso2.carbon.user.mgt.common.UserStoreInfo in project carbon-identity-framework by wso2.

the class IdentityProviderMgtServiceClient method getUserStoreDomains.

/**
 * Retrieve the user store domains.
 *
 * @return Array of user store domains.
 * @throws Exception if an error occurs while retrieving user store domains.
 */
public String[] getUserStoreDomains() throws Exception {
    try {
        List<String> readWriteDomainNames = new ArrayList<String>();
        UserStoreInfo[] storesInfo = userAdminStub.getUserRealmInfo().getUserStoresInfo();
        for (UserStoreInfo storeInfo : storesInfo) {
            if (!storeInfo.getReadOnly()) {
                readWriteDomainNames.add(storeInfo.getDomainName());
            }
        }
        return readWriteDomainNames.toArray(new String[readWriteDomainNames.size()]);
    } catch (Exception e) {
        log.error("Error in retrieving User Store Domain IDs", e);
        throw new Exception("Error occurred while retrieving Read-Write User Store Domain IDs " + "for logged-in user's tenant realm", e);
    }
}
Also used : UserStoreInfo(org.wso2.carbon.user.mgt.stub.types.carbon.UserStoreInfo) ArrayList(java.util.ArrayList) IdentityException(org.wso2.carbon.idp.mgt.ui.util.IdentityException) RemoteException(java.rmi.RemoteException) IdentityProviderMgtServiceIdentityProviderManagementExceptionException(org.wso2.carbon.idp.mgt.stub.IdentityProviderMgtServiceIdentityProviderManagementExceptionException)

Example 5 with UserStoreInfo

use of org.wso2.carbon.user.mgt.common.UserStoreInfo in project product-is by wso2.

the class IdentityProviderMgtServiceClient method getUserStoreDomains.

/**
 * @return
 * @throws Exception
 */
public String[] getUserStoreDomains() throws Exception {
    try {
        List<String> readWriteDomainNames = new ArrayList<String>();
        UserStoreInfo[] storesInfo = userAdminStub.getUserRealmInfo().getUserStoresInfo();
        for (UserStoreInfo storeInfo : storesInfo) {
            if (!storeInfo.getReadOnly()) {
                readWriteDomainNames.add(storeInfo.getDomainName());
            }
        }
        return readWriteDomainNames.toArray(new String[readWriteDomainNames.size()]);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new Exception("Error occurred while retrieving Read-Write User Store Domain IDs for logged-in user's tenant realm");
    }
}
Also used : UserStoreInfo(org.wso2.carbon.user.mgt.stub.types.carbon.UserStoreInfo)

Aggregations

ArrayList (java.util.ArrayList)6 UserStoreInfo (org.wso2.carbon.user.mgt.stub.types.carbon.UserStoreInfo)6 RemoteException (java.rmi.RemoteException)4 IdentityApplicationManagementServiceIdentityApplicationManagementClientException (org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementClientException)2 IdentityApplicationManagementServiceIdentityApplicationManagementException (org.wso2.carbon.identity.application.mgt.stub.IdentityApplicationManagementServiceIdentityApplicationManagementException)2 RegistryException (org.wso2.carbon.registry.api.RegistryException)2 UserStoreException (org.wso2.carbon.user.core.UserStoreException)2 UserAdminException (org.wso2.carbon.user.mgt.common.UserAdminException)2 UserStoreInfo (org.wso2.carbon.user.mgt.common.UserStoreInfo)2 AxisFault (org.apache.axis2.AxisFault)1 IdentityProviderMgtServiceIdentityProviderManagementExceptionException (org.wso2.carbon.idp.mgt.stub.IdentityProviderMgtServiceIdentityProviderManagementExceptionException)1 IdentityException (org.wso2.carbon.idp.mgt.ui.util.IdentityException)1 Claim (org.wso2.carbon.user.api.Claim)1 ClaimMapping (org.wso2.carbon.user.api.ClaimMapping)1 RealmConfiguration (org.wso2.carbon.user.api.RealmConfiguration)1 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)1 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)1 JDBCUserStoreManager (org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager)1 UserRealmInfo (org.wso2.carbon.user.mgt.common.UserRealmInfo)1 UserAdminUserAdminException (org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException)1