use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE in project carbon-identity-framework by wso2.
the class SecretDAOImpl method getSecretByName.
@Override
public Secret getSecretByName(String name, SecretType secretType, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
List<SecretRawDataCollector> secretRawDataCollectors;
try {
String query = GET_SECRET_BY_NAME;
secretRawDataCollectors = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> {
SecretRawDataCollector.SecretRawDataCollectorBuilder secretRawDataCollectorBuilder = new SecretRawDataCollector.SecretRawDataCollectorBuilder().setSecretId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)).setTenantId(resultSet.getInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID)).setSecretName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME)).setSecretValue(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_VALUE)).setLastModified(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, calendar)).setCreatedTime(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, calendar)).setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION)).setSecretType(secretType.getName());
return secretRawDataCollectorBuilder.build();
}, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME, name);
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretType.getId());
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
return secretRawDataCollectors == null || secretRawDataCollectors.size() == 0 ? null : buildSecretFromRawData(secretRawDataCollectors);
} catch (DataAccessException | CryptoException e) {
throw handleServerException(ERROR_CODE_GET_SECRET, name, e);
}
}
use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE in project carbon-identity-framework by wso2.
the class SecretDAOImpl method updateSecretValue.
@Override
public Secret updateSecretValue(Secret secret, String value) throws SecretManagementException {
Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeUpdate(UPDATE_SECRET_VALUE, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secret.getSecretId());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_VALUE, value);
preparedStatement.setTimeStamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, currentTime, calendar);
});
secret.setLastModified(currentTime.toInstant().toString());
secret.setSecretValue(value);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_UPDATE_SECRET, "value", e);
}
return secret;
}
use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE in project carbon-identity-framework by wso2.
the class SecretDAOImpl method getSecretById.
@Override
public Secret getSecretById(String secretId, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
List<SecretRawDataCollector> secretRawDataCollectors;
try {
String query = GET_SECRET_BY_ID;
secretRawDataCollectors = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> {
SecretRawDataCollector.SecretRawDataCollectorBuilder secretRawDataCollectorBuilder = new SecretRawDataCollector.SecretRawDataCollectorBuilder().setSecretId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)).setTenantId(resultSet.getInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID)).setSecretName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME)).setSecretValue(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_VALUE)).setLastModified(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, calendar)).setCreatedTime(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, calendar)).setSecretType(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME)).setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION));
return secretRawDataCollectorBuilder.build();
}, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretId);
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
return secretRawDataCollectors == null || secretRawDataCollectors.size() == 0 ? null : buildSecretFromRawData(secretRawDataCollectors);
} catch (DataAccessException | CryptoException e) {
throw handleServerException(ERROR_CODE_GET_SECRET, "id = " + secretId, e);
}
}
use of org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_VALUE 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