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