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