Search in sources :

Example 1 with AbstractUserStoreDAOFactory

use of org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory 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 2 with AbstractUserStoreDAOFactory

use of org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory 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 3 with AbstractUserStoreDAOFactory

use of org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory 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 4 with AbstractUserStoreDAOFactory

use of org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory in project carbon-identity-framework by wso2.

the class UserStoreConfigAdminService method getSecondaryRealmConfigurationsOnRepository.

/**
 * Get user stores from all the repositories.
 *
 * @param repositoryClassName repository class name
 * @return userstore {@link UserStoreDTO}
 * @throws IdentityUserStoreMgtException
 */
public UserStoreDTO[] getSecondaryRealmConfigurationsOnRepository(String repositoryClassName) throws IdentityUserStoreMgtException {
    if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled()) {
        Map<String, AbstractUserStoreDAOFactory> userStoreDAOFactories = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories();
        AbstractUserStoreDAOFactory userStoreDAOFactory = userStoreDAOFactories.get(repositoryClassName);
        if (userStoreDAOFactory != null) {
            return userStoreDAOFactory.getInstance().getUserStores();
        } else {
            return new UserStoreDTO[0];
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Repository separation of user-stores has been disabled. Returning empty " + "UserStoreDTO array.");
        }
        return new UserStoreDTO[0];
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreDTO(org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)

Example 5 with AbstractUserStoreDAOFactory

use of org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory in project carbon-identity-framework by wso2.

the class UserStoreConfigComponent method activate.

/**
 * @param ctxt
 */
@Activate
protected void activate(ComponentContext ctxt) {
    if (log.isDebugEnabled()) {
        log.debug("Identity User Store bundle is activated.");
    }
    try {
        BundleContext bundleContext = ctxt.getBundleContext();
        AbstractUserStoreDAOFactory fileBasedUserStoreDAOFactory = new FileBasedUserStoreDAOFactory();
        AbstractUserStoreDAOFactory databaseBasedUserStoreDAOFactory = new DatabaseBasedUserStoreDAOFactory();
        ServiceRegistration serviceRegistration = bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), fileBasedUserStoreDAOFactory, null);
        bundleContext.registerService(AbstractUserStoreDAOFactory.class.getName(), databaseBasedUserStoreDAOFactory, null);
        UserStoreConfigService userStoreConfigService = new UserStoreConfigServiceImpl();
        ctxt.getBundleContext().registerService(UserStoreConfigService.class.getName(), userStoreConfigService, null);
        UserStoreConfigListenersHolder.getInstance().setUserStoreConfigService(userStoreConfigService);
        UserStoreHashProviderConfigListenerImpl userStoreHashProviderListener = new UserStoreHashProviderConfigListenerImpl();
        ctxt.getBundleContext().registerService(UserStoreConfigListener.class.getName(), userStoreHashProviderListener, null);
        UserStoreConfigListenersHolder.getInstance().setUserStoreConfigListenerService(userStoreHashProviderListener);
        if (serviceRegistration != null) {
            if (log.isDebugEnabled()) {
                log.debug("FileBasedUserStoreDAOFactory is successfully registered.");
            }
        } else {
            log.error("FileBasedUserStoreDAOFactory could not be registered.");
        }
        readAllowedUserstoreConfiguration();
        readUserStoreAttributeMappingConfigs();
    } catch (Throwable e) {
        log.error("Failed to load user store org.wso2.carbon.identity.user.store.configuration details.", e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Identity User Store-Config bundle is activated.");
    }
}
Also used : AbstractUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory) UserStoreHashProviderConfigListenerImpl(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreHashProviderConfigListenerImpl) UserStoreConfigServiceImpl(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigServiceImpl) UserStoreConfigListener(org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener) FileBasedUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.impl.FileBasedUserStoreDAOFactory) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService) DatabaseBasedUserStoreDAOFactory(org.wso2.carbon.identity.user.store.configuration.dao.impl.DatabaseBasedUserStoreDAOFactory) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

AbstractUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.AbstractUserStoreDAOFactory)9 UserStoreDTO (org.wso2.carbon.identity.user.store.configuration.dto.UserStoreDTO)5 IdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException)5 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)5 UserStoreException (org.wso2.carbon.user.api.UserStoreException)5 SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException (org.wso2.carbon.identity.user.store.configuration.utils.SecondaryUserStoreConfigurationUtil.buildIdentityUserStoreClientException)4 UserStoreClientException (org.wso2.carbon.user.api.UserStoreClientException)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)1 UserStoreConfigServiceImpl (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigServiceImpl)1 DatabaseBasedUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.impl.DatabaseBasedUserStoreDAOFactory)1 FileBasedUserStoreDAOFactory (org.wso2.carbon.identity.user.store.configuration.dao.impl.FileBasedUserStoreDAOFactory)1 UserStoreConfigListener (org.wso2.carbon.identity.user.store.configuration.listener.UserStoreConfigListener)1 UserStoreHashProviderConfigListenerImpl (org.wso2.carbon.identity.user.store.configuration.listener.UserStoreHashProviderConfigListenerImpl)1