Search in sources :

Example 21 with RequestedClaim

use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.

the class RequestObjectDAOImplTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    requestObjectDAO = new RequestObjectDAOImpl();
    requestedEssentialClaims = new ArrayList<>();
    List lstRequestedClaims = new ArrayList<>();
    List values = new ArrayList<>();
    RequestedClaim requestedClaim = new RequestedClaim();
    requestedClaim.setName("email");
    requestedClaim.setType("userinfo");
    requestedClaim.setValue("value1");
    requestedClaim.setEssential(true);
    requestedClaim.setValues(values);
    values.add("val1");
    values.add("val2");
    requestedClaim.setValues(values);
    lstRequestedClaims.add(requestedClaim);
    requestedEssentialClaims.add(lstRequestedClaims);
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BeforeClass(org.testng.annotations.BeforeClass)

Example 22 with RequestedClaim

use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method getRequestedOidcClaimsList.

/**
 * Filter requested claims based on OIDC claims and return the claims which includes in OIDC.
 *
 * @param claimsForApproval         Consent required claims.
 * @param oauth2Params              OAuth parameters.
 * @param spTenantDomain            Tenant domain.
 * @return                          Requested OIDC claim list.
 * @throws RequestObjectException   If an error occurred while getting essential claims for the session data key.
 * @throws ClaimMetadataException   If an error occurred while getting claim mappings.
 */
private List<ClaimMetaData> getRequestedOidcClaimsList(ConsentClaimsData claimsForApproval, OAuth2Parameters oauth2Params, String spTenantDomain) throws RequestObjectException, ClaimMetadataException {
    List<ClaimMetaData> requestedOidcClaimsList = new ArrayList<>();
    List<String> localClaimsOfOidcClaims = new ArrayList<>();
    List<String> localClaimsOfEssentialClaims = new ArrayList<>();
    // Get the claims uri list of all the requested scopes. Eg:- country, email.
    List<String> claimListOfScopes = openIDConnectClaimFilter.getClaimsFilteredByOIDCScopes(oauth2Params.getScopes(), spTenantDomain);
    List<String> essentialRequestedClaims = new ArrayList<>();
    if (oauth2Params.isRequestObjectFlow()) {
        // Get the requested claims came through request object.
        List<RequestedClaim> requestedClaimsOfIdToken = EndpointUtil.getRequestObjectService().getRequestedClaimsForSessionDataKey(oauth2Params.getSessionDataKey(), false);
        List<RequestedClaim> requestedClaimsOfUserInfo = EndpointUtil.getRequestObjectService().getRequestedClaimsForSessionDataKey(oauth2Params.getSessionDataKey(), true);
        // Get the list of id token's essential claims.
        for (RequestedClaim requestedClaim : requestedClaimsOfIdToken) {
            if (requestedClaim.isEssential()) {
                essentialRequestedClaims.add(requestedClaim.getName());
            }
        }
        // Get the list of user info's essential claims.
        for (RequestedClaim requestedClaim : requestedClaimsOfUserInfo) {
            if (requestedClaim.isEssential()) {
                essentialRequestedClaims.add(requestedClaim.getName());
            }
        }
    }
    if (CollectionUtils.isNotEmpty(claimListOfScopes)) {
        // Get the external claims relevant to all oidc scope claims and essential claims.
        Set<ExternalClaim> externalClaimSetOfOidcClaims = ClaimMetadataHandler.getInstance().getMappingsFromOtherDialectToCarbon(OIDC_DIALECT, new HashSet<String>(claimListOfScopes), spTenantDomain);
        /* Get the locally mapped claims for all the external claims of requested scope and essential claims.
            Eg:- http://wso2.org/claims/country, http://wso2.org/claims/emailaddress
             */
        for (ExternalClaim externalClaim : externalClaimSetOfOidcClaims) {
            localClaimsOfOidcClaims.add(externalClaim.getMappedLocalClaim());
        }
    }
    if (CollectionUtils.isNotEmpty(essentialRequestedClaims)) {
        // Get the external claims relevant to all essential requested claims.
        Set<ExternalClaim> externalClaimSetOfEssentialClaims = ClaimMetadataHandler.getInstance().getMappingsFromOtherDialectToCarbon(OIDC_DIALECT, new HashSet<String>(essentialRequestedClaims), spTenantDomain);
        /* Get the locally mapped claims for all the external claims of essential claims.
            Eg:- http://wso2.org/claims/country, http://wso2.org/claims/emailaddress
             */
        for (ExternalClaim externalClaim : externalClaimSetOfEssentialClaims) {
            localClaimsOfEssentialClaims.add(externalClaim.getMappedLocalClaim());
        }
    }
    /* Check whether the local claim of oidc claims contains the requested claims or essential claims of
         request object contains the requested claims, If it contains add it as requested claim.
         */
    for (ClaimMetaData claimMetaData : claimsForApproval.getRequestedClaims()) {
        if (localClaimsOfOidcClaims.contains(claimMetaData.getClaimUri()) || localClaimsOfEssentialClaims.contains(claimMetaData.getClaimUri())) {
            requestedOidcClaimsList.add(claimMetaData);
        }
    }
    return requestedOidcClaimsList;
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) ExternalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim) ArrayList(java.util.ArrayList) ClaimMetaData(org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.consent.ClaimMetaData)

Example 23 with RequestedClaim

use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method getAcrValues.

/**
 * To get the value(s) for "acr" from request object.
 *
 * @param requestObject {@link RequestObject}
 * @return list of acr value(s)
 */
private List<String> getAcrValues(RequestObject requestObject) {
    List<String> acrRequestedValues = null;
    if (requestObject != null) {
        Map<String, List<RequestedClaim>> requestedClaims = requestObject.getRequestedClaims();
        List<RequestedClaim> requestedClaimsForIdToken = requestedClaims.get(OIDCConstants.ID_TOKEN);
        if (CollectionUtils.isNotEmpty(requestedClaimsForIdToken)) {
            for (RequestedClaim requestedClaim : requestedClaimsForIdToken) {
                if (OAuthConstants.ACR.equalsIgnoreCase(requestedClaim.getName()) && requestedClaim.isEssential()) {
                    acrRequestedValues = requestedClaim.getValues();
                    if (CollectionUtils.isEmpty(acrRequestedValues) && StringUtils.isNotEmpty(requestedClaim.getValue())) {
                        acrRequestedValues = Collections.singletonList(requestedClaim.getValue());
                    }
                    break;
                }
            }
        }
    }
    return acrRequestedValues;
}
Also used : RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with RequestedClaim

use of org.wso2.carbon.identity.openidconnect.model.RequestedClaim 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;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) SQLException(java.sql.SQLException) RequestedClaim(org.wso2.carbon.identity.openidconnect.model.RequestedClaim) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

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