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