Source Code Cross Referenced for LdapUserDetailsImpl.java in  » Security » acegi-security » org » acegisecurity » userdetails » ldap » 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.ldap 
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.ldap;
017:
018:        import org.acegisecurity.GrantedAuthority;
019:
020:        import org.springframework.util.Assert;
021:
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.List;
025:
026:        import javax.naming.directory.Attributes;
027:        import javax.naming.directory.BasicAttributes;
028:        import javax.naming.ldap.Control;
029:
030:        /**
031:         * A UserDetails implementation which is used internally by the Ldap services. It also contains the user's
032:         * distinguished name and a set of attributes that have been retrieved from the Ldap server.<p>An instance may be
033:         * created as the result of a search, or when user information is retrieved during authentication.</p>
034:         *  <p>An instance of this class will be used by the <tt>LdapAuthenticationProvider</tt> to construct the final
035:         * user details object that it returns.</p>
036:         *
037:         * @author Luke Taylor
038:         * @version $Id$
039:         */
040:        public class LdapUserDetailsImpl implements  LdapUserDetails {
041:            //~ Static fields/initializers =====================================================================================
042:
043:            private static final long serialVersionUID = 1L;
044:            private static final GrantedAuthority[] NO_AUTHORITIES = new GrantedAuthority[0];
045:            private static final Control[] NO_CONTROLS = new Control[0];
046:
047:            //~ Instance fields ================================================================================================
048:
049:            private Attributes attributes = new BasicAttributes();
050:            private String dn;
051:            private String password;
052:            private String username;
053:            private GrantedAuthority[] authorities = NO_AUTHORITIES;
054:            private Control[] controls = NO_CONTROLS;
055:            private boolean accountNonExpired = true;
056:            private boolean accountNonLocked = true;
057:            private boolean credentialsNonExpired = true;
058:            private boolean enabled = true;
059:
060:            //~ Constructors ===================================================================================================
061:
062:            protected LdapUserDetailsImpl() {
063:            }
064:
065:            //~ Methods ========================================================================================================
066:
067:            public Attributes getAttributes() {
068:                return attributes;
069:            }
070:
071:            public GrantedAuthority[] getAuthorities() {
072:                return authorities;
073:            }
074:
075:            public Control[] getControls() {
076:                return controls;
077:            }
078:
079:            public String getDn() {
080:                return dn;
081:            }
082:
083:            public String getPassword() {
084:                return password;
085:            }
086:
087:            public String getUsername() {
088:                return username;
089:            }
090:
091:            public boolean isAccountNonExpired() {
092:                return accountNonExpired;
093:            }
094:
095:            public boolean isAccountNonLocked() {
096:                return accountNonLocked;
097:            }
098:
099:            public boolean isCredentialsNonExpired() {
100:                return credentialsNonExpired;
101:            }
102:
103:            public boolean isEnabled() {
104:                return enabled;
105:            }
106:
107:            //~ Inner Classes ==================================================================================================
108:
109:            /**
110:             * Variation of essence pattern. Used to create mutable intermediate object
111:             */
112:            public static class Essence {
113:                private LdapUserDetailsImpl instance = createTarget();
114:                private List mutableAuthorities = new ArrayList();
115:
116:                public Essence() {
117:                }
118:
119:                public Essence(LdapUserDetails copyMe) {
120:                    setDn(copyMe.getDn());
121:                    setAttributes(copyMe.getAttributes());
122:                    setUsername(copyMe.getUsername());
123:                    setPassword(copyMe.getPassword());
124:                    setEnabled(copyMe.isEnabled());
125:                    setAccountNonExpired(copyMe.isAccountNonExpired());
126:                    setCredentialsNonExpired(copyMe.isCredentialsNonExpired());
127:                    setAccountNonLocked(copyMe.isAccountNonLocked());
128:                    setControls(copyMe.getControls());
129:                    setAuthorities(copyMe.getAuthorities());
130:                }
131:
132:                LdapUserDetailsImpl createTarget() {
133:                    return new LdapUserDetailsImpl();
134:                }
135:
136:                public Essence addAuthority(GrantedAuthority a) {
137:                    mutableAuthorities.add(a);
138:
139:                    return this ;
140:                }
141:
142:                public LdapUserDetails createUserDetails() {
143:                    //TODO: Validation of properties
144:                    Assert
145:                            .notNull(instance,
146:                                    "Essence can only be used to create a single instance");
147:
148:                    instance.authorities = getGrantedAuthorities();
149:
150:                    LdapUserDetails newInstance = instance;
151:
152:                    instance = null;
153:
154:                    return newInstance;
155:                }
156:
157:                public GrantedAuthority[] getGrantedAuthorities() {
158:                    return (GrantedAuthority[]) mutableAuthorities
159:                            .toArray(new GrantedAuthority[0]);
160:                }
161:
162:                public Essence setAccountNonExpired(boolean accountNonExpired) {
163:                    instance.accountNonExpired = accountNonExpired;
164:
165:                    return this ;
166:                }
167:
168:                public Essence setAccountNonLocked(boolean accountNonLocked) {
169:                    instance.accountNonLocked = accountNonLocked;
170:
171:                    return this ;
172:                }
173:
174:                public Essence setAttributes(Attributes attributes) {
175:                    instance.attributes = attributes;
176:
177:                    return this ;
178:                }
179:
180:                public Essence setAuthorities(GrantedAuthority[] authorities) {
181:                    mutableAuthorities = new ArrayList(Arrays
182:                            .asList(authorities));
183:
184:                    return this ;
185:                }
186:
187:                public void setControls(Control[] controls) {
188:                    instance.controls = controls;
189:                }
190:
191:                public Essence setCredentialsNonExpired(
192:                        boolean credentialsNonExpired) {
193:                    instance.credentialsNonExpired = credentialsNonExpired;
194:
195:                    return this ;
196:                }
197:
198:                public Essence setDn(String dn) {
199:                    instance.dn = dn;
200:
201:                    return this ;
202:                }
203:
204:                public Essence setEnabled(boolean enabled) {
205:                    instance.enabled = enabled;
206:
207:                    return this ;
208:                }
209:
210:                public Essence setPassword(String password) {
211:                    instance.password = password;
212:
213:                    return this ;
214:                }
215:
216:                public Essence setUsername(String username) {
217:                    instance.username = username;
218:
219:                    return this;
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.