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
021import java.net.URI;
022
023import com.nimbusds.oauth2.sdk.auth.ClientAuthentication;
024import com.nimbusds.oauth2.sdk.id.ClientID;
025
026
027/**
028 * Abstract request with optional client authentication or client
029 * identification.
030 *
031 * <p>Client authentication methods:
032 *
033 * <ul>
034 *     <li>{@link com.nimbusds.oauth2.sdk.auth.ClientSecretBasic client_secret_basic}
035 *     <li>{@link com.nimbusds.oauth2.sdk.auth.ClientSecretPost client_secret_post}
036 *     <li>{@link com.nimbusds.oauth2.sdk.auth.ClientSecretJWT client_secret_jwt}
037 *     <li>{@link com.nimbusds.oauth2.sdk.auth.PrivateKeyJWT private_key_jwt}
038 * </ul>
039 *
040 * <p>Client identification methods:
041 *
042 * <ul>
043 *     <li>Top level {@code client_id} parameter.
044 * </ul>
045 */
046public abstract class AbstractOptionallyIdentifiedRequest extends AbstractOptionallyAuthenticatedRequest {
047
048
049        /**
050         * The client identifier, {@code null} if not specified.
051         */
052        private final ClientID clientID;
053        
054
055
056        /**
057         * Creates a new abstract request with optional client authentication.
058         *
059         * @param uri        The URI of the endpoint (HTTP or HTTPS) for which
060         *                   the request is intended, {@code null} if not
061         *                   specified (if, for example, the
062         *                   {@link #toHTTPRequest()} method will not be used).
063         * @param clientAuth The client authentication, {@code null} if none.
064         */
065        public AbstractOptionallyIdentifiedRequest(final URI uri,
066                                                   final ClientAuthentication clientAuth) {
067
068                super(uri, clientAuth);
069                clientID = null;
070        }
071
072
073        /**
074         * Creates a new abstract request with optional client identification.
075         *
076         * @param uri      The URI of the endpoint (HTTP or HTTPS) for which
077         *                 the request is intended, {@code null} if not
078         *                 specified (if, for example, the
079         *                 {@link #toHTTPRequest()} method will not be used).
080         * @param clientID The client identifier, {@code null} if not
081         *                 specified.
082         */
083        public AbstractOptionallyIdentifiedRequest(final URI uri,
084                                                   final ClientID clientID) {
085
086                super(uri, null);
087                this.clientID = clientID;
088        }
089
090
091        /**
092         * Gets the client identifier (for a request from a public client or a
093         * request without explicit client authentication).
094         *
095         * @see #getClientAuthentication()
096         *
097         * @return The client identifier, {@code null} if not specified.
098         */
099        public ClientID getClientID() {
100
101                return clientID;
102        }
103}