Search in sources :

Example 1 with TenantManagementClientException

use of org.wso2.carbon.stratos.common.exception.TenantManagementClientException in project identity-api-server by wso2.

the class ServerTenantManagementService method handleTenantManagementException.

/**
 * Handle TenantMgtException, extract error code, error description and status code to be sent
 * in the response.
 *
 * @param e         TenantMgtException
 * @param errorEnum Error Message information.
 * @return APIError.
 */
private APIError handleTenantManagementException(TenantMgtException e, TenantManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof TenantManagementClientException) {
        if (ERROR_CODE_RESOURCE_LIMIT_REACHED.equals(e.getErrorCode())) {
            return handleResourceLimitReached();
        }
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.BAD_REQUEST;
    } else if (e instanceof TenantManagementServerException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    } else {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
        status = Response.Status.INTERNAL_SERVER_ERROR;
    }
    return new APIError(status, errorResponse);
}
Also used : TenantsListResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse) OwnerResponse(org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse) Response(javax.ws.rs.core.Response) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) TenantManagementServerException(org.wso2.carbon.stratos.common.exception.TenantManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 2 with TenantManagementClientException

use of org.wso2.carbon.stratos.common.exception.TenantManagementClientException in project identity-api-server by wso2.

the class ServerTenantManagementService method createTenantInfoBean.

private Tenant createTenantInfoBean(ChannelVerifiedTenantModel channelVerifiedTenantModel) throws TenantManagementClientException {
    Tenant tenant = new Tenant();
    Map<String, String> claimsMap = new HashMap<>();
    tenant.setActive(true);
    tenant.setDomain(StringUtils.lowerCase(channelVerifiedTenantModel.getDomain()));
    if (channelVerifiedTenantModel.getOwners() != null && channelVerifiedTenantModel.getOwners().size() > 0 && channelVerifiedTenantModel.getOwners().get(0) != null) {
        tenant.setAdminName(channelVerifiedTenantModel.getOwners().get(0).getEmail());
        tenant.setAdminFirstName(channelVerifiedTenantModel.getOwners().get(0).getFirstname());
        tenant.setAdminLastName(channelVerifiedTenantModel.getOwners().get(0).getLastname());
        tenant.setEmail(channelVerifiedTenantModel.getOwners().get(0).getEmail());
        tenant.setProvisioningMethod(VERIFIED_LITE_USER);
        String password = channelVerifiedTenantModel.getOwners().get(0).getPassword();
        String code = channelVerifiedTenantModel.getCode();
        if (StringUtils.isBlank(code)) {
            throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), "code"));
        }
        if (channelVerifiedTenantModel.getPurpose() != null) {
            claimsMap.put(PURPOSE, channelVerifiedTenantModel.getPurpose().getName());
            if (!CollectionUtils.isEmpty(channelVerifiedTenantModel.getPurpose().getAttributes())) {
                channelVerifiedTenantModel.getPurpose().getAttributes().forEach(attribute -> claimsMap.put(PURPOSE + "_" + attribute.getKey(), attribute.getValue()));
            }
        }
        tenant.setClaimsMap(claimsMap);
        tenant.setAdminPassword(password);
        List<AdditionalClaims> additionalClaimsList = channelVerifiedTenantModel.getOwners().get(0).getAdditionalClaims();
        if (CollectionUtils.isNotEmpty(additionalClaimsList)) {
            tenant.setClaimsMap(createClaimsMapping(additionalClaimsList));
        }
    } else {
        throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_OWNER_REQUIRED);
    }
    return tenant;
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) Tenant(org.wso2.carbon.user.core.tenant.Tenant) HashMap(java.util.HashMap) AdditionalClaims(org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)

Example 3 with TenantManagementClientException

use of org.wso2.carbon.stratos.common.exception.TenantManagementClientException in project identity-api-server by wso2.

the class ServerTenantManagementService method createTenantInfoBean.

private Tenant createTenantInfoBean(TenantModel tenantModel) throws TenantManagementClientException {
    Tenant tenant = new Tenant();
    tenant.setActive(true);
    tenant.setDomain(tenantModel.getDomain());
    if (tenantModel.getOwners() != null) {
        tenant.setAdminName(tenantModel.getOwners().get(0).getUsername());
        tenant.setAdminFirstName(tenantModel.getOwners().get(0).getFirstname());
        tenant.setAdminLastName(tenantModel.getOwners().get(0).getLastname());
        tenant.setEmail(tenantModel.getOwners().get(0).getEmail());
        String provisioningMethod = tenantModel.getOwners().get(0).getProvisioningMethod();
        if (INLINE_PASSWORD.equalsIgnoreCase(provisioningMethod)) {
            String password = tenantModel.getOwners().get(0).getPassword();
            if (StringUtils.isBlank(password)) {
                throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(TenantConstants.ErrorMessage.ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), "password"));
            }
            tenant.setAdminPassword(password);
        }
        tenant.setProvisioningMethod(provisioningMethod);
        List<AdditionalClaims> additionalClaimsList = tenantModel.getOwners().get(0).getAdditionalClaims();
        if (CollectionUtils.isNotEmpty(additionalClaimsList)) {
            tenant.setClaimsMap(createClaimsMapping(additionalClaimsList));
        }
    } else {
        throw new TenantManagementClientException(TenantConstants.ErrorMessage.ERROR_CODE_OWNER_REQUIRED);
    }
    return tenant;
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) Tenant(org.wso2.carbon.user.core.tenant.Tenant) AdditionalClaims(org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)

Example 4 with TenantManagementClientException

use of org.wso2.carbon.stratos.common.exception.TenantManagementClientException in project identity-api-server by wso2.

the class ServerTenantManagementService method validateInputAgainstCode.

/**
 * Validate details attached to the code sent in email verification with the sent in details.
 * @param tenant tenant
 * @throws TenantManagementClientException error in validating code
 */
private void validateInputAgainstCode(ChannelVerifiedTenantModel tenant) throws TenantManagementClientException {
    String code = tenant.getCode();
    if (StringUtils.isBlank(code)) {
        throw new TenantManagementClientException(ERROR_CODE_MISSING_REQUIRED_PARAMETER.getCode(), String.format(ERROR_CODE_MISSING_REQUIRED_PARAMETER.getMessage(), CODE));
    }
    UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
    // If the code is validated, the load method will return data. Otherwise method will throw exceptions.
    try {
        UserRecoveryData recoveryData = userRecoveryDataStore.load(code);
        if (recoveryData != null && recoveryData.getUser() != null && tenant.getOwners() != null && tenant.getOwners().get(0) != null && tenant.getOwners().get(0).getEmail() != null && tenant.getOwners().get(0).getEmail().equalsIgnoreCase(recoveryData.getUser().getUserName())) {
            userRecoveryDataStore.invalidate(code);
            return;
        } else {
            // the confirmed email using the code and submitted emails are different.
            userRecoveryDataStore.invalidate(code);
            log.warn("The confirmed email using the code and submitted emails are different.");
            throw new TenantManagementClientException(ERROR_CODE_INVALID_EMAIL.getCode(), String.format(ERROR_CODE_INVALID_EMAIL.getMessage(), CODE));
        }
    } catch (IdentityRecoveryException e) {
        throw handleException(Response.Status.UNAUTHORIZED, TenantManagementConstants.ErrorMessage.ERROR_CODE_ERROR_VALIDATING_TENANT_CODE, null);
    }
}
Also used : TenantManagementClientException(org.wso2.carbon.stratos.common.exception.TenantManagementClientException) UserRecoveryData(org.wso2.carbon.identity.recovery.model.UserRecoveryData) UserRecoveryDataStore(org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException)

Aggregations

TenantManagementClientException (org.wso2.carbon.stratos.common.exception.TenantManagementClientException)4 AdditionalClaims (org.wso2.carbon.identity.api.server.tenant.management.v1.model.AdditionalClaims)2 Tenant (org.wso2.carbon.user.core.tenant.Tenant)2 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)1 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)1 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)1 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)1 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)1 TenantManagementServerException (org.wso2.carbon.stratos.common.exception.TenantManagementServerException)1