Search in sources :

Example 6 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class UserStoreConfigAdminService method deleteUserStoresSetFromRepository.

/**
 * Delete the given list of user stores from any repository
 *
 * @param userStoreDTOs an array instance of {@link UserStoreDTO}
 * @throws IdentityUserStoreMgtException throws when an error occured while deleting the user store.
 */
public void deleteUserStoresSetFromRepository(UserStoreDTO[] userStoreDTOs) throws IdentityUserStoreMgtException {
    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled()) {
        for (String repositoryClass : UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories().keySet()) {
            List<String> domains = new ArrayList<>();
            for (UserStoreDTO userStoreDTO : userStoreDTOs) {
                if (repositoryClass.equals(userStoreDTO.getRepositoryClass())) {
                    domains.add(userStoreDTO.getDomainId());
                }
            }
            if (CollectionUtils.isNotEmpty(domains)) {
                AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories().get(repositoryClass);
                try {
                    userStoreDAOFactory.getInstance().deleteUserStores(domains.toArray(new String[0]));
                } catch (IdentityUserStoreClientException e) {
                    throw buildIdentityUserStoreMgtException(e, "Error while deleting the userstore list.");
                }
            }
        }
    } else {
        List<String> domainList = new ArrayList<>();
        for (UserStoreDTO userStoreDTO : userStoreDTOs) {
            if (StringUtils.equals(userStoreDTO.getRepositoryClass(), FILE_BASED_REPOSITORY_CLASS)) {
                domainList.add(userStoreDTO.getDomainId());
            }
        }
        String[] domains = domainList.toArray(new String[0]);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Attempting to remove " + "user-stores with file-based configurations. For user-stores " + String.join(",", domainList));
        }
        deleteUserStoresSet(domains);
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)

Example 7 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class UserStoreConfigServiceImpl method getUserStore.

@Override
public UserStoreDTO getUserStore(String domain) throws IdentityUserStoreMgtException {
    UserStoreDTO[] userStoreDTOS = new UserStoreDTO[0];
    Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories();
    for (Map.Entry<String, AbstractUserStoreDAOFactory> entry : userStoreDAOFactories.entrySet()) {
        if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() && StringUtils.equals(entry.getKey(), DB_BASED_REPOSITORY_CLASS)) {
            return entry.getValue().getInstance().getUserStore(domain);
        }
        try {
            userStoreDTOS = SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().getUserStores();
        } catch (UserStoreException e) {
            throw new IdentityUserStoreMgtException("Error occurred while retrieving the user stores from file" + " based system.", e);
        }
    }
    if (userStoreDTOS != null) {
        for (UserStoreDTO userStoreDTO : userStoreDTOS) {
            if (userStoreDTO.getDomainId().equals(domain)) {
                // Trigger post get listeners.
                try {
                    triggerListenersOnUserStorePostGet(userStoreDTO);
                } catch (UserStoreClientException e) {
                    throw buildIdentityUserStoreClientException("Userstore " + domain + " cannot be retrieved.", e);
                } catch (UserStoreException e) {
                    throw new IdentityUserStoreMgtException("Error occurred while triggering userstore post get " + "listener. " + e.getMessage(), e);
                }
                return userStoreDTO;
            }
        }
    }
    return null;
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException) IdentityUserStoreClientException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException) UserStoreClientException(org.wso2.carbon.user.api.UserStoreClientException) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) UserStoreException(org.wso2.carbon.user.api.UserStoreException) Map(java.util.Map)

Example 8 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class UserStoreConfigServiceImpl method modifyUserStoreState.

@Override
public void modifyUserStoreState(String domain, Boolean isDisable, String repositoryClass) throws IdentityUserStoreMgtException {
    loadTenant();
    UserStoreDTO userStoreDTO;
    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() && StringUtils.isNotEmpty(repositoryClass)) {
        Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories();
        AbstractUserStoreDAOFactory userStoreDAOFactory = userStoreDAOFactories.get(repositoryClass);
        userStoreDTO = getUserStoreDTO(domain, isDisable, repositoryClass);
        userStoreDAOFactory.getInstance().updateUserStore(userStoreDTO, true);
    } else if (StringUtils.equals(repositoryClass, FILE_BASED_REPOSITORY_CLASS)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Modifying state for " + "user-store " + domain + " with file-based configuration.");
        }
        userStoreDTO = getUserStoreDTO(domain, isDisable, null);
        updateStateInFileRepository(userStoreDTO);
    } else if (StringUtils.isNotEmpty(repositoryClass)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Unable to modify state " + "for user-store " + domain + " with repository class " + repositoryClass);
        }
    } else {
        userStoreDTO = getUserStoreDTO(domain, isDisable, null);
        updateStateInFileRepository(userStoreDTO);
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)

Example 9 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method getUserStoreDTO.

private UserStoreDTO getUserStoreDTO(RealmConfiguration secondaryRealmConfiguration, Map<String, String> userStoreProperties) {
    UserStoreDTO userStoreDTO = new UserStoreDTO();
    userStoreDTO.setClassName(secondaryRealmConfiguration.getUserStoreClass());
    userStoreDTO.setDescription(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigurationConstant.DESCRIPTION));
    userStoreDTO.setDomainId(secondaryRealmConfiguration.getUserStoreProperty(UserStoreConfigConstants.DOMAIN_NAME));
    userStoreDTO.setRepositoryClass(FILE_BASED);
    if (userStoreProperties.get(DISABLED) != null) {
        userStoreDTO.setDisabled(Boolean.valueOf(userStoreProperties.get(DISABLED)));
    }
    return userStoreDTO;
}
Also used : UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)

Example 10 with UserStoreDTO

use of org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO in project carbon-identity-framework by wso2.

the class FileBasedUserStoreDAOImpl method getUserStores.

@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()]);
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) RealmConfiguration(org.wso2.carbon.user.api.RealmConfiguration) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) MaskedProperty(org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)

Aggregations

UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)21 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.UserStoreDTO)14 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)13 UserStoreException (org.wso2.carbon.user.api.UserStoreException)11 ArrayList (java.util.ArrayList)9 AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)8 Test (org.testng.annotations.Test)7 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.stub.dto.PropertyDTO)7 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)7 UserStorePersistanceDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStorePersistanceDTO)6 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)6 PropertyDTO (org.wso2.carbon.identity.user.store.configuration.dto.PropertyDTO)5 File (java.io.File)4 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)4 UserStoreConfigListener (org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)4 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)4 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)4 H2DataBaseManager (org.wso2.carbon.automation.test.utils.dbutils.H2DataBaseManager)3 MaskedProperty (org.wso2.carbon.identity.user.store.configuration.beans.MaskedProperty)3 Property (org.wso2.carbon.user.api.Property)3