Search in sources :

Example 6 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerScriptLibrariesService method handleScriptLibraryClientError.

/**
 * Handle Client side errors.
 *
 * @param errorEnum Error Message information.
 * @param data      Error message data.
 * @return APIError
 */
private APIError handleScriptLibraryClientError(Constants.ErrorMessage errorEnum, Response.Status status, String... data) {
    ErrorResponse errorResponse = new ErrorResponse();
    errorResponse.setDescription(String.format(errorEnum.getDescription(), data));
    errorResponse.setCode(errorEnum.getCode());
    errorResponse.setMessage(errorEnum.getMessage());
    errorResponse.setRef(Util.getCorrelation());
    return new APIError(status, errorResponse);
}
Also used : APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 7 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class NotificationSendersApiServiceImpl method createEmailSender.

@Override
public Response createEmailSender(EmailSenderAdd emailSenderAdd) {
    if (StringUtils.equals(getTenantDomainFromContext(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
        return Response.status(Response.Status.METHOD_NOT_ALLOWED).build();
    }
    EmailSender emailSender = notificationSenderManagementService.addEmailSender(emailSenderAdd);
    URI location = null;
    try {
        location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + NOTIFICATION_SENDER_CONTEXT_PATH + "/" + EMAIL_PUBLISHER_TYPE + "/" + URLEncoder.encode(emailSender.getName(), StandardCharsets.UTF_8.name()).replace(PLUS, URL_ENCODED_SPACE));
    } 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(emailSender).build();
}
Also used : EmailSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSender) UnsupportedEncodingException(java.io.UnsupportedEncodingException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) URI(java.net.URI) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Example 8 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerApplicationManagementService method deleteInbound.

private void deleteInbound(String applicationId, String inboundType) {
    ServiceProvider appToUpdate;
    try {
        appToUpdate = cloneApplication(applicationId);
    } catch (APIError e) {
        if (ErrorMessage.APPLICATION_NOT_FOUND.getCode().equals(e.getCode())) {
            // Ignoring the delete operation and return 204 response code, since the resource does not exist.
            return;
        }
        throw e;
    }
    InboundAuthenticationConfig inboundAuthConfig = appToUpdate.getInboundAuthenticationConfig();
    if (ArrayUtils.isNotEmpty(inboundAuthConfig.getInboundAuthenticationRequestConfigs())) {
        // Remove the deleted inbound type by filtering it out of the available inbounds and doing an update.
        InboundAuthenticationRequestConfig[] filteredInbounds = Arrays.stream(inboundAuthConfig.getInboundAuthenticationRequestConfigs()).filter(inbound -> !StringUtils.equals(inboundType, inbound.getInboundAuthType())).toArray(InboundAuthenticationRequestConfig[]::new);
        appToUpdate.getInboundAuthenticationConfig().setInboundAuthenticationRequestConfigs(filteredInbounds);
        updateServiceProvider(applicationId, appToUpdate);
    }
    // Delete the associated CORS origins if the inboundType is oauth2.
    if (inboundType.equals(OAUTH2)) {
        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        CORSManagementService corsManagementService = ApplicationManagementServiceHolder.getCorsManagementService();
        try {
            List<CORSOrigin> existingCORSOrigins = corsManagementService.getApplicationCORSOrigins(applicationId, tenantDomain);
            corsManagementService.deleteCORSOrigins(applicationId, existingCORSOrigins.stream().map(CORSOrigin::getId).collect(Collectors.toList()), tenantDomain);
        } catch (CORSManagementServiceException e) {
            log.error("Error while trying to remove CORS origins associated with the application.", e);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) OpenIDConnectConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration) Arrays(java.util.Arrays) AbstractUserStoreManager(org.wso2.carbon.user.core.common.AbstractUserStoreManager) ERROR_PROCESSING_REQUEST(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_PROCESSING_REQUEST) BuildProvisioningConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.provisioning.BuildProvisioningConfiguration) Utils(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils) PrimitiveCondition(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveCondition) Autowired(org.springframework.beans.factory.annotation.Autowired) INBOUND_NOT_CONFIGURED(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.INBOUND_NOT_CONFIGURED) ApplicationResponseModel(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationResponseModel) InboundFunctions.getInboundAuthKey(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.getInboundAuthKey) RealmService(org.wso2.carbon.user.core.service.RealmService) ERROR_CODE_RESOURCE_LIMIT_REACHED(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_RESOURCE_LIMIT_REACHED) ApplicationTemplateApiModelToTemplate(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.ApplicationTemplateApiModelToTemplate) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) APPLICATION_CREATION_WITH_TEMPLATES_NOT_IMPLEMENTED(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.APPLICATION_CREATION_WITH_TEMPLATES_NOT_IMPLEMENTED) CORSManagementServiceClientException(org.wso2.carbon.identity.cors.mgt.core.exception.CORSManagementServiceClientException) FilterTreeBuilder(org.wso2.carbon.identity.core.model.FilterTreeBuilder) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) AuthProtocolMetadata(org.wso2.carbon.identity.api.server.application.management.v1.AuthProtocolMetadata) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) TemplateMgtConstants(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants) LogFactory(org.apache.commons.logging.LogFactory) OAuthInboundFunctions(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.oauth2.OAuthInboundFunctions) ApplicationBasicInfoToApiModel(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApplicationBasicInfoToApiModel) IdentityException(org.wso2.carbon.identity.base.IdentityException) ProvisioningConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.ProvisioningConfiguration) ContextLoader(org.wso2.carbon.identity.api.server.common.ContextLoader) ApplicationManagementService(org.wso2.carbon.identity.application.mgt.ApplicationManagementService) SearchContext(org.apache.cxf.jaxrs.ext.search.SearchContext) ComplexCondition(org.wso2.carbon.identity.configuration.mgt.core.search.ComplexCondition) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) CORSManagementServiceException(org.wso2.carbon.identity.cors.mgt.core.exception.CORSManagementServiceException) ApplicationManagementConstants(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants) UpdateProvisioningConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.provisioning.UpdateProvisioningConfiguration) ArrayList(java.util.ArrayList) ApplicationTemplatesListItem(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesListItem) EQUALS(org.wso2.carbon.identity.configuration.mgt.core.search.constant.ConditionType.PrimitiveOperator.EQUALS) InboundProtocolListItem(org.wso2.carbon.identity.api.server.application.management.v1.InboundProtocolListItem) SAMLInboundFunctions(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.saml.SAMLInboundFunctions) ResidentApplication(org.wso2.carbon.identity.api.server.application.management.v1.ResidentApplication) ApiModelToServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApiModelToServiceProvider) ERROR_APPLICATION_LIMIT_REACHED(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_APPLICATION_LIMIT_REACHED) Utils.buildNotImplementedError(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.buildNotImplementedError) ApplicationManagementServiceHolder(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementServiceHolder) OAUTH2(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.OAUTH2) ApplicationModel(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationModel) TemplateToApplicationTemplateListItem(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplateListItem) ImportResponse(org.wso2.carbon.identity.application.common.model.ImportResponse) PrimitiveStatement(org.apache.cxf.jaxrs.ext.search.PrimitiveStatement) IOException(java.io.IOException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) UpdateServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider) PassiveSTSInboundFunctions(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.PassiveSTSInboundFunctions) SearchCondition(org.apache.cxf.jaxrs.ext.search.SearchCondition) InboundFunctions.rollbackInbound(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.rollbackInbound) StandardInboundProtocols(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols) CORSManagementService(org.wso2.carbon.identity.cors.mgt.core.CORSManagementService) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) BiFunction(java.util.function.BiFunction) CustomInboundProtocolConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolConfiguration) ERROR_CODE_INVALID_APP_ID(org.wso2.carbon.identity.cors.mgt.core.constant.ErrorMessages.ERROR_CODE_INVALID_APP_ID) ApplicationListItem(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListItem) UNEXPECTED_SERVER_ERROR(org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.Error.UNEXPECTED_SERVER_ERROR) WSTrustConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.WSTrustConfiguration) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) User(org.wso2.carbon.identity.application.common.model.User) ApplicationPatchModel(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationPatchModel) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) Collectors(java.util.stream.Collectors) Link(org.wso2.carbon.identity.api.server.application.management.v1.Link) ApplicationConstants(org.wso2.carbon.identity.application.mgt.ApplicationConstants) List(java.util.List) PASSIVE_STS(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.PASSIVE_STS) InboundAuthConfigToApiModel(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundAuthConfigToApiModel) ApplicationTemplatesList(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesList) InboundFunctions.rollbackInbounds(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.rollbackInbounds) SAML2(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.SAML2) InboundFunctions.getInboundAuthenticationRequestConfig(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.getInboundAuthenticationRequestConfig) Template(org.wso2.carbon.identity.template.mgt.model.Template) SAML2ServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider) PassiveStsConfiguration(org.wso2.carbon.identity.api.server.application.management.v1.PassiveStsConfiguration) WS_TRUST(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.StandardInboundProtocols.WS_TRUST) INVALID_REQUEST(org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants.Error.INVALID_REQUEST) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) SpFileContent(org.wso2.carbon.identity.application.common.model.SpFileContent) ApplicationOwner(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationOwner) Function(java.util.function.Function) APPLICATION_MANAGEMENT_PATH_COMPONENT(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.APPLICATION_MANAGEMENT_PATH_COMPONENT) TemplateManagementClientException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementClientException) CollectionUtils(org.apache.commons.collections.CollectionUtils) ErrorMessages(org.wso2.carbon.identity.cors.mgt.core.constant.ErrorMessages) Util(org.wso2.carbon.identity.api.server.common.Util) InboundFunctions.updateOrInsertInbound(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.updateOrInsertInbound) TemplateToApplicationTemplate(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.template.TemplateToApplicationTemplate) WSTrustInboundFunctions(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.WSTrustInboundFunctions) TemplateManager(org.wso2.carbon.identity.template.mgt.TemplateManager) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo) ServiceProviderToApiModel(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ServiceProviderToApiModel) Utils.buildBadRequestError(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils.buildBadRequestError) ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) MalformedURLException(java.net.MalformedURLException) ErrorMessage(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage) CustomInboundFunctions(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.custom.CustomInboundFunctions) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) Node(org.wso2.carbon.identity.core.model.Node) TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) ApplicationTemplateModel(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplateModel) SAML2Configuration(org.wso2.carbon.identity.api.server.application.management.v1.SAML2Configuration) ApplicationListResponse(org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse) IdentityUtil(org.wso2.carbon.identity.core.util.IdentityUtil) Log(org.apache.commons.logging.Log) ConditionType(org.apache.cxf.jaxrs.ext.search.ConditionType) Collections(java.util.Collections) ArrayUtils(org.apache.commons.lang.ArrayUtils) InputStream(java.io.InputStream) CORSOrigin(org.wso2.carbon.identity.cors.mgt.core.model.CORSOrigin) InboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig) ApiModelToServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApiModelToServiceProvider) UpdateServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) SAML2ServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) InboundFunctions.getInboundAuthenticationRequestConfig(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.getInboundAuthenticationRequestConfig) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) CORSManagementServiceException(org.wso2.carbon.identity.cors.mgt.core.exception.CORSManagementServiceException) CORSManagementService(org.wso2.carbon.identity.cors.mgt.core.CORSManagementService)

Example 9 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerApplicationMetadataService method handleNotFoundError.

/**
 * Extract the required arguments and build a not found error.
 *
 * @param e Exception caught.
 * @return APIError with exception code, message and description.
 */
private APIError handleNotFoundError(Exception e) {
    ErrorMessage errorEnum = ERROR_WS_TRUST_METADATA_SERVICE_NOT_FOUND;
    String errorCode = errorEnum.getCode();
    String errorMessage = errorEnum.getMessage();
    String errorDescription = e.getMessage();
    return Utils.buildNotFoundError(errorCode, errorMessage, errorDescription);
}
Also used : ErrorMessage(org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)

Example 10 with APIError

use of org.wso2.carbon.identity.api.server.common.error.APIError in project identity-api-server by wso2.

the class ServerApplicationManagementService method putInbound.

/**
 * Create or replace the provided inbound configuration.
 *
 * @param <I>               Inbound API model
 * @param applicationId     Unique id of the app
 * @param inboundApiModel   Inbound API model to be created or replaced
 * @param getUpdatedInbound A function that takes the inbound API model and application as input and provides
 *                          updated inbound details.
 */
private <I> void putInbound(String applicationId, I inboundApiModel, BiFunction<ServiceProvider, I, InboundAuthenticationRequestConfig> getUpdatedInbound) {
    // We need a cloned copy of the Service Provider so that we changes we do not make cache dirty.
    ServiceProvider appToUpdate = cloneApplication(applicationId);
    // Update the service provider with the inbound configuration.
    InboundAuthenticationRequestConfig updatedInbound = getUpdatedInbound.apply(appToUpdate, inboundApiModel);
    // Add the updated inbound details
    updateOrInsertInbound(appToUpdate, updatedInbound);
    try {
        // Do the service provider update.
        updateServiceProvider(applicationId, appToUpdate);
    } catch (APIError error) {
        if (log.isDebugEnabled()) {
            log.debug("Error while updating application: " + applicationId + ". Attempting to rollback possible " + "inbound configurations created before the update.");
        }
        doRollback(applicationId, updatedInbound);
        throw error;
    }
}
Also used : ApiModelToServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.ApiModelToServiceProvider) UpdateServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.UpdateServiceProvider) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) SAML2ServiceProvider(org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider) InboundAuthenticationRequestConfig(org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig) InboundFunctions.getInboundAuthenticationRequestConfig(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.application.inbound.InboundFunctions.getInboundAuthenticationRequestConfig) APIError(org.wso2.carbon.identity.api.server.common.error.APIError)

Aggregations

APIError (org.wso2.carbon.identity.api.server.common.error.APIError)52 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)47 Response (javax.ws.rs.core.Response)41 ConnectionEstablishedResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse)4 UserStoreAttributeMappingResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreAttributeMappingResponse)4 UserStoreListResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse)4 UserStoreResponse (org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 ErrorMessage (org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage)3 FederatedAuthenticatorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListResponse)3 IdentityProviderListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderListResponse)3 IdentityProviderResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderResponse)3 IdentityProviderTemplateListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.IdentityProviderTemplateListResponse)3 OutboundConnectorListResponse (org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnectorListResponse)3 ProvisioningResponse (org.wso2.carbon.identity.api.server.idp.v1.model.ProvisioningResponse)3 OwnerResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.OwnerResponse)3 TenantsListResponse (org.wso2.carbon.identity.api.server.tenant.management.v1.model.TenantsListResponse)3 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)3 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)3