use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObject method processClaimObject.
/**
* To process the claim object which comes with the request object.
*
* @param jsonObjectRequestedClaims requested claims of the request object
* @throws ParseException
*/
private void processClaimObject(JSONObject jsonObjectRequestedClaims) throws RequestObjectException {
try {
Map<String, List<RequestedClaim>> claimsforClaimRequestor = new HashMap<>();
if (jsonObjectRequestedClaims.get(CLAIMS) != null) {
JSONObject jsonObjectClaim = (JSONObject) jsonObjectRequestedClaims.get(CLAIMS);
// To iterate the claims json object to fetch the claim requestor and all requested claims.
for (Map.Entry<String, Object> requesterClaimsMap : jsonObjectClaim.entrySet()) {
List<RequestedClaim> requestedClaimsList = new ArrayList();
if (jsonObjectClaim.get(requesterClaimsMap.getKey()) != null) {
// Get requested claim object
Object requestedClaimObject = jsonObjectClaim.get(requesterClaimsMap.getKey());
// Extract all requested claims if attribute is an JSONObject
if (requestedClaimObject instanceof JSONObject) {
JSONObject jsonObjectAllRequestedClaims = (JSONObject) jsonObjectClaim.get(requesterClaimsMap.getKey());
if (jsonObjectAllRequestedClaims != null) {
for (Map.Entry<String, Object> requestedClaims : jsonObjectAllRequestedClaims.entrySet()) {
JSONObject jsonObjectClaimAttributes = null;
if (jsonObjectAllRequestedClaims.get(requestedClaims.getKey()) != null) {
jsonObjectClaimAttributes = (JSONObject) jsonObjectAllRequestedClaims.get(requestedClaims.getKey());
}
populateRequestedClaimValues(requestedClaimsList, jsonObjectClaimAttributes, requestedClaims.getKey(), requesterClaimsMap.getKey());
}
}
}
}
claimsforClaimRequestor.put(requesterClaimsMap.getKey(), requestedClaimsList);
}
this.setRequestedClaims(claimsforClaimRequestor);
}
} catch (ClassCastException e) {
throw new RequestObjectException(OAuth2ErrorCodes.INVALID_REQUEST, "Requested \"claims\" in Request " + "Object is in invalid format.");
}
}
use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.
the class OpenIDConnectClaimFilterImplTest method testGetClaimsFilteredByEssentialClaimsWithNullValue.
@Test
public void testGetClaimsFilteredByEssentialClaimsWithNullValue() throws Exception {
claims = new HashMap<>();
claims.put("testUserClaimURI", "value1");
claims.put("testUserClaimURI2", "value2");
List requestedClaims = new ArrayList<>();
RequestedClaim requestedClaim = new RequestedClaim();
requestedClaim.setName("testUserClaimURI");
requestedClaim.setEssential(true);
requestedClaims.add(requestedClaim);
Map<String, Object> filteredClaims = openIDConnectClaimFilter.getClaimsFilteredByEssentialClaims(claims, requestedClaims);
Assert.assertNotNull(filteredClaims.get("testUserClaimURI"));
Assert.assertNull(filteredClaims.get("testUserClaimURI2"));
Assert.assertEquals(((String) filteredClaims.get("testUserClaimURI")), "value1");
}
use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectServiceTest method testGetRequestedClaimsForUserInfo.
@Test
public void testGetRequestedClaimsForUserInfo() throws Exception {
RequestObjectDAOImpl requestObjectDAO = new RequestObjectDAOImpl();
requestObjectService.addRequestObject(consumerKey, sessionKey, requestedEssentialClaims);
addToken(token, tokenId);
requestObjectDAO.updateRequestObjectReferencebyTokenId(sessionKey, tokenId);
List<RequestedClaim> claims = requestObjectService.getRequestedClaimsForUserInfo(token);
Assert.assertEquals(claims.get(0).getName(), "email");
}
use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectServiceTest method testGetRequestedClaimsForUserInfoException.
@Test(expectedExceptions = { IdentityOAuth2Exception.class })
public void testGetRequestedClaimsForUserInfoException() throws Exception {
RequestObjectDAOImpl requestObjectDAO = new RequestObjectDAOImpl();
requestObjectService.addRequestObject(consumerKey, sessionKey, requestedEssentialClaims);
requestObjectDAO.updateRequestObjectReferencebyTokenId(sessionKey, invalidTokenId);
addToken(token, tokenId);
List<RequestedClaim> claims = requestObjectService.getRequestedClaimsForUserInfo(token);
Assert.assertEquals(claims.get(0).getName(), "email");
}
use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.
the class RequestObjectService method getRequestedClaims.
/**
* To invoke the RequestObjectPersistenceFactory to retrieve request object.
*
* @param token access token Id
* @return list of claims which have marked as essential in the request object.
* @throws RequestObjectException
*/
private List<RequestedClaim> getRequestedClaims(String token, boolean isUserInfo) throws RequestObjectException {
boolean isRequestObjectEnabled = OAuthServerConfiguration.getInstance().isRequestObjectEnabled();
if (!isRequestObjectEnabled) {
log.debug("Request Object Flow is disabled, hence dropping the event");
return Collections.emptyList();
}
List<RequestedClaim> essentialClaims;
if (log.isDebugEnabled()) {
log.debug("Invoking the RequestObjectPersistenceFactory to retrieve essential claims list.");
}
try {
essentialClaims = OAuthTokenPersistenceFactory.getInstance().getRequestObjectDAO().getRequestedClaims(token, isUserInfo);
} catch (IdentityOAuth2Exception e) {
throw new RequestObjectException(e.getMessage());
}
return essentialClaims;
}
Aggregations