Search in sources :

Example 1 with SecretResponse

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse in project identity-api-server by wso2.

the class SecretManagementService method getSecretsList.

/**
 * Retrieve all the secrets of the tenant.
 *
 * @param secretType Secret type name.
 * @return Secrets of the tenant.
 */
public List<SecretResponse> getSecretsList(String secretType) {
    try {
        Secrets secrets = SecretManagementServiceHolder.getSecretConfigManager().getSecrets(secretType);
        List<Secret> secretsList = secrets.getSecrets();
        return secretsList.stream().map(secret -> buildSecretResponseFromResponseDTO(secret)).collect(Collectors.toList());
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_SECRET, null);
    }
}
Also used : Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) StringUtils(org.apache.commons.lang.StringUtils) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) SecretAddRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest) SecretManagementConstants(org.wso2.carbon.identity.api.server.secret.management.common.SecretManagementConstants) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) Secrets(org.wso2.carbon.identity.secret.mgt.core.model.Secrets) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse) ERROR_CODE_SECRET_ALREADY_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_ALREADY_EXISTS) SecretUpdateRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretUpdateRequest) Collectors(java.util.stream.Collectors) SecretManagementServerException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementServerException) Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) List(java.util.List) ERROR_CODE_SECRET_DOES_NOT_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_DOES_NOT_EXISTS) SecretPatchRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretPatchRequest) SecretManagementClientException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException) Response(javax.ws.rs.core.Response) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) SecretManagementServiceHolder(org.wso2.carbon.identity.api.server.secret.management.common.SecretManagementServiceHolder) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) Secrets(org.wso2.carbon.identity.secret.mgt.core.model.Secrets)

Example 2 with SecretResponse

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse in project identity-api-server by wso2.

the class SecretManagementService method getSecret.

/**
 * Retrieve the secret details by name.
 *
 * @param secretType Secret type name.
 * @param name       Secret name.
 * @return secret.
 */
public SecretResponse getSecret(String secretType, String name) {
    try {
        Secret responseDTO = SecretManagementServiceHolder.getSecretConfigManager().getSecret(secretType, name);
        SecretResponse secretResponse = new SecretResponse();
        secretResponse.secretName(responseDTO.getSecretName());
        secretResponse.setCreated(responseDTO.getCreatedTime());
        secretResponse.setLastModified(responseDTO.getLastModified());
        secretResponse.setSecretId(responseDTO.getSecretId());
        secretResponse.setType(responseDTO.getSecretType());
        secretResponse.setDescription(responseDTO.getDescription());
        return secretResponse;
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_SECRET, name);
    }
}
Also used : Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)

Example 3 with SecretResponse

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse in project identity-api-server by wso2.

the class SecretManagementService method addSecret.

/**
 * Create a secret.
 *
 * @param secretType       Secret type name.
 * @param secretAddRequest Secret post request.
 * @return secret.
 */
public SecretResponse addSecret(String secretType, SecretAddRequest secretAddRequest) {
    validateSecretAddRequest(secretAddRequest);
    Secret requestDTO, responseDTO;
    try {
        requestDTO = buildSecretRequestDTOFromSecretAddRequest(secretAddRequest);
        responseDTO = SecretManagementServiceHolder.getSecretConfigManager().addSecret(secretType, requestDTO);
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_SECRET, secretAddRequest.getName());
    }
    return buildSecretResponseFromResponseDTO(responseDTO);
}
Also used : Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)

Example 4 with SecretResponse

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse in project identity-api-server by wso2.

the class SecretManagementService method buildSecretResponseFromResponseDTO.

/**
 * To create Secret Response object for the post request
 *
 * @param responseDTO Secret object.
 * @return {@link SecretResponse} .
 */
private SecretResponse buildSecretResponseFromResponseDTO(Secret responseDTO) {
    SecretResponse secretResponse = new SecretResponse();
    secretResponse.secretName(responseDTO.getSecretName());
    secretResponse.setCreated(responseDTO.getCreatedTime());
    secretResponse.setLastModified(responseDTO.getLastModified());
    secretResponse.setSecretId(responseDTO.getSecretId());
    secretResponse.setType(responseDTO.getSecretType());
    secretResponse.setDescription(responseDTO.getDescription());
    return secretResponse;
}
Also used : SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)

Example 5 with SecretResponse

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse in project identity-api-server by wso2.

the class SecretManagementService method patchSecret.

/**
 * To make a partial update or update the specific property of the secret.
 *
 * @param secretType         Secret type name.
 * @param name               Secret name.
 * @param secretPatchRequest Secret's patch details.
 * @return Updated secret.
 */
public SecretResponse patchSecret(String secretType, String name, SecretPatchRequest secretPatchRequest) {
    Secret secret, responseDTO;
    try {
        secret = SecretManagementServiceHolder.getSecretConfigManager().getSecret(secretType, name);
        if (secret == null) {
            throw handleException(Response.Status.NOT_FOUND, SecretManagementConstants.ErrorMessage.ERROR_CODE_SECRET_NOT_FOUND, name);
        }
        String path = secretPatchRequest.getPath();
        SecretPatchRequest.OperationEnum operation = secretPatchRequest.getOperation();
        // Only the Replace operation supported with PATCH request.
        if (SecretPatchRequest.OperationEnum.REPLACE.equals(operation)) {
            if (SecretManagementConstants.VALUE_PATH.equals(path)) {
                responseDTO = SecretManagementServiceHolder.getSecretConfigManager().updateSecretValue(secretType, name, secretPatchRequest.getValue());
            } else if (SecretManagementConstants.DESCRIPTION_PATH.equals(path)) {
                responseDTO = SecretManagementServiceHolder.getSecretConfigManager().updateSecretDescription(secretType, name, secretPatchRequest.getValue());
            } else {
                throw handleException(Response.Status.BAD_REQUEST, SecretManagementConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT, "Path");
            }
        } else {
            // Throw an error if any other patch operations are sent in the request.
            throw handleException(Response.Status.BAD_REQUEST, SecretManagementConstants.ErrorMessage.ERROR_CODE_INVALID_INPUT, "Operation");
        }
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_SECRET, name);
    }
    return buildSecretResponseFromResponseDTO(responseDTO);
}
Also used : Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) SecretPatchRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretPatchRequest)

Aggregations

SecretManagementException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)5 Secret (org.wso2.carbon.identity.secret.mgt.core.model.Secret)5 SecretResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)4 SecretAddRequest (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest)2 SecretPatchRequest (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretPatchRequest)2 URI (java.net.URI)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)1 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)1 SecretManagementConstants (org.wso2.carbon.identity.api.server.secret.management.common.SecretManagementConstants)1 SecretManagementServiceHolder (org.wso2.carbon.identity.api.server.secret.management.common.SecretManagementServiceHolder)1 SecretUpdateRequest (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretUpdateRequest)1 ERROR_CODE_SECRET_ALREADY_EXISTS (org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_ALREADY_EXISTS)1 ERROR_CODE_SECRET_DOES_NOT_EXISTS (org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_DOES_NOT_EXISTS)1 SecretManagementClientException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementClientException)1