001/*
002 * Copyright 2011-2013 UnboundID Corp.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim.sdk;
019
020import com.unboundid.scim.schema.ResourceDescriptor;
021
022import javax.servlet.http.HttpServletRequest;
023import java.net.URI;
024
025
026
027/**
028 * This class is the base class for all SCIM requests.
029 */
030public abstract class SCIMRequest
031{
032  /**
033   * The base URL for the SCIM service.
034   */
035  private final URI baseURL;
036
037  /**
038   * The authenticated user ID or {@code null} if the request is not
039   * authenticated.
040   */
041  private final String authenticatedUserID;
042
043  /**
044   * The ResourceDescriptor associated with this request.
045   */
046  private final ResourceDescriptor resourceDescriptor;
047
048  /**
049   * The HttpServletRequest that initiated this SCIM request.
050   */
051  private final HttpServletRequest httpServletRequest;
052
053
054  /**
055   * Create a new SCIM request from the provided information.
056   *
057   * @param baseURL              The base URL for the SCIM service.
058   * @param authenticatedUserID  The authenticated user name or {@code null} if
059   *                             the request is not authenticated.
060   * @param resourceDescriptor   The ResourceDescriptor associated with this
061   *                             request.
062   */
063  public SCIMRequest(final URI baseURL, final String authenticatedUserID,
064                     final ResourceDescriptor resourceDescriptor)
065  {
066    this.baseURL             = baseURL;
067    this.authenticatedUserID = authenticatedUserID;
068    this.resourceDescriptor = resourceDescriptor;
069    this.httpServletRequest = null;
070  }
071
072
073
074  /**
075   * Create a new SCIM request from the provided information.
076   *
077   * @param baseURL              The base URL for the SCIM service.
078   * @param authenticatedUserID  The authenticated user name or {@code null} if
079   *                             the request is not authenticated.
080   * @param resourceDescriptor   The ResourceDescriptor associated with this
081   *                             request.
082   * @param httpServletRequest   The HTTP servlet request associated with this
083   *                             request or {@code null} if this request is not
084   *                             initiated by a servlet.
085   */
086  public SCIMRequest(final URI baseURL, final String authenticatedUserID,
087                     final ResourceDescriptor resourceDescriptor,
088                     final HttpServletRequest httpServletRequest)
089  {
090    this.baseURL             = baseURL;
091    this.authenticatedUserID = authenticatedUserID;
092    this.resourceDescriptor = resourceDescriptor;
093    this.httpServletRequest = httpServletRequest;
094  }
095
096
097
098  /**
099   * Retrieve the base URL for the SCIM service.
100   *
101   * @return The base URL for the SCIM service.
102   */
103  public URI getBaseURL()
104  {
105    return baseURL;
106  }
107
108
109
110  /**
111   * Get the authenticated user ID.
112   *
113   * @return  The authenticated user ID or {@code null} if the request is
114   *          not authenticated.
115   */
116  public String getAuthenticatedUserID()
117  {
118    return authenticatedUserID;
119  }
120
121
122
123  /**
124   * Get ResourceDescriptor associated with this request.
125   *
126   * @return The ResourceDescriptor associated with this request.
127   */
128  public ResourceDescriptor getResourceDescriptor() {
129    return resourceDescriptor;
130  }
131
132
133
134  /**
135   * Get the HTTP servlet request associated with this request.
136   *
137   * @return The HTTP servlet request associated with this request or
138   *         {@code null} if this request is not initiated by a servlet.
139   */
140  public HttpServletRequest getHttpServletRequest() {
141    return httpServletRequest;
142  }
143}