Java Code Examples for org.wso2.carbon.user.core.UserStoreManager#getSecondaryUserStoreManager()

The following examples show how to use org.wso2.carbon.user.core.UserStoreManager#getSecondaryUserStoreManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserRealmProxy.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 *  Checks whether the user store containing the given role name supports filter and limit.
 */
private boolean canLimitAndFilterUsersFromUMLevel(String roleName, UserStoreManager userStoreManager) {

    // Currently filter and limit for users in the role is supported only with the JDBC user store manager.
    boolean canLimitAndFilterWithUM = false;

    int domainSeparatorIndex = roleName.indexOf(CarbonConstants.DOMAIN_SEPARATOR);
    if (domainSeparatorIndex > 0) {
        String domainInRole = roleName.substring(0, domainSeparatorIndex);
        UserStoreManager secondaryUserStoreManager = userStoreManager.getSecondaryUserStoreManager(domainInRole);
        if (secondaryUserStoreManager != null) {
            canLimitAndFilterWithUM = secondaryUserStoreManager instanceof JDBCUserStoreManager;
        }
    } else {
        canLimitAndFilterWithUM = userStoreManager instanceof JDBCUserStoreManager;
    }
    return canLimitAndFilterWithUM;
}
 
Example 2
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private static UserStoreManager getSecondaryUserStoreManager(String userStoreDomain) throws UserStoreException {

        UserStoreManager secondaryUserStoreManager = null;
        UserRealm userRealm = (UserRealm) UserStoreConfigComponent.getRealmService().getTenantUserRealm(
                getTenantIdInTheCurrentContext());
        UserStoreManager userStoreManager = userRealm.getUserStoreManager();
        if (userStoreManager != null) {
            secondaryUserStoreManager = userStoreManager.getSecondaryUserStoreManager(userStoreDomain);
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Could not locate user store manager for user store domain: " + userStoreDomain);
            }
        }
        return secondaryUserStoreManager;
    }
 
Example 3
Source File: UserRegistrationService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * This service method will return back all available password validation regular expressions
 * against the corresponding domain names.
 *
 * @return
 * @throws IdentityException
 */
public PasswordRegExDTO[] getPasswordRegularExpressions() throws IdentityException {
    UserRealm realm = null;
    realm = IdentityTenantUtil.getRealm(null, null);
    List<PasswordRegExDTO> passwordRegExList = new ArrayList<PasswordRegExDTO>();
    PasswordRegExDTO passwordRegEx;

    try {
        UserStoreManager manager = realm.getUserStoreManager();
        String domainName;
        String regEx;

        while (manager != null) {
            domainName = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
            regEx = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_JS_REG_EX);
            if (regEx != null && regEx.length() > 0) {
                passwordRegEx = new PasswordRegExDTO();
                passwordRegEx.setDomainName(domainName);
                passwordRegEx.setRegEx(regEx);
                passwordRegExList.add(passwordRegEx);
            }
            manager = manager.getSecondaryUserStoreManager();
        }
    } catch (UserStoreException e) {
        log.error(e);
        throw IdentityException.error(
                "Error occured while loading password validation regular expressions.");
    }
    return passwordRegExList.toArray(new PasswordRegExDTO[passwordRegExList.size()]);
}
 
Example 4
Source File: UserRealmProxy.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public void bulkImportUsers(String userStoreDomain, String fileName, InputStream inStream, String defaultPassword)
        throws UserAdminException {
    try {
        BulkImportConfig config = new BulkImportConfig(inStream, fileName);
        if (defaultPassword != null && defaultPassword.trim().length() > 0) {
            config.setDefaultPassword(defaultPassword.trim());
        }
        if (StringUtils.isNotEmpty(userStoreDomain)) {
            config.setUserStoreDomain(userStoreDomain);
        }

        UserStoreManager userStore = this.realm.getUserStoreManager();
        userStore = userStore.getSecondaryUserStoreManager(userStoreDomain);

        if (fileName.endsWith("csv")) {
            UserBulkImport csvAdder = new CSVUserBulkImport(config);
            csvAdder.addUserList(userStore);
        } else if (fileName.endsWith("xls") || fileName.endsWith("xlsx")) {
            UserBulkImport excelAdder = new ExcelUserBulkImport(config);
            excelAdder.addUserList(userStore);
        } else {
            throw new UserAdminException("Unsupported format");
        }
    } catch (UserStoreException e) {
        // previously logged so logging not needed
        throw new UserAdminException(e.getMessage(), e);
    }

}
 
Example 5
Source File: MultipleCredentialsUserProxy.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private MultipleCredentialUserStoreManager getUserStoreManager() throws UserStoreException {

        if (userStoreManager == null) {
            synchronized (lock) {
                if (userStoreManager == null) {

                    // read parameter from axis2.xml
                    AxisConfiguration axisConfiguration =
                            CarbonConfigurationContextFactory.getConfigurationContext()
                                    .getAxisConfiguration();
                    String multipleCredentialDomain =
                            (String) axisConfiguration.getParameterValue(DOMAIN_PARAMETER);
                    if (multipleCredentialDomain == null) {
                        multipleCredentialDomain = MULTIPLE_CREDENTIAL_DOMAIN_NAME;
                    }

                    UserStoreManager storeManager = realm.getUserStoreManager();
                    UserStoreManager second =
                            storeManager.getSecondaryUserStoreManager(multipleCredentialDomain);
                    if (second != null) {
                        storeManager = second;
                    }

                    if (!(storeManager instanceof MultipleCredentialUserStoreManager)) {
                        String msg = "User store does not support multiple credentials.";
                        MultipleCredentialsNotSupportedException e =
                                new MultipleCredentialsNotSupportedException(
                                        msg);
                        log.fatal(msg, e);
                        throw e;
                    }

                    userStoreManager = (MultipleCredentialUserStoreManager) storeManager;

                }
            }
        }

        return userStoreManager;
    }
 
Example 6
Source File: UserRegistrationService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * This service method will return back all available password validation regular expressions
 * against the corresponding domain names.
 *
 * @return
 * @throws IdentityException
 */
public PasswordRegExDTO[] getPasswordRegularExpressions() throws IdentityException {
    UserRealm realm = null;
    realm = IdentityTenantUtil.getRealm(null, null);
    List<PasswordRegExDTO> passwordRegExList = new ArrayList<PasswordRegExDTO>();
    PasswordRegExDTO passwordRegEx;

    try {
        UserStoreManager manager = realm.getUserStoreManager();
        String domainName;
        String regEx;

        while (manager != null) {
            domainName = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
            regEx = manager.getRealmConfiguration().getUserStoreProperty(
                    UserCoreConstants.RealmConfig.PROPERTY_JS_REG_EX);
            if (regEx != null && regEx.length() > 0) {
                passwordRegEx = new PasswordRegExDTO();
                passwordRegEx.setDomainName(domainName);
                passwordRegEx.setRegEx(regEx);
                passwordRegExList.add(passwordRegEx);
            }
            manager = manager.getSecondaryUserStoreManager();
        }
    } catch (UserStoreException e) {
        log.error(e);
        throw IdentityException.error(
                "Error occured while loading password validation regular expressions.");
    }
    return passwordRegExList.toArray(new PasswordRegExDTO[passwordRegExList.size()]);
}
 
Example 7
Source File: UserRealmProxy.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public void bulkImportUsers(String userStoreDomain, String fileName, InputStream inStream, String defaultPassword)
        throws UserAdminException {
    try {
        BulkImportConfig config = new BulkImportConfig(inStream, fileName);
        if (defaultPassword != null && defaultPassword.trim().length() > 0) {
            config.setDefaultPassword(defaultPassword.trim());
        }
        if (StringUtils.isNotEmpty(userStoreDomain)) {
            config.setUserStoreDomain(userStoreDomain);
        }

        UserStoreManager userStore = this.realm.getUserStoreManager();
        userStore = userStore.getSecondaryUserStoreManager(userStoreDomain);

        if (fileName.endsWith("csv")) {
            CSVUserBulkImport csvAdder = new CSVUserBulkImport(config);
            csvAdder.addUserList(userStore);
        } else if (fileName.endsWith("xls") || fileName.endsWith("xlsx")) {
            ExcelUserBulkImport excelAdder = new ExcelUserBulkImport(config);
            excelAdder.addUserList(userStore);
        } else {
            throw new UserAdminException("Unsupported format");
        }
    } catch (UserStoreException e) {
        // previously logged so logging not needed
        throw new UserAdminException(e.getMessage(), e);
    }

}
 
Example 8
Source File: MultipleCredentialsUserProxy.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private MultipleCredentialUserStoreManager getUserStoreManager() throws UserStoreException {

        if (userStoreManager == null) {
            synchronized (lock) {
                if (userStoreManager == null) {

                    // read parameter from axis2.xml
                    AxisConfiguration axisConfiguration =
                            CarbonConfigurationContextFactory.getConfigurationContext()
                                    .getAxisConfiguration();
                    String multipleCredentialDomain =
                            (String) axisConfiguration.getParameterValue(DOMAIN_PARAMETER);
                    if (multipleCredentialDomain == null) {
                        multipleCredentialDomain = MULTIPLE_CREDENTIAL_DOMAIN_NAME;
                    }

                    UserStoreManager storeManager = realm.getUserStoreManager();
                    UserStoreManager second =
                            storeManager.getSecondaryUserStoreManager(multipleCredentialDomain);
                    if (second != null) {
                        storeManager = second;
                    }

                    if (!(storeManager instanceof MultipleCredentialUserStoreManager)) {
                        String msg = "User store does not support multiple credentials.";
                        MultipleCredentialsNotSupportedException e =
                                new MultipleCredentialsNotSupportedException(
                                        msg);
                        log.fatal(msg, e);
                        throw e;
                    }

                    userStoreManager = (MultipleCredentialUserStoreManager) storeManager;

                }
            }
        }

        return userStoreManager;
    }