Java Code Examples for org.wso2.carbon.user.api.RealmConfiguration#getSecondaryRealmConfig()

The following examples show how to use org.wso2.carbon.user.api.RealmConfiguration#getSecondaryRealmConfig() . 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: UserStoreCountUtils.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get the domain names of user stores which has count functionality enabled
 *
 * @return
 */
public static Set<String> getCountEnabledUserStores() throws UserStoreCounterException {
    RealmConfiguration realmConfiguration;
    Set<String> userStoreList = new HashSet<>();

    try {
        realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();

        while (realmConfiguration != null) {
            if (!Boolean.valueOf(realmConfiguration.getUserStoreProperty(
                    UserCoreConstants.RealmConfig.USER_STORE_DISABLED))) {
                if (StringUtils.isNotEmpty(realmConfiguration.getUserStoreProperty(COUNT_RETRIEVER_CLASS))) {
                    userStoreList.add(realmConfiguration
                            .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME));
                }
            }
            realmConfiguration = realmConfiguration.getSecondaryRealmConfig();
        }
    } catch (UserStoreException e) {
        throw new UserStoreCounterException("Error while getting the count enabled user stores", e);
    }

    return userStoreList;
}
 
Example 2
Source File: UserStoreCountUtils.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static boolean isUserStoreEnabled(String domain) throws UserStoreCounterException {

        RealmConfiguration realmConfiguration;
        boolean isEnabled = false;
        try {
            realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();

            do {
                String userStoreDomain = realmConfiguration.
                        getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);

                if (domain.equals(userStoreDomain)) {
                    isEnabled = !Boolean.valueOf(realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.
                            USER_STORE_DISABLED));
                    break;
                }
                realmConfiguration = realmConfiguration.getSecondaryRealmConfig();
            } while (realmConfiguration != null);

        } catch (UserStoreException e) {
            throw new UserStoreCounterException("Error occurred while getting Secondary Realm Configuration", e);
        }
        return isEnabled;
    }
 
Example 3
Source File: SecondaryUserStoreConfigurationUtil.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public static Map<String, String> getSecondaryUserStorePropertiesFromTenantUserRealm(String userStoreDomain)
        throws IdentityUserStoreMgtException {

    Map<String, String> secondaryUserStoreProperties = null;
    try {
        RealmConfiguration realmConfiguration = UserStoreConfigComponent.getRealmService().getTenantUserRealm(
                getTenantIdInTheCurrentContext()).getRealmConfiguration();
        while (realmConfiguration != null) {
            String domainName = realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig
                    .PROPERTY_DOMAIN_NAME);
            if (StringUtils.equalsIgnoreCase(domainName, userStoreDomain)) {
                secondaryUserStoreProperties = realmConfiguration.getUserStoreProperties();
                break;
            } else {
                realmConfiguration = realmConfiguration.getSecondaryRealmConfig();
            }
        }
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations for user store domain: "
                + userStoreDomain;
        throw new IdentityUserStoreMgtException(errorMessage, e);
    }
    return secondaryUserStoreProperties;
}
 
Example 4
Source File: UserStoreCountUtils.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get the available list of user store domains
 *
 * @return
 * @throws UserStoreCounterException
 */
public static Map<String, RealmConfiguration> getUserStoreList() throws UserStoreCounterException {
    String domain;
    RealmConfiguration realmConfiguration;
    Map<String, RealmConfiguration> userStoreList = new HashMap<>();

    try {
        realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();
        domain = IdentityUtil.getPrimaryDomainName();
        userStoreList.put(domain, realmConfiguration);

        while (realmConfiguration != null) {
            realmConfiguration = realmConfiguration.getSecondaryRealmConfig();
            if (realmConfiguration != null) {
                domain = realmConfiguration
                        .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
                userStoreList.put(domain, realmConfiguration);
            } else {
                break;
            }
        }

    } catch (UserStoreException e) {
        throw new UserStoreCounterException("Error while listing user stores for count functionality", e);
    }

    return userStoreList;
}
 
Example 5
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get a List of existing domain names.
 *
 * @return : list of domain names
 * @throws IdentityUserStoreMgtException
 */
private List<String> getDomainNames() throws IdentityUserStoreMgtException {

    List<String> domains = new ArrayList<String>();

    RealmConfiguration realmConfiguration = null;
    try {
        realmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration();
    } catch (UserStoreException e) {
        throw new IdentityUserStoreMgtException(" Error occurred while retrieving the realm configuration ", e);
    }

    // To add PRIMARY domain to the domains list
    String domain = realmConfiguration.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    if (domain == null) {
        domain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    domains.add(domain);

    RealmConfiguration secondaryRealmConfiguration = realmConfiguration.getSecondaryRealmConfig();
    while (secondaryRealmConfiguration != null) {
        domains.add(secondaryRealmConfiguration.getUserStoreProperty(UserCoreConstants.
                RealmConfig.PROPERTY_DOMAIN_NAME));
        secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
    }
    return domains;
}
 
Example 6
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {

    RealmConfiguration secondaryRealmConfiguration;
    List<UserStoreDTO> domains = new ArrayList<>();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStoreDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration,
                    userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));
            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            domains.add(userStoreDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();
        } while (secondaryRealmConfiguration != null);
    }
    return domains.toArray(new UserStoreDTO[domains.size()]);
}
 
Example 7
Source File: FileBasedUserStoreDAOImpl.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected UserStorePersistanceDTO[] doGetAllUserStores() throws IdentityUserStoreMgtException {

    RealmConfiguration secondaryRealmConfiguration;
    List<UserStorePersistanceDTO> userStorePersistanceDAOList = new ArrayList<>();
    UserStorePersistanceDTO userStorePersistanceDTO = new UserStorePersistanceDTO();
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        throw new IdentityUserStoreMgtException(errorMessage);
    }
    if (secondaryRealmConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("SecondaryRealmConfiguration is null. Can not find any userStore.");
        }
        return new UserStorePersistanceDTO[0];
    } else {
        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();

            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }
            String className = secondaryRealmConfiguration.getUserStoreClass();
            UserStoreDTO userStoreDTO = getUserStoreDTO(secondaryRealmConfiguration, userStoreProperties);
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            MaskedProperty[] maskedProperties = setMaskInUserStoreProperties(secondaryRealmConfiguration,
                    userStoreProperties, ENCRYPTED_PROPERTY_MASK, className);
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));

            // Now revert back to original password.
            for (MaskedProperty maskedProperty : maskedProperties) {
                userStoreProperties.put(maskedProperty.getName(), maskedProperty.getValue());
            }
            userStorePersistanceDTO.setUserStoreDTO(userStoreDTO);
            userStorePersistanceDAOList.add(userStorePersistanceDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();

        } while (secondaryRealmConfiguration != null);
    }
    return userStorePersistanceDAOList.toArray(new UserStorePersistanceDTO[userStorePersistanceDAOList.size()]);
}
 
Example 8
Source File: UserStoreConfigAdminService.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Get details of current secondary user store configurations
 *
 * @return : Details of all the configured secondary user stores
 * @throws UserStoreException
 */
public UserStoreDTO[] getSecondaryRealmConfigurations() throws IdentityUserStoreMgtException {
    ArrayList<UserStoreDTO> domains = new ArrayList<UserStoreDTO>();

    RealmConfiguration secondaryRealmConfiguration = null;
    try {
        secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
                getRealmConfiguration().getSecondaryRealmConfig();
    } catch (UserStoreException e) {
        String errorMessage = "Error while retrieving user store configurations";
        log.error(errorMessage, e);
        throw new IdentityUserStoreMgtException(errorMessage);
    }

    //not editing primary store
    if (secondaryRealmConfiguration == null) {
        return null;
    } else {

        do {
            Map<String, String> userStoreProperties = secondaryRealmConfiguration.getUserStoreProperties();
            UserStoreDTO userStoreDTO = new UserStoreDTO();

            String uuid = userStoreProperties.get(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT);
            if (uuid == null) {
                uuid = UUID.randomUUID().toString();
            }

            String randomPhrase = UserStoreConfigurationConstant.RANDOM_PHRASE_PREFIX + uuid;
            String className = secondaryRealmConfiguration.getUserStoreClass();
            userStoreDTO.setClassName(secondaryRealmConfiguration.getUserStoreClass());
            userStoreDTO.setDescription(secondaryRealmConfiguration.getUserStoreProperty(DESCRIPTION));
            userStoreDTO.setDomainId(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigConstants.DOMAIN_NAME));
            if (userStoreProperties.get(DISABLED) != null) {
                userStoreDTO.setDisabled(Boolean.valueOf(userStoreProperties.get(DISABLED)));
            }
            userStoreProperties.put("Class", className);
            userStoreProperties.put(UserStoreConfigurationConstant.UNIQUE_ID_CONSTANT, uuid);
            RandomPassword[] randomPasswords = getRandomPasswordProperties(className, randomPhrase,
                    secondaryRealmConfiguration);
            if (randomPasswords != null) {
                updatePasswordContainer(randomPasswords, uuid);
            }

            String originalPassword = null;
            if (userStoreProperties.containsKey(UserStoreConfigConstants.connectionPassword)) {
                originalPassword = userStoreProperties.get(UserStoreConfigConstants.connectionPassword);
                userStoreProperties.put(UserStoreConfigConstants.connectionPassword, randomPhrase);
            }
            if (userStoreProperties.containsKey(JDBCRealmConstants.PASSWORD)) {
                originalPassword = userStoreProperties.get(JDBCRealmConstants.PASSWORD);
                userStoreProperties.put(JDBCRealmConstants.PASSWORD, randomPhrase);
            }
            userStoreDTO.setProperties(convertMapToArray(userStoreProperties));

            //Now revert back to original password
            if (userStoreProperties.containsKey(UserStoreConfigConstants.connectionPassword)) {
                if (originalPassword != null) {
                    userStoreProperties.put(UserStoreConfigConstants.connectionPassword, originalPassword);
                }
            }
            if (userStoreProperties.containsKey(JDBCRealmConstants.PASSWORD)) {
                if (originalPassword != null) {
                    userStoreProperties.put(JDBCRealmConstants.PASSWORD, originalPassword);
                }
            }

            domains.add(userStoreDTO);
            secondaryRealmConfiguration = secondaryRealmConfiguration.getSecondaryRealmConfig();

        } while (secondaryRealmConfiguration != null);
    }
    return domains.toArray(new UserStoreDTO[domains.size()]);
}