Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.appbasics.security.login;
 
 
 
Represents the information of a single logged in user.

Author(s):
Philip Helger
 
 public final class LoginInfo extends MapBasedAttributeContainer implements IHasID <String>
 {
   private final IUser m_aUser;
   private final ISessionScope m_aSessionScope;
   private final DateTime m_aLoginDT;
   private DateTime m_aLastAccessDT;
   private DateTime m_aLogoutDT;
 
   LoginInfo (@Nonnull final IUser aUser, @Nonnull final ISessionScope aSessionScope)
   {
      = ValueEnforcer.notNull (aUser"User");
      = ValueEnforcer.notNull (aSessionScope"SessionScope");
      = PDTFactory.getCurrentDateTime ();
   }

  

Returns:
The user to which this login info belongs. Never null.
 
   @Nonnull
   public IUser getUser ()
   {
     return ;
   }

  

Returns:
The session scope to which this login info belongs. Never null.
 
   @Nonnull
   public ISessionScope getSessionScope ()
   {
     return ;
   }

  

Returns:
The ID of the user to which this login info belongs. Neither null nor empty.
 
   @Nonnull
   @Nonempty
   public String getUserID ()
   {
     return .getID ();
   }
 
   @Nonnull
   @Nonempty
   public String getID ()
   {
     return getUserID ();
   }

  

Returns:
The login data and time. Never null.
 
   @Nonnull
   public DateTime getLoginDT ()
  {
    return ;
  }

  

Returns:
The last access data and time. Never null.
  public DateTime getLastAccessDT ()
  {
    return ;
  }

  
Update the last access date time to the current date and time.
  public void setLastAccessDTNow ()
  {
     = PDTFactory.getCurrentDateTime ();
  }

  

Returns:
The date and time when the user logged out. Is null when the user is still logged in :)
  public DateTime getLogoutDT ()
  {
    return ;
  }

  
Update the logout date time to the current date and time.
  void setLogoutDTNow ()
  {
     = PDTFactory.getCurrentDateTime ();
  }

  

Returns:
true if this LoginInfo refers to an already logged out user.
  public boolean isLogout ()
  {
    return  != null;
  }
  public boolean equals (final Object o)
  {
    if (o == this)
      return true;
    if (!super.equals (o))
      return false;
    final LoginInfo rhs = (LoginInfoo;
    return .equals (rhs.m_aUser) &&
           .getID ().equals (rhs.m_aSessionScope.getID ()) &&
           .equals (rhs.m_aLoginDT) &&
           .equals (rhs.m_aLastAccessDT) &&
           EqualsUtils.equals (rhs.m_aLogoutDT);
  }
  public int hashCode ()
  {
    return HashCodeGenerator.getDerived (super.hashCode ())
                            .append ()
                            .append (.getID ())
                            .append ()
                            .append ()
                            .append ()
                            .getHashCode ();
  }
  public String toString ()
  {
    return ToStringGenerator.getDerived (super.toString ())
                            .append ("user")
                            .append ("sessionScopeID".getID ())
                            .append ("loginDT")
                            .append ("lastAccessDT")
                            .appendIfNotNull ("logoutDT")
                            .toString ();
  }
New to GrepCode? Check out our FAQ X