use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class ServerIdpManagementService method handleTemplateMgtException.
/**
* Handle template management exceptions and return related API errors.
*
* @param e {@link TemplateManagementException}.
* @param errorEnum Error message with error code and description.
* @param data Additional information.
* @return API error.
*/
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof TemplateManagementClientException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TemplateManagementServerException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
if (e.getErrorCode() != null) {
errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class KeyStoreService method handleException.
private APIError handleException(KeyStoreConstants.ErrorMessage errorMessage, String data, String description, Response.Status status) {
ErrorResponse.Builder builder = new ErrorResponse.Builder().withCode(errorMessage.getCode()).withMessage(generateErrorMessage(errorMessage.getMessage(), data)).withDescription(description);
ErrorResponse errorResponse = builder.build();
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class UpdateInboundProtocols method apply.
@Override
public void apply(ServiceProvider application, InboundProtocols inboundProtocols) {
List<InboundAuthenticationRequestConfig> inbounds = new ArrayList<>();
try {
if (inboundProtocols.getOidc() != null) {
inbounds.add(createOAuthInbound(application.getApplicationName(), inboundProtocols.getOidc()));
}
if (inboundProtocols.getSaml() != null) {
inbounds.add(createSAMLInbound(application, inboundProtocols.getSaml()));
}
if (inboundProtocols.getWsTrust() != null) {
inbounds.add(createWsTrustInbound(inboundProtocols.getWsTrust()));
}
} catch (APIError error) {
if (log.isDebugEnabled()) {
log.debug("Error while adding inbound protocols for application id: " + application.getApplicationResourceId() + ". Cleaning up possible partially created inbound " + "configurations.");
}
rollbackInbounds(inbounds);
throw error;
}
if (inboundProtocols.getPassiveSts() != null) {
inbounds.add(createPassiveSTSInboundConfig(inboundProtocols.getPassiveSts()));
}
if (inboundProtocols.getCustom() != null) {
inboundProtocols.getCustom().forEach(inboundConfigModel -> {
// TODO Add validate at swagger to make sure inbound key and name are not null.
InboundAuthenticationRequestConfig inboundRequestConfig = createCustomInbound(inboundConfigModel);
inbounds.add(inboundRequestConfig);
});
}
InboundAuthenticationConfig inboundAuthConfig = new InboundAuthenticationConfig();
inboundAuthConfig.setInboundAuthenticationRequestConfigs(inbounds.toArray(new InboundAuthenticationRequestConfig[0]));
application.setInboundAuthenticationConfig(inboundAuthConfig);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class BrandingPreferenceManagementService method handleBrandingPreferenceMgtException.
/**
* Handle branding preference management exceptions and return an API error.
*
* @param exception Branding preference management exception
* @param errorEnum Branding preference management error enum.
* @param data Relevant data.
* @return Processed API Error.
*/
private APIError handleBrandingPreferenceMgtException(BrandingPreferenceMgtException exception, BrandingPreferenceManagementConstants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (exception instanceof BrandingPreferenceMgtClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception.getMessage());
if (exception.getErrorCode() != null) {
String errorCode = exception.getErrorCode();
errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(exception.getMessage());
if (BRANDING_PREFERENCE_ALREADY_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
status = Response.Status.CONFLICT;
} else if (BRANDING_PREFERENCE_NOT_EXISTS_ERROR_CODE.equals(exception.getErrorCode())) {
status = Response.Status.NOT_FOUND;
} else {
status = Response.Status.BAD_REQUEST;
}
} else if (exception instanceof BrandingPreferenceMgtServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
if (exception.getErrorCode() != null) {
String errorCode = exception.getErrorCode();
errorCode = errorCode.contains(BRANDING_PREFERENCE_MGT_ERROR_CODE_DELIMITER) ? errorCode : BRANDING_PREFERENCE_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(exception.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, exception, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.
the class BrandingPreferenceApiServiceImpl method addBrandingPreference.
// TODO: Improve API to manage application level & language level theming resources in addition to the tenant level.
@Override
public Response addBrandingPreference(BrandingPreferenceModel brandingPreferenceModel) {
if (StringUtils.isBlank(brandingPreferenceModel.getType().toString())) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
if (!ORGANIZATION_TYPE.equals(brandingPreferenceModel.getType().toString())) {
return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
}
if ((!DEFAULT_LOCALE.equals(brandingPreferenceModel.getLocale())) && StringUtils.isNotBlank(brandingPreferenceModel.getLocale())) {
return Response.status(Response.Status.NOT_IMPLEMENTED).entity("Not Implemented.").build();
}
BrandingPreferenceModel createdBrandingPreferenceModel = brandingPreferenceManagementService.addBrandingPreference(brandingPreferenceModel);
URI location = null;
try {
location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + BRANDING_PREFERENCE_CONTEXT_PATH + QUERY_PARAM_INDICATOR + URLEncoder.encode(String.format(GET_PREFERENCE_COMPONENT_WITH_QUERY_PARAM, ORGANIZATION_TYPE, getTenantDomainFromContext(), DEFAULT_LOCALE), StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
ErrorResponse errorResponse = new ErrorResponse.Builder().withMessage("Error due to unsupported encoding.").build();
throw new APIError(Response.Status.METHOD_NOT_ALLOWED, errorResponse);
}
return Response.created(location).entity(createdBrandingPreferenceModel).build();
}
Aggregations