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 java.util.List;
022
023import net.jcip.annotations.Immutable;
024
025import com.nimbusds.jose.jwk.JWK;
026import com.nimbusds.jose.jwk.JWKSelector;
027import com.nimbusds.jose.jwk.JWKSet;
028import com.nimbusds.jose.proc.SecurityContext;
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 2022-08-24
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                if (jwkSet == null) {
055                        throw new IllegalArgumentException("The JWK set must not be null");
056                }
057                this.jwkSet = jwkSet;
058        }
059
060
061        /**
062         * Returns the JWK set.
063         *
064         * @return The JWK set.
065         */
066        public JWKSet getJWKSet() {
067                return jwkSet;
068        }
069
070
071        /**
072         * {@inheritDoc} The security context is ignored.
073         */
074        @Override
075        public List<JWK> get(final JWKSelector jwkSelector, final C context) {
076
077                return jwkSelector.select(jwkSet);
078        }
079}