use of org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants.INSERT_SECRET in project carbon-identity-framework by wso2.
the class SecretDAOImpl method addSecret.
@Override
public void addSecret(Secret secret) throws SecretManagementException {
SecretType secretType = getSecretTypeByName(secret.getSecretType());
Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.withTransaction(template -> {
// Insert secret metadata.
template.executeInsert(INSERT_SECRET, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secret.getSecretId());
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME, secret.getSecretName());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_VALUE, secret.getSecretValue());
preparedStatement.setTimeStamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, currentTime, calendar);
preparedStatement.setTimeStamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, currentTime, calendar);
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretType.getId());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION, secret.getDescription());
}, secret, false);
return null;
});
secret.setLastModified(currentTime.toInstant().toString());
secret.setCreatedTime(currentTime.toInstant().toString());
secret.setSecretType(secretType.getName());
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_ADD_SECRET, secret.getSecretName(), e);
}
}
Aggregations