Search in sources :

Example 1 with SecretManagementServerException

use of org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException in project identity-api-server by wso2.

the class SecretManagementService method handleSecretMgtException.

private APIError handleSecretMgtException(SecretManagementException e, SecretManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof SecretManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        if (ERROR_CODE_SECRET_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (ERROR_CODE_SECRET_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (e instanceof SecretManagementServerException) {
        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 : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse) Response(javax.ws.rs.core.Response) SecretManagementClientException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretManagementServerException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)

Example 2 with SecretManagementServerException

use of org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException in project identity-api-server by wso2.

the class SecretTypeManagementService method handleSecretMgtException.

private APIError handleSecretMgtException(SecretManagementException e, SecretManagementConstants.ErrorMessage errorEnum, String data) {
    ErrorResponse errorResponse;
    Response.Status status;
    if (e instanceof SecretManagementClientException) {
        errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
        if (e.getErrorCode() != null) {
            String errorCode = e.getErrorCode();
            errorResponse.setCode(errorCode);
        }
        errorResponse.setDescription(e.getMessage());
        if (ERROR_CODE_SECRET_TYPE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.CONFLICT;
        } else if (ERROR_CODE_SECRET_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            status = Response.Status.NOT_FOUND;
        } else {
            status = Response.Status.BAD_REQUEST;
        }
    } else if (e instanceof SecretManagementServerException) {
        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 : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretTypeResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse) Response(javax.ws.rs.core.Response) SecretManagementClientException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretManagementServerException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)

Example 3 with SecretManagementServerException

use of org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException in project carbon-identity-framework by wso2.

the class SecretResolveManagerImpl method getResolvedSecret.

private ResolvedSecret getResolvedSecret(Secret secret) throws SecretManagementServerException {
    ResolvedSecret resolvedSecret = new ResolvedSecret();
    resolvedSecret.setSecretId(secret.getSecretId());
    resolvedSecret.setSecretName(secret.getSecretName());
    resolvedSecret.setCreatedTime(secret.getCreatedTime());
    resolvedSecret.setLastModified(secret.getLastModified());
    resolvedSecret.setTenantDomain(secret.getTenantDomain());
    resolvedSecret.setResolvedSecretValue(getDecryptedSecretValue(secret.getSecretValue(), secret.getSecretName()));
    return resolvedSecret;
}
Also used : ResolvedSecret(org.wso2.carbon.identity.secret.mgt.core.model.ResolvedSecret)

Aggregations

Response (javax.ws.rs.core.Response)2 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)2 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)2 SecretManagementClientException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException)2 SecretManagementServerException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException)2 SecretResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)1 SecretTypeResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)1 ResolvedSecret (org.wso2.carbon.identity.secret.mgt.core.model.ResolvedSecret)1