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);
}
}
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);
}
}
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);
}
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;
}
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);
}
Aggregations