001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
003 * 
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package core.tut.pori.http.parameters;
017
018import javax.servlet.http.HttpSession;
019
020import core.tut.pori.users.UserIdentity;
021
022/**
023 * 
024 * Special HTTP Parameter which (if used) contains details of the authenticated user
025 * 
026 * Note: when using this class as a method parameter, the use of \@HTTPAuthenticationParameter annotation is required
027 *
028 * Note: there can be only one AuthenticationParameter per method
029 * 
030 * The AuthenticationParameter object will always be present (not null) for the method in which is it declared, but
031 * getUserIdentity() can return null if authentication was NOT required and the user did NOT provide credentials
032 */
033public class AuthenticationParameter{
034  private UserIdentity _userId = null;
035  private HttpSession _session = null;
036
037  /**
038   * 
039   * @return true if the parameter has values
040   */
041  public boolean hasValues() {
042    return (_userId != null);
043  }
044
045  /**
046   * @return the userId or null if not authenticated
047   */
048  public UserIdentity getUserIdentity() {
049    return _userId;
050  }
051
052  /**
053   * @param userId the userId to set
054   */
055  public void setUserIdentity(UserIdentity userId) {
056    _userId = userId;
057  }
058
059  /**
060   * @return the session information or null if none available
061   */
062  public HttpSession getSession() {
063    return _session;
064  }
065
066  /**
067   * @param session the session to set
068   */
069  public void setSession(HttpSession session) {
070    _session = session;
071  }
072}