001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, 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.oauth2.sdk;
019
020
021/**
022 * Assertion grant. Used in access token requests with an assertion, such as a
023 * SAML 2.0 assertion or JSON Web Token (JWT).
024 *
025 * <p>Related specifications:
026 *
027 * <ul>
028 *     <li>Assertion Framework for OAuth 2.0 Client Authentication and
029 *         Authorization Grants (RFC 7521), section 4.1.
030 * </ul>
031 */
032public abstract class AssertionGrant extends AuthorizationGrant {
033        
034        
035        private static final String MISSING_GRANT_TYPE_PARAM_MESSAGE = "Missing \"grant_type\" parameter";
036        
037        
038        private static final String MISSING_ASSERTION_PARAM_MESSAGE = "Missing or empty \"assertion\" parameter";
039
040        
041        /**
042         * Cached missing {@code grant_type} parameter exception.
043         */
044        protected static final ParseException MISSING_GRANT_TYPE_PARAM_EXCEPTION
045                = new ParseException(MISSING_GRANT_TYPE_PARAM_MESSAGE,
046                        OAuth2Error.INVALID_REQUEST.appendDescription(": " + MISSING_GRANT_TYPE_PARAM_MESSAGE));
047
048
049        /**
050         * Caches missing {@code assertion} parameter exception.
051         */
052        protected static final ParseException MISSING_ASSERTION_PARAM_EXCEPTION
053                = new ParseException(MISSING_ASSERTION_PARAM_MESSAGE,
054                        OAuth2Error.INVALID_REQUEST.appendDescription(": " + MISSING_ASSERTION_PARAM_MESSAGE));
055
056
057        /**
058         * Creates a new assertion-based authorisation grant.
059         *
060         * @param type The authorisation grant type. Must not be {@code null}.
061         */
062        protected AssertionGrant(final GrantType type) {
063
064                super(type);
065        }
066
067
068        /**
069         * Gets the assertion.
070         *
071         * @return The assertion as a string.
072         */
073        public abstract String getAssertion();
074}