001package com.nimbusds.oauth2.sdk.jose.jwk;
002
003
004import java.util.Collections;
005import java.util.List;
006
007import com.nimbusds.jose.jwk.JWK;
008import com.nimbusds.jose.jwk.JWKSelector;
009import com.nimbusds.jose.jwk.JWKSet;
010import com.nimbusds.oauth2.sdk.id.Identifier;
011import net.jcip.annotations.Immutable;
012
013
014/**
015 * Immutable JSON Web Key (JWK) set. Intended for a JWK set specified by value.
016 */
017@Immutable
018public class ImmutableJWKSet extends AbstractJWKSource {
019
020
021        /**
022         * The JWK set.
023         */
024        private final JWKSet jwkSet;
025
026
027        /**
028         * Creates a new immutable JWK set.
029         *
030         * @param id     The JWK set owner identifier. Typically the OAuth 2.0
031         *               server issuer ID, or client ID. Must not be
032         *               {@code null}.
033         * @param jwkSet The JWK set. Must not be {@code null}.
034         */
035        public ImmutableJWKSet(final Identifier id, final JWKSet jwkSet) {
036                super(id);
037                if (jwkSet == null) {
038                        throw new IllegalArgumentException("The JWK set must not be null");
039                }
040                this.jwkSet = jwkSet;
041        }
042
043
044        /**
045         * Returns the JWK set.
046         *
047         * @return The JWK set.
048         */
049        public JWKSet getJWKSet() {
050                return jwkSet;
051        }
052
053
054        @Override
055        public List<JWK> get(final Identifier id, final JWKSelector jwkSelector) {
056                if (! getOwner().equals(id)) {
057                        return Collections.emptyList();
058                }
059                return jwkSelector.select(jwkSet);
060        }
061}