001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2020, Connect2id Ltd and contributors.
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.openid.connect.sdk.federation.trust.constraints;
019
020
021import java.util.Objects;
022
023import net.jcip.annotations.Immutable;
024
025import com.nimbusds.openid.connect.sdk.federation.entities.EntityID;
026
027
028/**
029 * Exact match entity ID constraint.
030 *
031 * <p>Related specifications:
032 *
033 * <ul>
034 *     <li>OpenID Connect Federation 1.0, section 7.3.
035 *     <li>RFC 5280, section 4.2.1.10.
036 * </ul>
037 */
038@Immutable
039public final class ExactMatchEntityIDConstraint extends EntityIDConstraint {
040        
041        
042        /**
043         * The exact entity ID to match.
044         */
045        private final EntityID entityID;
046        
047        
048        /**
049         * Creates a new exact match entity ID constraint.
050         *
051         * @param entityID The exact entity ID to match. Must not be
052         *                 {@code null}.
053         */
054        public ExactMatchEntityIDConstraint(final EntityID entityID) {
055                if (entityID == null) {
056                        throw new IllegalArgumentException("The entity ID must not be null");
057                }
058                this.entityID = entityID;
059        }
060        
061        
062        @Override
063        public boolean matches(final EntityID entityID) {
064                return this.entityID.equals(entityID);
065        }
066        
067        
068        @Override
069        public String toString() {
070                return entityID.getValue();
071        }
072        
073        
074        @Override
075        public boolean equals(Object o) {
076                if (this == o) return true;
077                if (!(o instanceof ExactMatchEntityIDConstraint)) return false;
078                ExactMatchEntityIDConstraint that = (ExactMatchEntityIDConstraint) o;
079                return entityID.equals(that.entityID);
080        }
081        
082        
083        @Override
084        public int hashCode() {
085                return Objects.hash(entityID);
086        }
087}