View Javadoc

1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.common;
20  
21  import java.util.Collection;
22  
23  import org.springframework.security.core.GrantedAuthority;
24  import org.springframework.security.core.userdetails.User;
25  
26  /**
27   * The Class CustomUserDetails.
28   */
29  public final class CustomUserDetails extends User {
30  
31      @Override
32  	public int hashCode() {
33  		final int prime = 31;
34  		int result = super.hashCode();
35  		result = prime * result + ((email == null) ? 0 : email.hashCode());
36  		result = prime * result + ((name == null) ? 0 : name.hashCode());
37  		result = prime * result + (newUser ? 1231 : 1237);
38  		return result;
39  	}
40  
41  	@Override
42  	public boolean equals(Object obj) {
43  		if (this == obj)
44  			return true;
45  		if (!super.equals(obj))
46  			return false;
47  		if (getClass() != obj.getClass())
48  			return false;
49  		CustomUserDetails other = (CustomUserDetails) obj;
50  		if (email == null) {
51  			if (other.email != null)
52  				return false;
53  		} else if (!email.equals(other.email))
54  			return false;
55  		if (name == null) {
56  			if (other.name != null)
57  				return false;
58  		} else if (!name.equals(other.name))
59  			return false;
60  		if (newUser != other.newUser)
61  			return false;
62  		return true;
63  	}
64  
65  	/** The Constant serialVersionUID. */
66  	private static final long serialVersionUID = 1L;
67  
68  	/** The email. */
69  	private String email;
70  
71      /** The name. */
72      private String name;
73  
74      /** The new user. */
75      private boolean newUser;
76  
77      /**
78  	 * Instantiates a new custom user details.
79  	 *
80  	 * @param username
81  	 *            the username
82  	 * @param authorities
83  	 *            the authorities
84  	 */
85      public CustomUserDetails(final String username, final Collection<GrantedAuthority> authorities) {
86          super(username, "unused", authorities);
87      }
88  
89      /**
90  	 * Gets the email.
91  	 *
92  	 * @return the email
93  	 */
94      public String getEmail() {
95          return email;
96      }
97  
98      /**
99  	 * Sets the email.
100 	 *
101 	 * @param email
102 	 *            the new email
103 	 */
104     public void setEmail(final String email) {
105         this.email = email;
106     }
107 
108     /**
109 	 * Checks if is new user.
110 	 *
111 	 * @return true, if is new user
112 	 */
113     public boolean isNewUser() {
114         return newUser;
115     }
116 
117     /**
118 	 * Sets the new user.
119 	 *
120 	 * @param newUser
121 	 *            the new new user
122 	 */
123     public void setNewUser(final boolean newUser) {
124         this.newUser = newUser;
125     }
126 
127     /**
128 	 * Gets the name.
129 	 *
130 	 * @return the name
131 	 */
132     public String getName() {
133         return name;
134     }
135 
136     /**
137 	 * Sets the name.
138 	 *
139 	 * @param name
140 	 *            the new name
141 	 */
142     public void setName(final String name) {
143         this.name = name;
144     }
145 }
146