Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2022 Authlete, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package com.authlete.jakarta;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import com.authlete.common.dto.StringArray;
import com.authlete.common.util.Utils;
/**
* Utility to collect verified claims by using an SPI implementation.
*
*
* This class implements the complex logic of how to call the method
* provided by the SPI implementation so that the SPI implementation can
* focus on building a new dataset that satisfies conditions of a
* {@code "verified_claims"} request without needing to know how to
* interact with Authlete APIs.
*
*
* @since 2.43
*/
class VerifiedClaimsCollector
{
// Keys that appear in JSON
private static final String KEY_VERIFIED_CLAIMS = "verified_claims";
private static final String KEY_CLAIMS = "claims";
private final BiFunction mVerifiedClaimsGetter;
public VerifiedClaimsCollector(BiFunction getter)
{
mVerifiedClaimsGetter = getter;
}
public Map collect(
Map claims, String subject, String claimsRequest)
{
Object verifiedClaimsRequest = extractVerifiedClaimsRequest(claimsRequest);
if (verifiedClaimsRequest == null)
{
// No need to collect verified claims because the authorization
// request does not contain "verified_claims".
//
// The set of claims that will appear in the ID token or the
// userinfo response is not changed here.
return claims;
}
// Use the getter to collect values of verified claims.
Object verifiedClaimsValue =
mVerifiedClaimsGetter.apply(subject, verifiedClaimsRequest);
// If the getter did not build a value of "verified_claims".
if (verifiedClaimsValue == null)
{
// "verified_claims" won't be included in the ID token or the
// userinfo response.
return claims;
}
// If the API caller did not pass the "claims" request parameter
// to the Authlete API (/api/auth/authorization/issue API or
// /api/auth/userinfo/issue API).
if (claims == null)
{
// Create a holder that contains "verified_claims".
claims = new HashMap<>();
}
// Embed "verified_claims" in the ID token or the userinfo response.
claims.put(KEY_VERIFIED_CLAIMS, verifiedClaimsValue);
return claims;
}
private Object extractVerifiedClaimsRequest(String claimsRequest)
{
// 'claimsRequest' here represents the content of "id_token"
// or "userinfo" in the "claims" request parameter of an
// authorization request.
if (claimsRequest == null || claimsRequest.length() == 0)
{
// "verified_claims" appears under "id_token" or "userinfo".
// If the container is missing, "verified_claims" cannot be
// present.
return null;
}
// Extract the value of "verified_claims". The value is one of
// (1) a Map instance, (2) a List instance, or (3) null.
return Utils.fromJson(claimsRequest, Map.class).get(KEY_VERIFIED_CLAIMS);
}
public List