use of org.wso2.carbon.database.utils.jdbc.RowMapper in project identity-inbound-auth-oauth by wso2-extensions.
the class ScopeClaimMappingDAOImpl method getScopes.
@Override
public List<ScopeDTO> getScopes(int tenantId) throws IdentityOAuth2Exception {
String sql = SQLQueries.GET_IDN_OIDC_SCOPES_CLAIMS;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
List<ScopeDTO> oidcScopeClaimList;
try {
Map<String, ScopeDTO> scopeClaimMap = new HashMap<>();
jdbcTemplate.executeQuery(sql, (RowMapper<ScopeDTO>) (resultSet, i) -> {
String scope = resultSet.getString(1);
if (!scopeClaimMap.containsKey(scope)) {
ScopeDTO tempScopeDTO = new ScopeDTO(scope, resultSet.getString(2), resultSet.getString(3), new String[] {});
if (resultSet.getString(4) != null) {
tempScopeDTO.setClaim(new String[] { resultSet.getString(4) });
}
scopeClaimMap.put(scope, tempScopeDTO);
} else {
if (resultSet.getString(4) != null) {
ScopeDTO tempScope = scopeClaimMap.get(scope);
tempScope.addNewClaimToExistingClaims(resultSet.getString(4));
scopeClaimMap.replace(scope, tempScope);
}
}
return null;
}, preparedStatement -> {
preparedStatement.setInt(1, tenantId);
preparedStatement.setString(2, Oauth2ScopeConstants.SCOPE_TYPE_OIDC);
preparedStatement.setInt(3, tenantId);
preparedStatement.setInt(4, tenantId);
preparedStatement.setString(5, OIDC_DIALECT_URI);
});
oidcScopeClaimList = new ArrayList<ScopeDTO>(scopeClaimMap.values());
} catch (DataAccessException e) {
String errorMessage = "Error occured while loading scopes claims mapping.";
throw new IdentityOAuth2Exception(errorMessage, e);
}
return oidcScopeClaimList;
}
use of org.wso2.carbon.database.utils.jdbc.RowMapper 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