001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2014-2015 ForgeRock AS.
015 */
016
017package org.forgerock.openig.filter.oauth2;
018
019import java.util.Map;
020import java.util.Set;
021
022import org.forgerock.json.JsonValue;
023
024/**
025 * Represents an <a href="http://tools.ietf.org/html/rfc6749#section-1.4">OAuth2 Access Token</a>.
026 */
027public interface AccessToken {
028
029    /**
030     * Marker for never ending tokens.
031     */
032    long NEVER_EXPIRES = Long.MAX_VALUE;
033
034    /**
035     * Returns the access token identifier issued from the authorization server.
036     *
037     * @return the access token identifier issued from the authorization server.
038     */
039    String getToken();
040
041    /**
042     * Returns the scopes associated to this token. Will return an empty Set if no scopes are associated with this
043     * token.
044     *
045     * @return the scopes associated to this token.
046     */
047    Set<String> getScopes();
048
049    /**
050     * Returns the time (expressed as a timestamp in milliseconds since epoch) when this token will be expired. If the
051     * {@link #NEVER_EXPIRES} constant is returned, this token is always considered as available.
052     *
053     * @return the time (expressed as a timestamp, in milliseconds since epoch) when this token will be expired.
054     */
055    long getExpiresAt();
056
057    /**
058     * Returns the raw JSON as a map.
059     *
060     * @return the raw JSON as a map.
061     */
062    Map<String, Object> getInfo();
063
064    /**
065     * Returns the raw JSON as returned by the {@literal tokeninfo} endpoint.
066     *
067     * @return the raw JSON as returned by the {@literal tokeninfo} endpoint.
068     */
069    JsonValue asJsonValue();
070}