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.user;
 
 import java.util.Map;
 
 
 
Default implementation of the IUser interface.

Author(s):
Philip Helger
 
 public class User extends MapBasedAttributeContainer implements IUser
 {
   private final String m_sID;
   private final DateTime m_aCreationDT;
   private DateTime m_aDeletionDT;
   private String m_sLoginName;
   private String m_sEmailAddress;
   private String m_sFirstName;
   private String m_sLastName;
   private Locale m_aDesiredLocale;
   private DateTime m_aLastLoginDT;
   private int m_nLoginCount;
   private boolean m_bDeleted;
   private boolean m_bDisabled;

  
Create a new user

Parameters:
sLoginName Login name of the user. May neither be null nor empty.
sEmailAddress Email address of the user. May be null.
aPasswordHash Password hash of the user. May not be null.
sFirstName The first name. May be null.
sLastName The last name. May be null.
aDesiredLocale The desired locale. May be null.
aCustomAttrs Custom attributes. May be null.
bDisabled true if the user is disabled
 
   public User (@Nonnull @Nonempty final String sLoginName,
                @Nullable final String sEmailAddress,
                @Nonnull final PasswordHash aPasswordHash,
                @Nullable final String sFirstName,
                @Nullable final String sLastName,
                @Nullable final Locale aDesiredLocale,
                @Nullable final Map <String, ?> aCustomAttrs,
                final boolean bDisabled)
   {
     this (GlobalIDFactory.getNewPersistentStringID (),
           PDTFactory.getCurrentDateTime (),
           (DateTimenull,
           (DateTimenull,
          sLoginName,
          sEmailAddress,
          aPasswordHash,
          sFirstName,
          sLastName,
          aDesiredLocale,
          (DateTimenull,
          0,
          0,
          aCustomAttrs,
          false,
          bDisabled);
  }
  // Internal use only
  User (@Nonnull @Nonempty final String sID,
        @Nonnull @Nonempty final String sLoginName,
        @Nullable final String sEmailAddress,
        @Nonnull final PasswordHash aPasswordHash,
        @Nullable final String sFirstName,
        @Nullable final String sLastName,
        @Nullable final Locale aDesiredLocale,
        @Nullable final Map <String, ?> aCustomAttrs,
        final boolean bDisabled)
  {
    this (sID,
          PDTFactory.getCurrentDateTime (),
          (DateTimenull,
          (DateTimenull,
          sLoginName,
          sEmailAddress,
          aPasswordHash,
          sFirstName,
          sLastName,
          aDesiredLocale,
          (DateTimenull,
          0,
          0,
          aCustomAttrs,
          false,
          bDisabled);
  }

  
For deserialization only.

Parameters:
sID user ID
aCreationDT The creation date and time
aLastModificationDT The last modification date and time
aDeletionDT The deletion date and time
sLoginName Login name of the user. May neither be null nor empty.
sEmailAddress Email address of the user. May be null.
aPasswordHash Password hash of the user. May not be null.
sFirstName The first name. May be null.
sLastName The last name. May be null.
aDesiredLocale The desired locale. May be null.
aLastLoginDT The date time when the user last logged in.
nLoginCount The number of times the user logged in. Must be &ge; 0.
nConsecutiveFailedLoginCount The number of consecutive failed logins. Must be &ge; 0.
aCustomAttrs Custom attributes. May be null.
bDeleted true if the user is deleted, false if nto
bDisabled true if the user is disabled
  User (@Nonnull @Nonempty final String sID,
        @Nonnull final DateTime aCreationDT,
        @Nullable final DateTime aLastModificationDT,
        @Nullable final DateTime aDeletionDT,
        @Nonnull @Nonempty final String sLoginName,
        @Nullable final String sEmailAddress,
        @Nonnull final PasswordHash aPasswordHash,
        @Nullable final String sFirstName,
        @Nullable final String sLastName,
        @Nullable final Locale aDesiredLocale,
        @Nullable final DateTime aLastLoginDT,
        @Nonnegative final int nLoginCount,
        @Nonnegative final int nConsecutiveFailedLoginCount,
        @Nullable final Map <String, ?> aCustomAttrs,
        final boolean bDeleted,
        final boolean bDisabled)
  {
    ValueEnforcer.notEmpty (sID"ID");
    ValueEnforcer.notNull (aCreationDT"CreationDT");
    ValueEnforcer.notEmpty (sLoginName"LoginName");
    ValueEnforcer.isGE0 (nLoginCount"LoginCount");
    ValueEnforcer.isGE0 (nConsecutiveFailedLoginCount"ConsecutiveFailedLoginCount");
     = sID;
     = aCreationDT;
     = aLastModificationDT;
     = aDeletionDT;
     = sLoginName;
    setEmailAddress (sEmailAddress);
    setPasswordHash (aPasswordHash);
     = sFirstName;
     = sLastName;
     = aDesiredLocale;
     = aLastLoginDT;
     = nLoginCount;
     = nConsecutiveFailedLoginCount;
    setAttributes (aCustomAttrs);
     = bDeleted;
     = bDisabled;
  }
  public ObjectType getTypeID ()
  {
    return .;
  }
  public boolean isAdministrator ()
  {
  }
  public String getID ()
  {
    return ;
  }
  {
    return ;
  }
  {
    return ;
  }
  void updateLastModified ()
  {
     = PDTFactory.getCurrentDateTime ();
  }
  {
    return ;
  }
  public final String getName ()
  {
    return getLoginName ();
  }
  public String getLoginName ()
  {
    return ;
  }
  EChange setLoginName (@Nonnull @Nonempty final String sLoginName)
  {
    ValueEnforcer.notEmpty (sLoginName"loginName");
    if (sLoginName.equals ())
      return .;
     = sLoginName;
    return .;
  }
  public String getEmailAddress ()
  {
    return ;
  }
  EChange setEmailAddress (@Nullable final String sEmailAddress)
  {
    if (EqualsUtils.equals (sEmailAddress))
      return .;
     = sEmailAddress;
    return .;
  }
  {
    return ;
  }
  EChange setPasswordHash (@Nonnull final PasswordHash aPasswordHash)
  {
    ValueEnforcer.notNull (aPasswordHash"PasswordHash");
    if (aPasswordHash.equals ())
      return .;
     = aPasswordHash;
    return .;
  }
  public String getFirstName ()
  {
    return ;
  }
  EChange setFirstName (@Nullable final String sFirstName)
  {
    if (EqualsUtils.equals (sFirstName))
      return .;
     = sFirstName;
    return .;
  }
  public String getLastName ()
  {
    return ;
  }
  EChange setLastName (@Nullable final String sLastName)
  {
    if (EqualsUtils.equals (sLastName))
      return .;
     = sLastName;
    return .;
  }
  public Locale getDesiredLocale ()
  {
    return ;
  }
  EChange setDesiredLocale (@Nullable final Locale aDesiredLocale)
  {
    if (EqualsUtils.equals (aDesiredLocale))
      return .;
     = aDesiredLocale;
    return .;
  }
  {
    return ;
  }
  public int getLoginCount ()
  {
    return ;
  }
  {
  }
  void onSuccessfulLogin ()
  {
     = PDTFactory.getCurrentDateTime ();
    ++;
  }
  void onFailedLogin ()
  {
  }
  public String getDisplayName ()
  {
    return StringHelper.getConcatenatedOnDemand (" ");
  }
  public boolean isDeleted ()
  {
    return ;
  }
  EChange setDeleted (final boolean bDeleted)
  {
    if (bDeleted == )
      return .;
     = bDeleted;
     = bDeleted ? PDTFactory.getCurrentDateTime () : null;
    return .;
  }
  public boolean isDisabled ()
  {
    return ;
  }
  EChange setDisabled (final boolean bDisabled)
  {
    if (bDisabled == )
      return .;
     = bDisabled;
    return .;
  }
  public boolean isEnabled ()
  {
    return !;
  }
  EChange setEnabled (final boolean bEnabled)
  {
    return setDisabled (!bEnabled);
  }
  public boolean equals (final Object o)
  {
    if (o == this)
      return true;
    if (!(o instanceof User))
      return false;
    final User rhs = (Usero;
    return .equals (rhs.m_sID);
  }
  public int hashCode ()
  {
    return new HashCodeGenerator (this).append ().getHashCode ();
  }
  public String toString ()
  {
    return ToStringGenerator.getDerived (super.toString ())
                            .append ("ID")
                            .append ("creationDT")
                            .appendIfNotNull ("lastModificationDT")
                            .appendIfNotNull ("deletionDT")
                            .append ("loginName")
                            .appendIfNotNull ("emailAddress")
                            .append ("passwordHash")
                            .appendIfNotNull ("firstName")
                            .appendIfNotNull ("lastName")
                            .appendIfNotNull ("desiredLocale")
                            .appendIfNotNull ("lastLoginDT")
                            .append ("loginCount")
                            .append ("consecutiveFailedLoginCount")
                            .append ("deleted")
                            .append ("disabled")
                            .toString ();
  }
New to GrepCode? Check out our FAQ X