Search in sources :

Example 1 with ERROR_CODE_REPLACE_SECRET

use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_REPLACE_SECRET in project carbon-identity-framework by wso2.

the class SecretDAOImpl method replaceSecret.

@Override
public void replaceSecret(Secret secret) throws SecretManagementException {
    Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
    SecretType secretType = getSecretTypeByName(secret.getSecretType());
    NamedJdbcTemplate jdbcTemplate = getNewTemplate();
    try {
        Timestamp createdTime = jdbcTemplate.withTransaction(template -> {
            updateSecretMetadata(template, secret, secretType, currentTime);
            return getCreatedTimeInResponse(secret, secretType.getId());
        });
        secret.setLastModified(currentTime.toInstant().toString());
        if (createdTime != null) {
            secret.setCreatedTime(createdTime.toInstant().toString());
        }
        secret.setSecretType(secretType.getName());
    } catch (TransactionException e) {
        if (e.getCause() instanceof SecretManagementException) {
            throw (SecretManagementException) e.getCause();
        }
        throw handleServerException(ERROR_CODE_REPLACE_SECRET, secret.getSecretName(), e);
    }
}
Also used : SecretManagementException(org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) SecretType(org.wso2.carbon.identity.secret.mgt.core.model.SecretType) NamedJdbcTemplate(org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 NamedJdbcTemplate (org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate)1 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)1 SecretManagementException (org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException)1 SecretType (org.wso2.carbon.identity.secret.mgt.core.model.SecretType)1