Search in sources :

Example 1 with SecretAddRequest

use of org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest 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 2 with SecretAddRequest

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

the class SecretManagementService method buildSecretAddFromSecretUpdateRequest.

/**
 * Build secretAdd object from secret update request.
 *
 * @param name                Secret name.
 * @param secretUpdateRequest Secret's update request body.
 * @return secretAdd object
 */
private SecretAddRequest buildSecretAddFromSecretUpdateRequest(String name, SecretUpdateRequest secretUpdateRequest) {
    SecretAddRequest secretAddRequest = new SecretAddRequest();
    secretAddRequest.setName(name);
    secretAddRequest.setValue(secretUpdateRequest.getValue());
    if (!StringUtils.isEmpty(secretUpdateRequest.getDescription())) {
        secretAddRequest.setDescription(secretUpdateRequest.getDescription());
    }
    return secretAddRequest;
}
Also used : SecretAddRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest)

Example 3 with SecretAddRequest

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

the class SecretManagementService method buildSecretRequestDTOFromSecretAddRequest.

/**
 * Build secret requestDTO by secret body request.
 *
 * @param secretAddRequest Secret post body.
 * @return Secret requestDTO object.
 */
private Secret buildSecretRequestDTOFromSecretAddRequest(SecretAddRequest secretAddRequest) {
    Secret requestDTO = new Secret();
    requestDTO.setSecretName(secretAddRequest.getName());
    requestDTO.setSecretValue(secretAddRequest.getValue());
    requestDTO.setDescription(secretAddRequest.getDescription());
    return requestDTO;
}
Also used : Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret)

Example 4 with SecretAddRequest

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

the class SecretManagementService method updateSecret.

/**
 * Update secret details by name.
 *
 * @param secretType          Secret type name.
 * @param name                Secret name.
 * @param secretUpdateRequest Secret's updated details.
 * @return Updated secret.
 */
public SecretResponse updateSecret(String secretType, String name, SecretUpdateRequest secretUpdateRequest) {
    Secret requestDTO, responseDTO;
    SecretAddRequest secretAddRequest = buildSecretAddFromSecretUpdateRequest(name, secretUpdateRequest);
    try {
        requestDTO = buildSecretRequestDTOFromSecretAddRequest(secretAddRequest);
        responseDTO = SecretManagementServiceHolder.getSecretConfigManager().replaceSecret(secretType, requestDTO);
    } 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) SecretAddRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)

Example 5 with SecretAddRequest

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

the class SecretsApiServiceImpl method createSecret.

@Override
public Response createSecret(String secretType, SecretAddRequest secretAddRequest) {
    SecretResponse secretResponse = secretManagementService.addSecret(secretType, secretAddRequest);
    URI location = ContextLoader.buildURIForHeader(V1_API_PATH_COMPONENT + SECRET_CONTEXT_PATH + "/" + secretResponse.getSecretName());
    return Response.created(location).entity(secretResponse).build();
}
Also used : SecretResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse) URI(java.net.URI)

Aggregations

Secret (org.wso2.carbon.identity.secret.mgt.core.model.Secret)3 SecretAddRequest (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretAddRequest)2 SecretManagementException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)2 URI (java.net.URI)1 SecretResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretResponse)1