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);
}
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;
}
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;
}
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);
}
}
Aggregations