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 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.identity.secret.mgt.core.constant.SecretConstants.DB_SCHEMA_COLUMN_NAME_SECRET_NAME 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_NAME in project carbon-identity-framework by wso2.
the class SecretDAOImpl method getSecrets.
@Override
public List getSecrets(SecretType secretType, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
return jdbcTemplate.executeQuery(GET_SECRETS, (LambdaExceptionUtils.rethrowRowMapper((resultSet, rowNumber) -> {
String secretId = resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID);
String secretName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME);
String secretLastModified = resultSet.getString(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED);
String secretCreatedTime = resultSet.getString(DB_SCHEMA_COLUMN_NAME_CREATED_TIME);
String description = resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION);
Secret secret = new Secret();
secret.setCreatedTime(secretCreatedTime);
secret.setSecretId(secretId);
secret.setSecretName(secretName);
secret.setLastModified(secretLastModified);
secret.setTenantDomain(IdentityTenantUtil.getTenantDomain(tenantId));
secret.setSecretType(secretType.getName());
secret.setDescription(description);
return secret;
})), preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretType.getId());
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_SECRETS_DOES_NOT_EXISTS, e);
}
}
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 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_NAME in project carbon-identity-framework by wso2.
the class SecretDAOImpl method deleteSecretByName.
@Override
public void deleteSecretByName(String name, String secretTypeId, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
try {
jdbcTemplate.executeUpdate(SQLConstants.DELETE_SECRET, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME, name);
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretTypeId);
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_DELETE_SECRET, e);
}
}
Aggregations