use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeClaimMappingDAOImpl method getClaims.
@Override
public ScopeDTO getClaims(String scope, int tenantId) throws IdentityOAuth2Exception {
String sql = SQLQueries.GET_IDN_OIDC_CLAIMS;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
ScopeDTO scopeDTO = new ScopeDTO();
try {
List<String> claimsList = jdbcTemplate.executeQuery(sql, (resultSet, i) -> resultSet.getString(1), preparedStatement -> {
preparedStatement.setString(1, scope);
preparedStatement.setInt(2, tenantId);
});
scopeDTO.setName(scope);
String[] claimsArr = new String[claimsList.size()];
scopeDTO.setClaim(claimsList.toArray(claimsArr));
} catch (DataAccessException e) {
String errorMessage = "Error while loading OIDC claims for the scope: " + scope;
throw new IdentityOAuth2Exception(errorMessage, e);
}
return scopeDTO;
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectDAOImpl method getRequestedClaimsbySessionDataKey.
/**
* Retrieve Requested claims for the sessionDataKey and user info endpoint.
*
* @param sessionDataKey sessionDataKey
* @param isUserInfo isUserInfo
* @throws IdentityOAuth2Exception
*/
@Override
public List<RequestedClaim> getRequestedClaimsbySessionDataKey(String sessionDataKey, boolean isUserInfo) throws IdentityOAuth2Exception {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet resultSet = null;
List<RequestedClaim> essentialClaims = new ArrayList<>();
try {
connection = IdentityDatabaseUtil.getDBConnection(false);
String sql = isH2DB() ? SQLQueries.RETRIEVE_REQUESTED_CLAIMS_BY_SESSION_DATA_KEY_H2 : SQLQueries.RETRIEVE_REQUESTED_CLAIMS_BY_SESSION_DATA_KEY;
prepStmt = connection.prepareStatement(sql);
prepStmt.setString(1, sessionDataKey);
prepStmt.setString(2, isUserInfo ? "1" : "0");
resultSet = prepStmt.executeQuery();
while (resultSet.next()) {
RequestedClaim requestedClaim = new RequestedClaim();
requestedClaim.setName(resultSet.getString(1));
requestedClaim.setEssential(!"0".equals(resultSet.getString(2)));
requestedClaim.setValue(resultSet.getString(3));
essentialClaims.add(requestedClaim);
}
} catch (DataAccessException | SQLException e) {
String errorMsg = "Error occurred while retrieving request object by session data key: " + sessionDataKey + ", isUserInfo: " + isUserInfo;
throw new IdentityOAuth2Exception(errorMsg, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, resultSet, prepStmt);
}
return essentialClaims;
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeClaimMappingDAOImpl method getScope.
/**
* Get OIDC scope details by scope name.
*
* @param scopeName Scope name.
* @param tenantId Tenant ID.
* @return OIDC scope object.
* @throws IdentityOAuth2Exception
*/
@Override
public ScopeDTO getScope(String scopeName, int tenantId) throws IdentityOAuth2Exception {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
String sql = SQLQueries.GET_IDN_OIDC_SCOPE_DETAILS;
try {
Map<String, ScopeDTO> tempScopeMap = new HashMap<>();
jdbcTemplate.executeQuery(sql, (RowMapper<ScopeDTO>) (resultSet, i) -> {
if (!tempScopeMap.containsKey(resultSet.getString(1))) {
ScopeDTO scopeDTO = new ScopeDTO(resultSet.getString(1), resultSet.getString(2), resultSet.getString(3), new String[] {});
if (resultSet.getString(4) != null) {
scopeDTO.setClaim(new String[] { resultSet.getString(4) });
}
tempScopeMap.put(resultSet.getString(1), scopeDTO);
} else {
if (resultSet.getString(4) != null) {
ScopeDTO tempScope = tempScopeMap.get(resultSet.getString(1));
tempScope.addNewClaimToExistingClaims(resultSet.getString(4));
tempScopeMap.replace(resultSet.getString(1), tempScope);
}
}
return null;
}, preparedStatement -> {
preparedStatement.setString(1, scopeName);
preparedStatement.setInt(2, tenantId);
preparedStatement.setString(3, Oauth2ScopeConstants.SCOPE_TYPE_OIDC);
preparedStatement.setInt(4, tenantId);
preparedStatement.setInt(5, tenantId);
preparedStatement.setString(6, OIDC_DIALECT_URI);
});
return tempScopeMap.get(scopeName);
} catch (DataAccessException e) {
String errorMessage = "Error while fetching scope details for scope: " + scopeName;
throw new IdentityOAuth2Exception(errorMessage, e);
}
}
Aggregations