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);
}
}
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;
}
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);
}
}
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];
}
}
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.");
}
}
Aggregations