Source Code Cross Referenced for User.java in  » Security » acegi-security » org » acegisecurity » userdetails » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Security » acegi security » org.acegisecurity.userdetails 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002:         *
003:         * Licensed under the Apache License, Version 2.0 (the "License");
004:         * you may not use this file except in compliance with the License.
005:         * You may obtain a copy of the License at
006:         *
007:         *     http://www.apache.org/licenses/LICENSE-2.0
008:         *
009:         * Unless required by applicable law or agreed to in writing, software
010:         * distributed under the License is distributed on an "AS IS" BASIS,
011:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:         * See the License for the specific language governing permissions and
013:         * limitations under the License.
014:         */
015:
016:        package org.acegisecurity.userdetails;
017:
018:        import org.acegisecurity.GrantedAuthority;
019:
020:        import org.springframework.util.Assert;
021:
022:        /**
023:         * Models core user information retieved by an {@link UserDetailsService}.<p>Implemented with value object
024:         * semantics (immutable after construction, like a <code>String</code>). Developers may use this class directly,
025:         * subclass it, or write their own {@link UserDetails} implementation from scratch.</p>
026:         *
027:         * @author Ben Alex
028:         * @version $Id: User.java 1784 2007-02-24 21:00:24Z luke_t $
029:         */
030:        public class User implements  UserDetails {
031:            //~ Instance fields ================================================================================================
032:
033:            private static final long serialVersionUID = 1L;
034:            private String password;
035:            private String username;
036:            private GrantedAuthority[] authorities;
037:            private boolean accountNonExpired;
038:            private boolean accountNonLocked;
039:            private boolean credentialsNonExpired;
040:            private boolean enabled;
041:
042:            //~ Constructors ===================================================================================================
043:
044:            /**
045:             * Construct the <code>User</code> with the details required by
046:             * {@link org.acegisecurity.providers.dao.DaoAuthenticationProvider}.
047:             *
048:             * @param username the username presented to the
049:             *        <code>DaoAuthenticationProvider</code>
050:             * @param password the password that should be presented to the
051:             *        <code>DaoAuthenticationProvider</code>
052:             * @param enabled set to <code>true</code> if the user is enabled
053:             * @param authorities the authorities that should be granted to the caller
054:             *        if they presented the correct username and password and the user
055:             *        is enabled
056:             *
057:             * @throws IllegalArgumentException if a <code>null</code> value was passed
058:             *         either as a parameter or as an element in the
059:             *         <code>GrantedAuthority[]</code> array
060:             *
061:             * @deprecated use new constructor with extended properties (this
062:             *             constructor will be removed from release 1.0.0)
063:             */
064:            public User(String username, String password, boolean enabled,
065:                    GrantedAuthority[] authorities)
066:                    throws IllegalArgumentException {
067:                this (username, password, enabled, true, true, authorities);
068:            }
069:
070:            /**
071:             * Construct the <code>User</code> with the details required by
072:             * {@link org.acegisecurity.providers.dao.DaoAuthenticationProvider}.
073:             *
074:             * @param username the username presented to the
075:             *        <code>DaoAuthenticationProvider</code>
076:             * @param password the password that should be presented to the
077:             *        <code>DaoAuthenticationProvider</code>
078:             * @param enabled set to <code>true</code> if the user is enabled
079:             * @param accountNonExpired set to <code>true</code> if the account has not
080:             *        expired
081:             * @param credentialsNonExpired set to <code>true</code> if the credentials
082:             *        have not expired
083:             * @param authorities the authorities that should be granted to the caller
084:             *        if they presented the correct username and password and the user
085:             *        is enabled
086:             *
087:             * @throws IllegalArgumentException if a <code>null</code> value was passed
088:             *         either as a parameter or as an element in the
089:             *         <code>GrantedAuthority[]</code> array
090:             *
091:             * @deprecated use new constructor with extended properties (this
092:             *             constructor will be removed from release 1.0.0)
093:             */
094:            public User(String username, String password, boolean enabled,
095:                    boolean accountNonExpired, boolean credentialsNonExpired,
096:                    GrantedAuthority[] authorities)
097:                    throws IllegalArgumentException {
098:                this (username, password, enabled, accountNonExpired,
099:                        credentialsNonExpired, true, authorities);
100:            }
101:
102:            /**
103:             * Construct the <code>User</code> with the details required by
104:             * {@link org.acegisecurity.providers.dao.DaoAuthenticationProvider}.
105:             *
106:             * @param username the username presented to the
107:             *        <code>DaoAuthenticationProvider</code>
108:             * @param password the password that should be presented to the
109:             *        <code>DaoAuthenticationProvider</code>
110:             * @param enabled set to <code>true</code> if the user is enabled
111:             * @param accountNonExpired set to <code>true</code> if the account has not
112:             *        expired
113:             * @param credentialsNonExpired set to <code>true</code> if the credentials
114:             *        have not expired
115:             * @param accountNonLocked set to <code>true</code> if the account is not
116:             *        locked
117:             * @param authorities the authorities that should be granted to the caller
118:             *        if they presented the correct username and password and the user
119:             *        is enabled
120:             *
121:             * @throws IllegalArgumentException if a <code>null</code> value was passed
122:             *         either as a parameter or as an element in the
123:             *         <code>GrantedAuthority[]</code> array
124:             */
125:            public User(String username, String password, boolean enabled,
126:                    boolean accountNonExpired, boolean credentialsNonExpired,
127:                    boolean accountNonLocked, GrantedAuthority[] authorities)
128:                    throws IllegalArgumentException {
129:                if (((username == null) || "".equals(username))
130:                        || (password == null)) {
131:                    throw new IllegalArgumentException(
132:                            "Cannot pass null or empty values to constructor");
133:                }
134:
135:                this .username = username;
136:                this .password = password;
137:                this .enabled = enabled;
138:                this .accountNonExpired = accountNonExpired;
139:                this .credentialsNonExpired = credentialsNonExpired;
140:                this .accountNonLocked = accountNonLocked;
141:                setAuthorities(authorities);
142:            }
143:
144:            //~ Methods ========================================================================================================
145:
146:            public boolean equals(Object rhs) {
147:                if (!(rhs instanceof  User) || (rhs == null)) {
148:                    return false;
149:                }
150:
151:                User user = (User) rhs;
152:
153:                // We rely on constructor to guarantee any User has non-null and >0
154:                // authorities
155:                if (user.getAuthorities().length != this .getAuthorities().length) {
156:                    return false;
157:                }
158:
159:                for (int i = 0; i < this .getAuthorities().length; i++) {
160:                    if (!this .getAuthorities()[i]
161:                            .equals(user.getAuthorities()[i])) {
162:                        return false;
163:                    }
164:                }
165:
166:                // We rely on constructor to guarantee non-null username and password
167:                return (this .getPassword().equals(user.getPassword())
168:                        && this .getUsername().equals(user.getUsername())
169:                        && (this .isAccountNonExpired() == user
170:                                .isAccountNonExpired())
171:                        && (this .isAccountNonLocked() == user
172:                                .isAccountNonLocked())
173:                        && (this .isCredentialsNonExpired() == user
174:                                .isCredentialsNonExpired()) && (this 
175:                        .isEnabled() == user.isEnabled()));
176:            }
177:
178:            public GrantedAuthority[] getAuthorities() {
179:                return authorities;
180:            }
181:
182:            public String getPassword() {
183:                return password;
184:            }
185:
186:            public String getUsername() {
187:                return username;
188:            }
189:
190:            public int hashCode() {
191:                int code = 9792;
192:
193:                if (this .getAuthorities() != null) {
194:                    for (int i = 0; i < this .getAuthorities().length; i++) {
195:                        code = code * (this .getAuthorities()[i].hashCode() % 7);
196:                    }
197:                }
198:
199:                if (this .getPassword() != null) {
200:                    code = code * (this .getPassword().hashCode() % 7);
201:                }
202:
203:                if (this .getUsername() != null) {
204:                    code = code * (this .getUsername().hashCode() % 7);
205:                }
206:
207:                if (this .isAccountNonExpired()) {
208:                    code = code * -2;
209:                }
210:
211:                if (this .isAccountNonLocked()) {
212:                    code = code * -3;
213:                }
214:
215:                if (this .isCredentialsNonExpired()) {
216:                    code = code * -5;
217:                }
218:
219:                if (this .isEnabled()) {
220:                    code = code * -7;
221:                }
222:
223:                return code;
224:            }
225:
226:            public boolean isAccountNonExpired() {
227:                return accountNonExpired;
228:            }
229:
230:            public boolean isAccountNonLocked() {
231:                return this .accountNonLocked;
232:            }
233:
234:            public boolean isCredentialsNonExpired() {
235:                return credentialsNonExpired;
236:            }
237:
238:            public boolean isEnabled() {
239:                return enabled;
240:            }
241:
242:            protected void setAuthorities(GrantedAuthority[] authorities) {
243:                Assert.notNull(authorities,
244:                        "Cannot pass a null GrantedAuthority array");
245:
246:                for (int i = 0; i < authorities.length; i++) {
247:                    Assert
248:                            .notNull(
249:                                    authorities[i],
250:                                    "Granted authority element "
251:                                            + i
252:                                            + " is null - GrantedAuthority[] cannot contain any null elements");
253:                }
254:
255:                this .authorities = authorities;
256:            }
257:
258:            public String toString() {
259:                StringBuffer sb = new StringBuffer();
260:                sb.append(super .toString()).append(": ");
261:                sb.append("Username: ").append(this .username).append("; ");
262:                sb.append("Password: [PROTECTED]; ");
263:                sb.append("Enabled: ").append(this .enabled).append("; ");
264:                sb.append("AccountNonExpired: ").append(this .accountNonExpired)
265:                        .append("; ");
266:                sb.append("credentialsNonExpired: ").append(
267:                        this .credentialsNonExpired).append("; ");
268:                sb.append("AccountNonLocked: ").append(this .accountNonLocked)
269:                        .append("; ");
270:
271:                if (this .getAuthorities() != null) {
272:                    sb.append("Granted Authorities: ");
273:
274:                    for (int i = 0; i < this .getAuthorities().length; i++) {
275:                        if (i > 0) {
276:                            sb.append(", ");
277:                        }
278:
279:                        sb.append(this .getAuthorities()[i].toString());
280:                    }
281:                } else {
282:                    sb.append("Not granted any authorities");
283:                }
284:
285:                return sb.toString();
286:            }
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.