use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getResourceTypeByIdentifier.
private ResourceType getResourceTypeByIdentifier(String name, String id) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
ResourceType resourceTypeResponse;
try {
resourceTypeResponse = jdbcTemplate.fetchSingleRecord(selectGetResourceTypeQuery(id), (resultSet, rowNumber) -> {
ResourceType resourceType = new ResourceType();
resourceType.setId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID));
resourceType.setName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME));
resourceType.setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTTION));
return resourceType;
}, preparedStatement -> preparedStatement.setString(1, StringUtils.isEmpty(name) ? id : name));
return resourceTypeResponse;
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_RETRIEVE_RESOURCE_TYPE, name, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class SAMLSSOServiceProviderDAO method getApplicationCertificateId.
/**
* Returns the certificate reference ID for the given issuer (Service Provider) if there is one.
*
* @param issuer
* @return
* @throws SQLException
*/
private int getApplicationCertificateId(String issuer, int tenantId) throws SQLException {
try {
String sqlStmt = isH2DB() ? QUERY_TO_GET_APPLICATION_CERTIFICATE_ID_H2 : QUERY_TO_GET_APPLICATION_CERTIFICATE_ID;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement statementToGetApplicationCertificate = connection.prepareStatement(sqlStmt)) {
statementToGetApplicationCertificate.setString(1, CERTIFICATE_PROPERTY_NAME);
statementToGetApplicationCertificate.setString(2, issuer);
statementToGetApplicationCertificate.setInt(3, tenantId);
try (ResultSet queryResults = statementToGetApplicationCertificate.executeQuery()) {
if (queryResults.next()) {
return queryResults.getInt(1);
}
}
}
return -1;
} catch (DataAccessException e) {
String errorMsg = "Error while retrieving application certificate data for issuer: " + issuer + " and tenant Id: " + tenantId;
throw new SQLException(errorMsg, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getIdentityPropertiesByIdpId.
/**
* Get Identity properties map.
*
* @param dbConnection database connection
* @param idpId IDP Id
* @return Identity provider properties
*/
private List<IdentityProviderProperty> getIdentityPropertiesByIdpId(Connection dbConnection, int idpId) throws SQLException {
PreparedStatement prepStmt = null;
ResultSet rs = null;
List<IdentityProviderProperty> idpProperties = new ArrayList<IdentityProviderProperty>();
try {
String sqlStmt = isH2DB() ? IdPManagementConstants.SQLQueries.GET_IDP_METADATA_BY_IDP_ID_H2 : IdPManagementConstants.SQLQueries.GET_IDP_METADATA_BY_IDP_ID;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setInt(1, idpId);
rs = prepStmt.executeQuery();
while (rs.next()) {
IdentityProviderProperty property = new IdentityProviderProperty();
property.setName(rs.getString("NAME"));
property.setValue(rs.getString("VALUE"));
property.setDisplayName(rs.getString("DISPLAY_NAME"));
idpProperties.add(property);
}
} catch (DataAccessException e) {
throw new SQLException("Error while retrieving IDP properties for IDP ID: " + idpId, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
}
return idpProperties;
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class IdPManagementDAO method addIdentityProviderProperties.
/**
* Add Identity provider properties
*
* @param dbConnection
* @param idpId
* @param properties
* @throws SQLException
*/
private void addIdentityProviderProperties(Connection dbConnection, int idpId, List<IdentityProviderProperty> properties, int tenantId) throws SQLException {
PreparedStatement prepStmt = null;
try {
String sqlStmt = isH2DB() ? IdPManagementConstants.SQLQueries.ADD_IDP_METADATA_H2 : IdPManagementConstants.SQLQueries.ADD_IDP_METADATA;
prepStmt = dbConnection.prepareStatement(sqlStmt);
for (IdentityProviderProperty property : properties) {
if (property.getValue() != null) {
prepStmt.setInt(1, idpId);
prepStmt.setString(2, property.getName());
prepStmt.setString(3, property.getValue());
prepStmt.setString(4, property.getDisplayName());
prepStmt.setInt(5, tenantId);
prepStmt.addBatch();
} else {
if (log.isDebugEnabled()) {
String msg = "IDP property '%s' of IDP with id:%d of tenantId:%d is null. " + "Not adding the property to 'IDP_METADATA' table.";
log.debug(String.format(msg, property.getName(), idpId, tenantId));
}
}
}
prepStmt.executeBatch();
} catch (DataAccessException e) {
String errorMsg = "Error while adding IDP properties for IDP ID: " + idpId + " and tenant ID:" + tenantId;
throw new SQLException(errorMsg, e);
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class TemplateManagerDAOImpl method getTemplateByName.
/**
* Retrieve {@link Template} by template name and tenant Id.
*
* @param templateName name of the {@link Template} to retrieve.
* @param tenantId tenant Id of the tenant which the {@link Template} resides.
* @return {@link Template} for the given name and tenant Id.
* @throws TemplateManagementException If error occurs while retrieving {@link Template}.
*/
public Template getTemplateByName(String templateName, Integer tenantId) throws TemplateManagementException {
Template template;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
template = jdbcTemplate.fetchSingleRecord(GET_TEMPLATE_BY_NAME, ((resultSet, rowNumber) -> {
Template templateResult;
try {
templateResult = new Template(resultSet.getString(1), resultSet.getString(2), IOUtils.toString(resultSet.getBinaryStream(3)));
} catch (IOException e) {
// SQLException is thrown since the QueryFilter throws an SQLException
throw new TemplateManagementSQLException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
}
return templateResult;
}), preparedStatement -> {
preparedStatement.setString(1, templateName);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw new TemplateManagementServerException(String.format(ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getMessage(), tenantId, templateName), ERROR_CODE_SELECT_TEMPLATE_BY_NAME.getCode(), e);
}
return template;
}
Aggregations