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.jwt;
019
020
021import java.io.Serializable;
022import java.text.ParseException;
023
024import com.nimbusds.jose.Header;
025import com.nimbusds.jose.util.Base64URL;
026
027
028/**
029 * JSON Web Token (JWT) interface.
030 *
031 * @author Vladimir Dzhuvinov
032 * @version 2014-08-19
033 */
034public interface JWT extends Serializable {
035
036
037        /**
038         * Gets the JOSE header of the JSON Web Token (JWT).
039         *
040         * @return The header.
041         */
042        Header getHeader();
043
044
045        /**
046         * Gets the claims set of the JSON Web Token (JWT).
047         *
048         * @return The claims set, {@code null} if not available (for an 
049         *         encrypted JWT that isn't decrypted).
050         *
051         * @throws ParseException If the payload of the JWT doesn't represent a
052         *                        valid JSON object and a JWT claims set.
053         */
054        JWTClaimsSet getJWTClaimsSet()
055                throws ParseException;
056
057
058        /**
059         * Gets the original parsed Base64URL parts used to create the JSON Web
060         * Token (JWT).
061         *
062         * @return The original Base64URL parts used to creates the JWT,
063         *         {@code null} if the JWT was created from scratch. The 
064         *         individual parts may be empty or {@code null} to indicate a 
065         *         missing part.
066         */
067        Base64URL[] getParsedParts();
068
069
070        /**
071         * Gets the original parsed string used to create the JSON Web Token 
072         * (JWT).
073         *
074         * @see #getParsedParts
075         * 
076         * @return The parsed string used to create the JWT, {@code null} if 
077         *         the JWT was created from scratch.
078         */
079        String getParsedString();
080
081
082        /**
083         * Serialises the JSON Web Token (JWT) to its compact format consisting 
084         * of Base64URL-encoded parts delimited by period ('.') characters.
085         *
086         * @return The serialised JWT.
087         *
088         * @throws IllegalStateException If the JWT is not in a state that 
089         *                               permits serialisation.
090         */
091        String serialize();
092}