001package com.nimbusds.openid.connect.sdk.claims;
002
003
004import net.jcip.annotations.Immutable;
005
006import com.nimbusds.jose.JWSAlgorithm;
007
008import com.nimbusds.oauth2.sdk.token.AccessToken;
009
010
011/**
012 * Access token hash ({@code at_hash}). This class is immutable.
013 *
014 * <p>Related specifications:
015 *
016 * <ul>
017 *     <li>OpenID Connect Messages 1.0, section 2.1.1.
018 * </ul>
019 *
020 * @author Vladimir Dzhuvinov
021 */
022@Immutable
023public final class AccessTokenHash extends HashClaim {
024
025
026        /**
027         * Creates a new access token hash with the specified value.
028         *
029         * @param value The access token hash value. Must not be {@code null}.
030         */
031        public AccessTokenHash(final String value) {
032        
033                super(value);
034        }
035
036
037        /**
038         * Computes the hash for the specified access token and reference JSON
039         * Web Signature (JWS) algorithm.
040         *
041         * @param accessToken The access token. Must not be {@code null}.
042         * @param alg         The reference JWS algorithm. Must not be
043         *                    {@code null}.
044         *
045         * @return The access token hash, or {@code null} if the JWS algorithm
046         *         is not supported.
047         */
048        public static AccessTokenHash compute(final AccessToken accessToken, final JWSAlgorithm alg) {
049
050                String value = computeValue(accessToken, alg);
051
052                if (value == null)
053                        return null;
054
055                return new AccessTokenHash(value);
056        }
057
058
059        @Override
060        public boolean equals(final Object object) {
061        
062                return object instanceof AccessTokenHash &&
063                       this.toString().equals(object.toString());
064        }
065}