Search in sources :

Example 6 with DB_SCHEMA_COLUMN_NAME_SECRET_NAME

use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_NAME 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);
    }
}
Also used : 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

NamedJdbcTemplate (org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate)6 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)5 Timestamp (java.sql.Timestamp)4 Date (java.util.Date)4 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)3 UTC (java.time.ZoneOffset.UTC)3 Calendar (java.util.Calendar)3 List (java.util.List)3 TimeZone (java.util.TimeZone)3 StringUtils (org.apache.commons.lang.StringUtils)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)3 CryptoException (org.wso2.carbon.core.util.CryptoException)3 NamedTemplate (org.wso2.carbon.database.utils.jdbc.NamedTemplate)3 IdentityDatabaseUtil (org.wso2.carbon.identity.core.util.IdentityDatabaseUtil)3 IdentityTenantUtil (org.wso2.carbon.identity.core.util.IdentityTenantUtil)3 LambdaExceptionUtils (org.wso2.carbon.identity.core.util.LambdaExceptionUtils)3 SQLConstants (org.wso2.carbon.identity.secret.mgt.core.constant.SQLConstants)3