use of org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate in project carbon-identity-framework by wso2.
the class SecretDAOImpl method isExistingSecret.
@Override
public boolean isExistingSecret(String secretId, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
String secretName;
try {
secretName = jdbcTemplate.fetchSingleRecord(GET_SECRET_NAME_BY_ID, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME), preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretId);
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
return StringUtils.isNotEmpty(secretName);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_SECRET, "id = " + secretId, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate 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);
}
}
use of org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate in project carbon-identity-framework by wso2.
the class SecretDAOImpl method addSecretType.
@Override
public void addSecretType(SecretType secretType) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeInsert(SQLConstants.INSERT_SECRET_TYPE, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretType.getId());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_NAME, secretType.getName());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION, secretType.getDescription());
}, secretType, false);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_ADD_SECRET_TYPE, secretType.getName(), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate 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.database.utils.jdbc.NamedJdbcTemplate in project carbon-identity-framework by wso2.
the class SecretDAOImpl method replaceSecretType.
@Override
public void replaceSecretType(SecretType secretType) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeInsert(UPDATE_SECRET_TYPE, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_NAME, secretType.getName());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION, secretType.getDescription());
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_ID, secretType.getId());
}, secretType, false);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_UPDATE_SECRET_TYPE, secretType.getName(), e);
}
}
Aggregations