001 package com.croftsoft.core.security;
002
003 import java.io.Serializable;
004
005 import com.croftsoft.core.lang.NullArgumentException;
006 import com.croftsoft.core.lang.ObjectLib;
007
008 /*********************************************************************
009 * Stores a username/password pair.
010 *
011 * @version
012 * 2003-06-17
013 * @since
014 * 2001-04-12
015 * @author
016 * <a href="https://www.croftsoft.com/">David W. Croft</a>
017 *********************************************************************/
018
019 public final class Authentication
020 implements Cloneable, Serializable
021 //////////////////////////////////////////////////////////////////////
022 //////////////////////////////////////////////////////////////////////
023 {
024
025 private static final long serialVersionUID = 0L;
026
027 //
028
029 private final String username;
030
031 private final String password;
032
033 //////////////////////////////////////////////////////////////////////
034 //////////////////////////////////////////////////////////////////////
035
036 /*********************************************************************
037 * Main constructor.
038 *
039 * @throws NullArgumentException
040 * If username is null.
041 *********************************************************************/
042 public Authentication (
043 String username,
044 String password )
045 //////////////////////////////////////////////////////////////////////
046 {
047 NullArgumentException.check ( this.username = username );
048
049 this.password = password;
050 }
051
052 //////////////////////////////////////////////////////////////////////
053 //////////////////////////////////////////////////////////////////////
054
055 public String getUsername ( ) { return username; }
056
057 public String getPassword ( ) { return password; }
058
059 //////////////////////////////////////////////////////////////////////
060 //////////////////////////////////////////////////////////////////////
061
062 public Object clone ( )
063 //////////////////////////////////////////////////////////////////////
064 {
065 try
066 {
067 return super.clone ( );
068 }
069 catch ( CloneNotSupportedException ex )
070 {
071 // This will never happen.
072
073 throw new RuntimeException ( );
074 }
075 }
076
077 public boolean equals ( Object other )
078 //////////////////////////////////////////////////////////////////////
079 {
080 if ( other == null )
081 {
082 return false;
083 }
084
085 if ( !getClass ( ).equals ( other.getClass ( ) ) )
086 {
087 return false;
088 }
089
090 Authentication that = ( Authentication ) other;
091
092 return this.username.equals ( that.username )
093 && ObjectLib.equivalent ( this.password, that.password );
094 }
095
096 public int hashCode ( )
097 //////////////////////////////////////////////////////////////////////
098 {
099 return username.hashCode ( );
100 }
101
102 //////////////////////////////////////////////////////////////////////
103 //////////////////////////////////////////////////////////////////////
104 }