Search in sources :

Example 6 with RequestedClaim

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.");
    }
}
Also used : RequestObjectException(org.wso2.carbon.identity.oauth2.RequestObjectException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(net.minidev.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JSONObject(net.minidev.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with RequestedClaim

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");
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 8 with RequestedClaim

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");
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) RequestObjectDAOImpl(org.wso2.carbon.identity.openidconnect.dao.RequestObjectDAOImpl) Test(org.testng.annotations.Test)

Example 9 with RequestedClaim

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");
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) RequestObjectDAOImpl(org.wso2.carbon.identity.openidconnect.dao.RequestObjectDAOImpl) Test(org.testng.annotations.Test)

Example 10 with RequestedClaim

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;
}
Also used : RequestObjectException(org.wso2.carbon.identity.oauth2.RequestObjectException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim)

Aggregations

RequestedClaim (org.wso2.carbon.identity.openidconnect.model.RequestedClaim)20 ArrayList (java.util.ArrayList)14 List (java.util.List)9 Test (org.testng.annotations.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)5 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)5 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 BeforeClass (org.testng.annotations.BeforeClass)4 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3 Map (java.util.Map)3 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)3 RequestObjectException (org.wso2.carbon.identity.oauth2.RequestObjectException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 OpenIDConnectClaimFilterImpl (org.wso2.carbon.identity.openidconnect.OpenIDConnectClaimFilterImpl)2 RequestObjectDAOImpl (org.wso2.carbon.identity.openidconnect.dao.RequestObjectDAOImpl)2