001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.oauth2.sdk.auth.verifier;
019
020
021import java.security.PublicKey;
022import java.util.List;
023
024import com.nimbusds.jose.JWSHeader;
025import com.nimbusds.oauth2.sdk.auth.ClientAuthenticationMethod;
026import com.nimbusds.oauth2.sdk.auth.Secret;
027import com.nimbusds.oauth2.sdk.id.ClientID;
028
029
030/**
031 * Selector of client credential candidates for client authentication
032 * verification. The select methods should typically return a single candidate,
033 * but may also return multiple in case of client credentials key rotation.
034 * Implementations should be tread-safe.
035 *
036 * <p>Selection of {@link com.nimbusds.oauth2.sdk.auth.ClientSecretBasic
037 * client_secret_basic}, {@link com.nimbusds.oauth2.sdk.auth.ClientSecretPost
038 * client_secret_post} and {@link com.nimbusds.oauth2.sdk.auth.ClientSecretJWT
039 * client_secret_jwt} secrets is handled by the {@link #selectClientSecrets}
040 * method.
041 *
042 * <p>Selection of {@link com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT
043 * private_key_jwt} keys is handled by the {@link #selectPublicKeys} method.
044 *
045 * <p>The generic {@link Context context object} may be used to return
046 * {@link com.nimbusds.oauth2.sdk.client.ClientMetadata client metadata} or
047 * other information to the caller.
048 */
049public interface ClientCredentialsSelector<T> {
050
051
052        /**
053         * Selects one or more client secret candidates for
054         * {@link com.nimbusds.oauth2.sdk.auth.ClientSecretBasic client_secret_basic},
055         * {@link com.nimbusds.oauth2.sdk.auth.ClientSecretPost client_secret_post} and
056         * {@link com.nimbusds.oauth2.sdk.auth.ClientSecretJWT client_secret_jwt}
057         * authentication.
058         *
059         * @param claimedClientID The client identifier (to be verified). Not
060         *                        {@code null}.
061         * @param authMethod      The client authentication method. Not
062         *                        {@code null}.
063         * @param context         Additional context. May be {@code null}.
064         *
065         * @return The selected client secret candidates, empty list if none.
066         *
067         * @throws InvalidClientException If the client is invalid.
068         */
069        List<Secret> selectClientSecrets(final ClientID claimedClientID,
070                                         final ClientAuthenticationMethod authMethod,
071                                         final Context<T> context)
072                throws InvalidClientException;
073
074
075        /**
076         * Selects one or more public key candidates (e.g. RSA or EC) for
077         * {@link com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT private_key_jwt}
078         * authentication.
079         *
080         * @param claimedClientID The client identifier (to be verified). Not
081         *                        {@code null}.
082         * @param authMethod      The client authentication method. Not
083         *                        {@code null}.
084         * @param jwsHeader       The JWS header, which may contain parameters
085         *                        such as key ID to facilitate the key
086         *                        selection. Not {@code null}.
087         * @param forceRefresh    {@code true} to force refresh of the JWK set
088         *                        (for a remote JWK set referenced by URL).
089         * @param context         Additional context. May be {@code null}.
090         *
091         * @return The selected public key candidates, empty list if none.
092         *
093         * @throws InvalidClientException If the client is invalid.
094         */
095        List<? extends PublicKey> selectPublicKeys(final ClientID claimedClientID,
096                                                   final ClientAuthenticationMethod authMethod,
097                                                   final JWSHeader jwsHeader,
098                                                   final boolean forceRefresh,
099                                                   final Context<T> context)
100                throws InvalidClientException;
101}