001/* 002 * nimbus-jose-jwt 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.jwt.proc; 019 020 021import java.security.Key; 022import java.util.List; 023 024import com.nimbusds.jose.JWSHeader; 025import com.nimbusds.jose.KeySourceException; 026import com.nimbusds.jose.proc.SecurityContext; 027import com.nimbusds.jwt.JWTClaimsSet; 028 029 030/** 031 * Interface for selecting key candidates for processing a signed JWT which 032 * provides access to the JWT claims set in addition to the JWS header. 033 * 034 * <p>The interface supports keys selection based on: 035 * 036 * <ul> 037 * <li>Recognised header parameter(s) referencing the key (e.g. 038 * {@code kid}, {@code x5t}). 039 * <li>JWT claim(s) (e.g. issuer ({@code iss}) to locate a JWK set). 040 * <li>Additional {@link SecurityContext}, if required and set by the 041 * application (e.g. endpoint where the JWT was received). 042 * </ul> 043 * 044 * <p>See the simpler {@link com.nimbusds.jose.proc.JWSKeySelector} if the 045 * application doesn't use JWT claim(s) to select the key candidates. 046 * 047 * <p>Possible key types: 048 * 049 * <ul> 050 * <li>{@link javax.crypto.SecretKey} for HMAC keys. 051 * <li>{@link java.security.interfaces.RSAPublicKey} public RSA keys. 052 * <li>{@link java.security.interfaces.ECPublicKey} public EC keys. 053 * </ul> 054 * 055 * @author Vladimir Dzhuvinov 056 * @version 2019-06-16 057 */ 058public interface JWTClaimsSetAwareJWSKeySelector<C extends SecurityContext> { 059 060 061 /** 062 * Selects key candidates for verifying a signed JWT. 063 * 064 * @param header The JWS header. Must not be {@code null}. 065 * @param claimsSet The JWT claims set (not verified). Must not be 066 * {@code null}. 067 * @param context Optional context of the JOSE object, {@code null} 068 * if not required. 069 * 070 * @return The key candidates in trial order, empty list if none. 071 * 072 * @throws KeySourceException If a key sourcing exception is 073 * encountered, e.g. on remote JWK 074 * retrieval. 075 */ 076 List<? extends Key> selectKeys(final JWSHeader header, final JWTClaimsSet claimsSet, final C context) 077 throws KeySourceException; 078} 079