use of org.wso2.carbon.user.core.UserStoreClientException in project carbon-identity-framework by wso2.
the class UserStoreConfigServiceImpl method getUserStores.
@Override
public UserStoreDTO[] getUserStores() throws IdentityUserStoreMgtException {
List<UserStoreDTO> userStoreDTOList = new ArrayList<>();
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)) {
continue;
}
UserStoreDTO[] allUserStores = entry.getValue().getInstance().getUserStores();
userStoreDTOList.addAll(Arrays.asList(allUserStores));
}
UserStoreDTO[] userStoreDTOS = userStoreDTOList.toArray(new UserStoreDTO[0]);
// Trigger post get listeners.
try {
triggerListenersOnUserStoresPostGet(userStoreDTOS);
} catch (UserStoreClientException e) {
throw buildIdentityUserStoreClientException("Userstores cannot be retrieved.", e);
} catch (UserStoreException e) {
throw new IdentityUserStoreMgtException("Error occurred while triggering userstores post get listener.", e);
}
return userStoreDTOS;
}
use of org.wso2.carbon.user.core.UserStoreClientException in project carbon-identity-framework by wso2.
the class UserStoreConfigServiceImpl method updateUserStore.
@Override
public void updateUserStore(UserStoreDTO userStoreDTO, boolean isStateChange) throws IdentityUserStoreMgtException {
loadTenant();
try {
triggerListenersOnUserStorePreUpdate(userStoreDTO, isStateChange);
if (SecondaryUserStoreConfigurationUtil.isUserStoreRepositorySeparationEnabled() && StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {
AbstractUserStoreDAOFactory userStoreDAOFactory = UserStoreConfigListenersHolder.getInstance().getUserStoreDAOFactories().get(userStoreDTO.getRepositoryClass());
userStoreDAOFactory.getInstance().updateUserStore(userStoreDTO, false);
} else if (StringUtils.equals(userStoreDTO.getRepositoryClass(), FILE_BASED_REPOSITORY_CLASS)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Repository separation of user-stores has been disabled. Editing user-store " + userStoreDTO.getDomainId() + " with file-based configuration.");
}
validateConnectionUrl(userStoreDTO);
SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO, false);
} else if (StringUtils.isNotEmpty(userStoreDTO.getRepositoryClass())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Repository separation of user-stores has been disabled. Unable to edit " + "user-store " + userStoreDTO.getDomainId() + " with repository class " + userStoreDTO.getRepositoryClass());
}
} else {
validateConnectionUrl(userStoreDTO);
SecondaryUserStoreConfigurationUtil.getFileBasedUserStoreDAOFactory().updateUserStore(userStoreDTO, false);
}
} catch (UserStoreClientException e) {
throw buildIdentityUserStoreClientException("Userstore " + userStoreDTO.getDomainId() + " cannot be updated.", e);
} catch (UserStoreException e) {
String errorMessage = e.getMessage();
throw new IdentityUserStoreMgtException(errorMessage, e);
}
}
use of org.wso2.carbon.user.core.UserStoreClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMUserManager method deleteUser.
@Override
public void deleteUser(String userId) throws NotFoundException, CharonException, BadRequestException {
if (log.isDebugEnabled()) {
log.debug("Deleting user: " + userId);
}
// get the user name of the user with this id
org.wso2.carbon.user.core.common.User coreUser = null;
String userName = null;
try {
// Set thread local property to signal the downstream SCIMUserOperationListener
// about the provisioning route.
SCIMCommonUtils.setThreadLocalIsManagedThroughSCIMEP(true);
String userIdLocalClaim = SCIMCommonUtils.getSCIMtoLocalMappings().get(SCIMConstants.CommonSchemaConstants.ID_URI);
if (StringUtils.isNotBlank(userIdLocalClaim)) {
// We cannot use getUserWithID because it throws exception when the user cannot be found.
// (Generic user store exception). If we can send a specific user not found exception in user core level
// we can use that method.
List<org.wso2.carbon.user.core.common.User> coreUsers = carbonUM.getUserListWithID(userIdLocalClaim, userId, UserCoreConstants.DEFAULT_PROFILE);
if (coreUsers.size() > 0) {
coreUser = coreUsers.get(0);
}
}
String userStoreDomainFromSP = null;
try {
userStoreDomainFromSP = getUserStoreDomainFromSP();
} catch (IdentityApplicationManagementException e) {
throw new CharonException("Error retrieving User Store name. ", e);
}
if (coreUser == null) {
// Resource with given id not found
if (log.isDebugEnabled()) {
log.debug("User with id: " + userId + " not found.");
}
throw new NotFoundException();
} else if (userStoreDomainFromSP != null && !(userStoreDomainFromSP.equalsIgnoreCase(coreUser.getUserStoreDomain()))) {
throw new CharonException("User :" + coreUser.getUsername() + "is not belong to user store " + userStoreDomainFromSP + "Hence user updating fail");
} else {
// We assume (since id is unique per user) only one user exists for a given id.
userName = coreUser.getUsername();
String userStoreDomainName = coreUser.getUserStoreDomain();
// Check if SCIM is enabled for the user store.
if (!isSCIMEnabled(userStoreDomainName)) {
throw new CharonException("Cannot delete user: " + userName + " through SCIM from user store: " + userStoreDomainName + ". SCIM is not enabled for user store: " + userStoreDomainName);
}
carbonUM.deleteUserWithID(coreUser.getUserID());
if (log.isDebugEnabled()) {
log.debug("User: " + userName + " is deleted through SCIM.");
}
}
} catch (UserStoreClientException e) {
String errorMessage;
if (isNotifyUserstoreStatusEnabled()) {
errorMessage = String.format("Error occurred while deleting user with ID: %s. %s", userId, e.getMessage());
} else {
errorMessage = "Error occurred while deleting user with ID: " + userId;
}
throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
} catch (org.wso2.carbon.user.core.UserStoreException e) {
String errorMessage;
if (isNotifyUserstoreStatusEnabled()) {
errorMessage = String.format("Error occurred while deleting user with ID: %s. %s", userId, e.getMessage());
} else {
errorMessage = "Error occurred while deleting user with ID: " + userId;
}
/*
There are scenarios where the client exceptions are wrapped in the super class.Therefore checking for
possible client exception.
*/
Throwable ex = ExceptionUtils.getRootCause(e);
if (ex instanceof UserStoreClientException) {
throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
}
throw resolveError(e, errorMessage);
}
}
use of org.wso2.carbon.user.core.UserStoreClientException in project identity-inbound-provisioning-scim2 by wso2-extensions.
the class SCIMUserManager method listUsernamesUsingLegacyAPIs.
/**
* Method to list usernames of all users from a specific user store using legacy APIs.
*
* @param domainName Name of the user store
* @return Usernames list
* @throws CharonException Error while listing usernames
* @throws BadRequestException
*/
private Set<org.wso2.carbon.user.core.common.User> listUsernamesUsingLegacyAPIs(String domainName) throws CharonException, BadRequestException {
Set<org.wso2.carbon.user.core.common.User> users = null;
try {
Map<String, String> scimToLocalClaimsMap = SCIMCommonUtils.getSCIMtoLocalMappings();
String userIdLocalClaim = scimToLocalClaimsMap.get(SCIMConstants.CommonSchemaConstants.ID_URI);
String claimValue = domainName.toUpperCase() + CarbonConstants.DOMAIN_SEPARATOR + SCIMCommonConstants.ANY;
if (StringUtils.isNotBlank(userIdLocalClaim)) {
if (removeDuplicateUsersInUsersResponseEnabled) {
users = new TreeSet<>(Comparator.comparing(org.wso2.carbon.user.core.common.User::getFullQualifiedUsername));
} else {
users = new LinkedHashSet<>();
}
users.addAll(carbonUM.getUserListWithID(userIdLocalClaim, claimValue, null));
}
return users;
} catch (UserStoreClientException e) {
String errorMessage = String.format("Error while listing usernames from domain: %s. %s", domainName, e.getMessage());
if (log.isDebugEnabled()) {
log.debug(errorMessage, e);
}
throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
} catch (UserStoreException e) {
// Sometimes client exceptions are wrapped in the super class.
// Therefore checking for possible client exception.
Throwable ex = ExceptionUtils.getRootCause(e);
if (ex instanceof UserStoreClientException) {
String errorMessage = String.format("Error while listing usernames from domain: %s. %s", domainName, ex.getMessage());
if (log.isDebugEnabled()) {
log.debug(errorMessage, ex);
}
throw new BadRequestException(errorMessage, ResponseCodeConstants.INVALID_VALUE);
}
throw new CharonException(String.format("Error while listing usernames from domain: %s.", domainName), e);
}
}
Aggregations