Search in sources :

Example 1 with NotificationUsernameRecoveryManager

use of org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager in project identity-governance by wso2-extensions.

the class ClaimsApiServiceImpl method claimsGet.

@Override
public Response claimsGet(String tenantDomain) {
    if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
        tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    }
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    } else if (!RecoveryUtil.isValidTenantDomain(tenantDomain)) {
        RecoveryUtil.handleBadRequest("Invalid tenant domain :" + tenantDomain, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_INVALID_TENANT.getCode());
    }
    String dialect = IdentityRecoveryConstants.WSO2CARBON_CLAIM_DIALECT;
    NotificationUsernameRecoveryManager notificationBasedUsernameRecoveryManager = RecoveryUtil.getNotificationBasedUsernameRecoveryManager();
    ClaimDTO[] claimDTOs = new ClaimDTO[0];
    try {
        Claim[] userClaims = notificationBasedUsernameRecoveryManager.getIdentitySupportedClaims(dialect, tenantDomain);
        claimDTOs = RecoveryUtil.getClaimDTOs(userClaims);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Client Error while getting all identity claims ", e);
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, null);
    } catch (Throwable throwable) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    return Response.ok(claimDTOs).build();
}
Also used : ClaimDTO(org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO) NotificationUsernameRecoveryManager(org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) Claim(org.wso2.carbon.user.api.Claim) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Example 2 with NotificationUsernameRecoveryManager

use of org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager in project identity-governance by wso2-extensions.

the class RecoverUsernameApiServiceImpl method recoverUsernamePost.

@Override
public Response recoverUsernamePost(List<UserClaimDTO> claim, String tenantDomain, Boolean notify) {
    if (IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT) != null) {
        tenantDomain = (String) IdentityUtil.threadLocalProperties.get().get(Constants.TENANT_NAME_FROM_CONTEXT);
    }
    NotificationUsernameRecoveryManager notificationBasedUsernameRecoveryManager = RecoveryUtil.getNotificationBasedUsernameRecoveryManager();
    String username = null;
    try {
        username = notificationBasedUsernameRecoveryManager.verifyUsername(RecoveryUtil.getUserClaims(claim), tenantDomain, notify);
    } catch (IdentityRecoveryClientException e) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(e.getMessage(), e);
        }
        if (IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_NO_USER_FOUND.getCode().equals(e.getErrorCode())) {
            return Response.noContent().build();
        }
        RecoveryUtil.handleBadRequest(e.getMessage(), e.getErrorCode());
    } catch (IdentityRecoveryException e) {
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, e.getErrorCode(), LOG, e);
    } catch (Throwable throwable) {
        if (throwable != null && StringUtils.equals(Constants.ERROR_MESSAGE_EMAIL_NOT_FOUND, throwable.getMessage())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(throwable.getMessage());
            }
            return Response.ok().build();
        }
        RecoveryUtil.handleInternalServerError(Constants.SERVER_ERROR, IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED.getCode(), LOG, throwable);
    }
    if (StringUtils.isBlank(username)) {
        return Response.accepted().build();
    }
    return Response.accepted(username).build();
}
Also used : NotificationUsernameRecoveryManager(org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) IdentityRecoveryClientException(org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)

Aggregations

IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)2 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)2 NotificationUsernameRecoveryManager (org.wso2.carbon.identity.recovery.username.NotificationUsernameRecoveryManager)2 ClaimDTO (org.wso2.carbon.identity.recovery.endpoint.dto.ClaimDTO)1 Claim (org.wso2.carbon.user.api.Claim)1