use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException 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.utils.IdentityUserStoreClientException in project carbon-identity-framework by wso2.
the class FileBasedUserStoreDAOImpl method doAddUserStore.
@Override
protected void doAddUserStore(UserStorePersistanceDTO userStorePersistanceDTO) throws IdentityUserStoreMgtException {
String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
try {
// Run pre user-store add listeners.
triggerListenersOnUserStorePreAdd(domainName);
boolean validDomain = isValidDomainToAdd(domainName);
validateForFederatedDomain(domainName);
if (validDomain) {
Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
if (Files.exists(userStoreConfigFile)) {
throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), false);
}
writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(), false, false, domainName);
} else {
if (log.isDebugEnabled()) {
log.debug("The user store domain: " + domainName + "is not a valid domain name.");
}
}
} catch (UserStoreException e) {
throw new IdentityUserStoreClientException("Error occurred while adding the user store with the domain: " + domainName, e);
}
}
use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project identity-api-server by wso2.
the class ServerUserStoreService method deleteUserStore.
/**
* Delete a userStore by its domainId.
*
* @param userstoreDomainId base64 encoded url value of userStore domain Id.
*/
public void deleteUserStore(String userstoreDomainId) {
try {
UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
userStoreConfigService.deleteUserStore(base64URLDecodeId(userstoreDomainId));
} catch (IdentityUserStoreClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
} catch (IdentityUserStoreMgtException e) {
UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_USER_STORE;
throw handleIdentityUserStoreMgtException(e, errorEnum);
}
}
use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project identity-api-server by wso2.
the class ServerUserStoreService method handleIdentityUserStoreMgtException.
/**
* Handle handleIdentityUserStoreMgtException, ie, handle the appropriate client and server exception and set
* proper API Error Response.
*
* @param exception Exception thrown
* @param errorEnum Corresponding error enum
* @return API Error object.
*/
private APIError handleIdentityUserStoreMgtException(IdentityUserStoreMgtException exception, UserStoreConstants.ErrorMessage errorEnum) {
Response.Status status;
ErrorResponse errorResponse;
if (exception instanceof IdentityUserStoreServerException) {
errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
return handleIdentityUserStoreException(exception, errorResponse, status);
} else if (exception instanceof IdentityUserStoreClientException) {
errorResponse = getErrorBuilder(errorEnum).build(LOG, exception.getMessage());
if (ERROR_CODE_RESOURCE_LIMIT_REACHED.equals(exception.getErrorCode())) {
return handleResourceLimitReached();
}
// Send client error with specific error code or as a BAD request.
status = Response.Status.BAD_REQUEST;
return handleIdentityUserStoreException(exception, errorResponse, status);
} else {
// Internal Server error
errorResponse = getErrorBuilder(errorEnum).build(LOG, exception, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
return new APIError(status, errorResponse);
}
}
use of org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreClientException in project carbon-identity-framework by wso2.
the class FileBasedUserStoreDAOImpl method doUpdateUserStore.
@Override
protected void doUpdateUserStore(UserStorePersistanceDTO userStorePersistanceDTO, boolean isStateChange) throws IdentityUserStoreMgtException {
boolean isValidDomain;
String domainName = userStorePersistanceDTO.getUserStoreDTO().getDomainId();
try {
validateForFederatedDomain(domainName);
isValidDomain = isDomainNameExists(domainName);
} catch (UserStoreException e) {
throw new IdentityUserStoreClientException("Error while updating the user store.", e);
}
if (isValidDomain) {
Path userStoreConfigFile = getUserStoreConfigurationFile(userStorePersistanceDTO.getUserStoreDTO());
if (!Files.exists(userStoreConfigFile)) {
throw buildException(userStorePersistanceDTO.getUserStoreDTO().getDomainId(), true);
}
writeToUserStoreConfigurationFile(userStoreConfigFile, userStorePersistanceDTO.getUserStoreDTO(), true, isStateChange, domainName);
} else {
String errorMessage = "Trying to edit an invalid domain : " + domainName;
throw new IdentityUserStoreClientException(errorMessage);
}
}
Aggregations