001package com.nimbusds.jose.jwk.source;
002
003
004import java.util.List;
005
006import com.nimbusds.jose.jwk.JWK;
007import com.nimbusds.jose.jwk.JWKSelector;
008import com.nimbusds.jose.jwk.JWKSet;
009import com.nimbusds.jose.proc.SecurityContext;
010import net.jcip.annotations.Immutable;
011
012
013/**
014 * JSON Web Key (JWK) source backed by an immutable JWK set.
015 *
016 * @author Vladimir Dzhuvinov
017 * @version 2016-04-10
018 */
019@Immutable
020public class ImmutableJWKSet<C extends SecurityContext> implements JWKSource<C> {
021
022
023        /**
024         * The JWK set.
025         */
026        private final JWKSet jwkSet;
027
028
029        /**
030         * Creates a new JWK source backed by an immutable JWK set.
031         *
032         * @param jwkSet The JWK set. Must not be {@code null}.
033         */
034        public ImmutableJWKSet(final JWKSet jwkSet) {
035                if (jwkSet == null) {
036                        throw new IllegalArgumentException("The JWK set must not be null");
037                }
038                this.jwkSet = jwkSet;
039        }
040
041
042        /**
043         * Returns the JWK set.
044         *
045         * @return The JWK set.
046         */
047        public JWKSet getJWKSet() {
048                return jwkSet;
049        }
050
051
052        /**
053         * {@inheritDoc} The security context is ignored.
054         */
055        @Override
056        public List<JWK> get(final JWKSelector jwkSelector, final C context) {
057
058                return jwkSelector.select(jwkSet);
059        }
060}