001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd. 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.jose.jwk.source; 019 020 021import com.nimbusds.jose.jwk.JWK; 022import com.nimbusds.jose.jwk.JWKSelector; 023import com.nimbusds.jose.jwk.JWKSet; 024import com.nimbusds.jose.proc.SecurityContext; 025import net.jcip.annotations.Immutable; 026 027import java.util.List; 028import java.util.Objects; 029 030 031/** 032 * JSON Web Key (JWK) source backed by an immutable JWK set. 033 * 034 * @author Vladimir Dzhuvinov 035 * @author Thomas Rørvik Skjølberg 036 * @version 2024-04-20 037 */ 038@Immutable 039public class ImmutableJWKSet<C extends SecurityContext> implements JWKSource<C> { 040 041 042 /** 043 * The JWK set. 044 */ 045 private final JWKSet jwkSet; 046 047 048 /** 049 * Creates a new JWK source backed by an immutable JWK set. 050 * 051 * @param jwkSet The JWK set. Must not be {@code null}. 052 */ 053 public ImmutableJWKSet(final JWKSet jwkSet) { 054 this.jwkSet = Objects.requireNonNull(jwkSet); 055 } 056 057 058 /** 059 * Returns the JWK set. 060 * 061 * @return The JWK set. 062 */ 063 public JWKSet getJWKSet() { 064 return jwkSet; 065 } 066 067 068 /** 069 * {@inheritDoc} The security context is ignored. 070 */ 071 @Override 072 public List<JWK> get(final JWKSelector jwkSelector, final C context) { 073 074 return jwkSelector.select(jwkSet); 075 } 076}