Search in sources :

Example 1 with SecretTypeResponse

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

the class SecretDAOImpl method getSecretTypeByName.

@Override
public SecretType getSecretTypeByName(String secretTypeName) throws SecretManagementException {
    NamedJdbcTemplate jdbcTemplate = getNewTemplate();
    SecretType secretTypeResponse;
    try {
        secretTypeResponse = jdbcTemplate.fetchSingleRecord(GET_SECRET_TYPE_BY_NAME, (resultSet, rowNumber) -> {
            SecretType secretType = new SecretType();
            secretType.setId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID));
            secretType.setName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME));
            secretType.setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION));
            return secretType;
        }, preparedStatement -> preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_NAME, secretTypeName));
        return secretTypeResponse;
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_RETRIEVE_SECRET_TYPE, secretTypeName, e);
    }
}
Also used : DB_SCHEMA_COLUMN_NAME_CREATED_TIME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_CREATED_TIME) DB_SCHEMA_COLUMN_NAME_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_TYPE) StringUtils(org.apache.commons.lang.StringUtils) GET_SECRET_BY_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_BY_ID) IdentityDatabaseUtil(org.wso2.carbon.identity.core.util.IdentityDatabaseUtil) UPDATE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_TYPE) Date(java.util.Date) GET_SECRET_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_BY_NAME) DB_SCHEMA_COLUMN_NAME_SECRET_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_NAME) SecretUtils.handleServerException(org.wso2.carbon.identity.secret.mgt.core.util.SecretUtils.handleServerException) ERROR_CODE_ADD_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_ADD_SECRET_TYPE) UPDATE_SECRET_DESCRIPTION(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_DESCRIPTION) ERROR_CODE_UPDATE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_UPDATE_SECRET_TYPE) ERROR_CODE_SECRETS_DOES_NOT_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRETS_DOES_NOT_EXISTS) ERROR_CODE_DELETE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_DELETE_SECRET) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) LambdaExceptionUtils(org.wso2.carbon.identity.core.util.LambdaExceptionUtils) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) GET_SECRET_NAME_BY_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_NAME_BY_ID) UPDATE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET) Secret(org.wso2.carbon.identity.secret.mgt.core.model.Secret) DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED) List(java.util.List) ERROR_CODE_UPDATE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_UPDATE_SECRET) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) UTC(java.time.ZoneOffset.UTC) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_GET_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_GET_SECRET) SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) INSERT_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.INSERT_SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) DB_SCHEMA_COLUMN_NAME_SECRET_VALUE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE) GET_SECRET_TYPE_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_TYPE_BY_NAME) Calendar(java.util.Calendar) DB_SCHEMA_COLUMN_NAME_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_NAME) SQLConstants(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants) SecretDAO(org.wso2.carbon.identity.secret.mgt.core.dao.SecretDAO) GET_SECRETS(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRETS) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ADD_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_ADD_SECRET) CryptoException(org.wso2.carbon.core.util.CryptoException) ERROR_CODE_SECRET_ALREADY_EXISTS(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_SECRET_ALREADY_EXISTS) ERROR_CODE_REPLACE_SECRET(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_REPLACE_SECRET) GET_SECRET_CREATED_TIME_BY_NAME(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.GET_SECRET_CREATED_TIME_BY_NAME) NamedTemplate(org.wso2.carbon.database.utils.jdbc.NamedTemplate) UPDATE_SECRET_VALUE(org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.UPDATE_SECRET_VALUE) ERROR_CODE_DELETE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_DELETE_SECRET_TYPE) SecretUtils.handleClientException(org.wso2.carbon.identity.secret.mgt.core.util.SecretUtils.handleClientException) DB_SCHEMA_COLUMN_NAME_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_ID) DB_SCHEMA_COLUMN_NAME_TENANT_ID(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_TENANT_ID) Log(org.apache.commons.logging.Log) DB_SCHEMA_COLUMN_NAME_DESCRIPTION(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_DESCRIPTION) ERROR_CODE_RETRIEVE_SECRET_TYPE(org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_RETRIEVE_SECRET_TYPE) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 2 with SecretTypeResponse

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

the class SecretTypeManagementService method updateTypeSecret.

/**
 * Update secret details by name.
 *
 * @param name                Secret name.
 * @param secretUpdateRequest Secret's updated details.
 * @return Updated secret.
 */
public SecretTypeResponse updateTypeSecret(String name, SecretTypeUpdateRequest secretUpdateRequest) {
    SecretType requestDTO, responseDTO;
    SecretTypeAddRequest secretAdd = buildSecretTypeAddFromSecretTypeUpdateRequest(name, secretUpdateRequest);
    try {
        requestDTO = buildSecretTypeRequestDTOFromSecretTypeAddRequest(secretAdd);
        responseDTO = SecretManagementServiceHolder.getSecretConfigManager().replaceSecretType(requestDTO);
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_SECRET, name);
    }
    return buildSecretTypeResponseFromResponseDTO(responseDTO);
}
Also used : SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) SecretTypeAddRequest(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeAddRequest)

Example 3 with SecretTypeResponse

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

the class SecretTypeManagementService method getSecretType.

/**
 * Retrieve the secret details by name.
 *
 * @param secretTypeName Secret name.
 * @return secret.
 */
public SecretTypeResponse getSecretType(String secretTypeName) {
    try {
        SecretType responseDTO = SecretManagementServiceHolder.getSecretConfigManager().getSecretType(secretTypeName);
        SecretTypeResponse secretTypeResponse = new SecretTypeResponse();
        secretTypeResponse.setId(responseDTO.getId());
        secretTypeResponse.setName(responseDTO.getName());
        secretTypeResponse.description(responseDTO.getDescription());
        return secretTypeResponse;
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_SECRET, secretTypeName);
    }
}
Also used : SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) SecretTypeResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)

Example 4 with SecretTypeResponse

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

the class SecretTypeManagementService method addSecretType.

/**
 * Create a secret Type.
 *
 * @param secretTypeAddRequest Secret post request.
 * @return secret.
 */
public SecretTypeResponse addSecretType(SecretTypeAddRequest secretTypeAddRequest) {
    validateSecretTypeAddRequest(secretTypeAddRequest);
    SecretType requestDTO, responseDTO;
    try {
        requestDTO = buildSecretTypeRequestDTOFromSecretTypeAddRequest(secretTypeAddRequest);
        responseDTO = SecretManagementServiceHolder.getSecretConfigManager().addSecretType(requestDTO);
    } catch (SecretManagementException e) {
        throw handleSecretMgtException(e, SecretManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_SECRET, secretTypeAddRequest.getName());
    }
    return buildSecretTypeResponseFromResponseDTO(responseDTO);
}
Also used : SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType)

Example 5 with SecretTypeResponse

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

the class SecretTypeManagementService method buildSecretTypeResponseFromResponseDTO.

/**
 * To create Secret Response object for the post request
 *
 * @param secretTypeReq Secret object.
 * @return {@link SecretTypeResponse} .
 */
private SecretTypeResponse buildSecretTypeResponseFromResponseDTO(SecretType secretTypeReq) {
    SecretTypeResponse secretTypeResponse = new SecretTypeResponse();
    secretTypeResponse.setId(secretTypeReq.getId());
    secretTypeResponse.setName(secretTypeReq.getName());
    secretTypeResponse.setDescription(secretTypeReq.getDescription());
    return secretTypeResponse;
}
Also used : SecretTypeResponse(org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)

Aggregations

SecretManagementException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)4 SecretType (org.wso2.carbon.identity.secret.mgt.core.model.SecretType)4 SecretTypeResponse (org.wso2.carbon.identity.api.server.secret.management.v1.model.SecretTypeResponse)3 URI (java.net.URI)1 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)1 Timestamp (java.sql.Timestamp)1 UTC (java.time.ZoneOffset.UTC)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 List (java.util.List)1 TimeZone (java.util.TimeZone)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 CryptoException (org.wso2.carbon.core.util.CryptoException)1 NamedJdbcTemplate (org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate)1 NamedTemplate (org.wso2.carbon.database.utils.jdbc.NamedTemplate)1 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)1 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)1