use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class Utils method getRealmConfiguration.
/**
* Get RealmConfiguration by tenantId
*
* @param user User
* @return realmConfiguration RealmConfiguration of the given tenant
* @throws IdentityRecoveryClientException If fails
*/
private static RealmConfiguration getRealmConfiguration(User user) throws IdentityRecoveryClientException {
int tenantId = IdentityTenantUtil.getTenantId(user.getTenantDomain());
UserStoreManager userStoreManager;
try {
userStoreManager = IdentityRecoveryServiceDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId).getUserStoreManager();
} catch (UserStoreException userStoreException) {
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, null, userStoreException);
}
return ((org.wso2.carbon.user.core.UserStoreManager) userStoreManager).getSecondaryUserStoreManager(user.getUserStoreDomain()).getRealmConfiguration();
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class NotificationUsernameRecoveryManager method initiateUsernameRecovery.
/**
* Initiate username recovery.
*
* @param claims User claims
* @param tenantDomain Tenant domain
* @param manageNotificationsInternally Enable internal notification management
* @return RecoveryChannelInfoDTO
* @throws IdentityRecoveryException Error initiating username recovery.
*/
private RecoveryInformationDTO initiateUsernameRecovery(Map<String, String> claims, String tenantDomain, boolean manageNotificationsInternally) throws IdentityRecoveryException {
try {
HashMap<String, String> properties = new HashMap<>();
properties.put(IdentityRecoveryConstants.USE_LEGACY_API_PROPERTY_KEY, Boolean.toString(true));
properties.put(IdentityRecoveryConstants.MANAGE_NOTIFICATIONS_INTERNALLY_PROPERTY_KEY, Boolean.toString(manageNotificationsInternally));
return usernameRecoveryManagerImpl.initiate(claims, tenantDomain, properties);
} catch (IdentityRecoveryServerException exception) {
if (StringUtils.isNotEmpty(exception.getErrorCode())) {
String errorCode = exception.getErrorCode();
// Userstore not found error.
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_GETTING_USERSTORE_MANAGER.getCode().equals(errorCode)) {
String msg = "Error retrieving the user store manager for the tenant";
throw new IdentityRecoveryException(msg, exception);
}
// Error retrieving claims.
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_ERROR_RETRIEVING_USER_CLAIM.getCode().equals(errorCode)) {
String msg = "Unable to retrieve the claim for the given tenant";
throw new IdentityRecoveryException(msg, exception);
}
}
throw exception;
} catch (IdentityRecoveryClientException exception) {
if (StringUtils.isNotEmpty(exception.getErrorCode())) {
String errorCode = exception.getErrorCode();
// Multiple users matched error.
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_MULTIPLE_MATCHING_USERS.getCode().equals(errorCode)) {
if (Boolean.parseBoolean(IdentityUtil.getProperty(IdentityRecoveryConstants.ConnectorConfig.NOTIFY_USER_EXISTENCE))) {
throw exception;
}
/* If the notify user is not enabled, return an NULL object so that the user is not notified with
an error. */
return null;
}
// Configurations not enabled error.
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USERNAME_RECOVERY_NOT_ENABLED.getCode().equals(errorCode)) {
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USERNAME_RECOVERY_NOT_ENABLE, null);
}
}
throw exception;
}
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class ValidateCodeApiServiceImpl method validateCodePost.
@Override
public Response validateCodePost(CodeValidationRequestDTO codeValidationRequestDTO) {
User user = null;
UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
try {
// Get the map of properties in the request.
HashMap<String, String> propertyMap = Utils.getPropertiesMap(codeValidationRequestDTO.getProperties());
// Get externally verified channel information.
VerifiedChannelDTO verifiedChannelDTO = codeValidationRequestDTO.getVerifiedChannel();
String verifiedChannelType = null;
String verifiedChannelClaim = null;
// Handling verified channel details not in the request.
if (verifiedChannelDTO != null) {
verifiedChannelClaim = verifiedChannelDTO.getClaim();
verifiedChannelType = verifiedChannelDTO.getType();
}
// Confirm self registration.
user = userSelfRegistrationManager.getConfirmedSelfRegisteredUser(codeValidationRequestDTO.getCode(), verifiedChannelType, verifiedChannelClaim, propertyMap);
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client Error while confirming self up user ", e);
}
Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
} catch (IdentityRecoveryException e) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
} catch (Throwable throwable) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return Response.accepted(Utils.getUserDTO(user)).build();
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class MeApiServiceImpl method meValidateCodePost.
@Override
public Response meValidateCodePost(MeCodeValidationRequestDTO meCodeValidationRequestDTO) {
UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
try {
// Get the map of properties in the request.
HashMap<String, String> propertyMap = Utils.getPropertiesMap(meCodeValidationRequestDTO.getProperties());
// Confirm verification code.
userSelfRegistrationManager.confirmVerificationCodeMe(meCodeValidationRequestDTO.getCode(), propertyMap);
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client error while confirming verification code.", e);
}
Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
} catch (IdentityRecoveryException e) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
} catch (Throwable throwable) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return Response.accepted().build();
}
use of org.wso2.carbon.identity.recovery.IdentityRecoveryClientException in project identity-governance by wso2-extensions.
the class MeApiServiceImpl method mePost.
@Override
public Response mePost(SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO) {
String tenantFromContext = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
if (StringUtils.isNotBlank(tenantFromContext)) {
selfUserRegistrationRequestDTO.getUser().setTenantDomain(tenantFromContext);
}
if (selfUserRegistrationRequestDTO != null && StringUtils.isBlank(selfUserRegistrationRequestDTO.getUser().getRealm())) {
selfUserRegistrationRequestDTO.getUser().setRealm(IdentityUtil.getPrimaryDomainName());
}
UserSelfRegistrationManager userSelfRegistrationManager = Utils.getUserSelfRegistrationManager();
NotificationResponseBean notificationResponseBean = null;
try {
notificationResponseBean = userSelfRegistrationManager.registerUser(Utils.getUser(selfUserRegistrationRequestDTO.getUser()), selfUserRegistrationRequestDTO.getUser().getPassword(), Utils.getClaims(selfUserRegistrationRequestDTO.getUser().getClaims()), Utils.getProperties(selfUserRegistrationRequestDTO.getProperties()));
} catch (IdentityRecoveryClientException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Client Error while registering self up user ", e);
}
if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_USER_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
Utils.handleConflict(e.getMessage(), e.getErrorCode());
} else {
Utils.handleBadRequest(e.getMessage(), e.getErrorCode());
}
} catch (IdentityRecoveryException e) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
} catch (Throwable throwable) {
Utils.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
}
return buildSuccessfulAPIResponse(notificationResponseBean);
}
Aggregations