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);
}
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;
}
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;
}
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;
}
Aggregations