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 2013-2015 ForgeRock AS.
015 */
016
017package org.forgerock.json.jose.jwt;
018
019/**
020 * The interface for all types of JSON Web Tokens (JWTs).
021 * <p>
022 * JSON Web Token (JWT) is a means of representing claims to be transferred between two parties.  The claims in a JWT
023 * are encoded as a JSON object that is digitally signed or MACed using JSON Web Signature (JWS) and/or encrypted using
024 * JSON Web Encryption (JWE).
025 * <p>
026 * @see <a href="http://tools.ietf.org/html/draft-jones-json-web-token-10">JSON Web Token Specification</a>
027 *
028 * @since 2.0.0
029 */
030public interface Jwt {
031
032    /**
033     * Gets the header object for the JWT, which contains properties which describe the cryptographic operations
034     * applied to the JWT, among other properties.
035     * <p>
036     * When the JWT is digitally signed or MACed, the JWT Header is a JWS Header.  When the JWT is encrypted, the JWT
037     * Header is a JWE Header.
038     *
039     * @return The JWTs Header.
040     */
041    JwtHeader getHeader();
042
043    /**
044     * Gets the claims set object for the Jwt, which contains all of the claims (name value pairs) conveyed by the JWT.
045     *
046     * @return The JWTs Claims Set.
047     */
048    JwtClaimsSet getClaimsSet();
049
050    /**
051     * Builds the JWT into a <code>String</code> by following the steps specified in the relevant specification
052     * according to whether the JWT is being signed and/or encrypted.
053     * <p>
054     * @see <a href="http://tools.ietf.org/html/draft-jones-json-web-token-10#section-7">
055     *     JSON Web Token Specification</a>
056     * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-5">
057     *     JSON Web Signature Specification</a>
058     * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-11#section-5">
059     *     JSON Web Encryption Specification</a>
060     *
061     * @return The base64url encoded UTF-8 parts of the JWT.
062     */
063    String build();
064}