1 | /* Copyright 2006-2009 the original author or authors. |
---|
2 | * |
---|
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | * you may not use this file except in compliance with the License. |
---|
5 | * You may obtain a copy of the License at |
---|
6 | * |
---|
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | * |
---|
9 | * Unless required by applicable law or agreed to in writing, software |
---|
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | * See the License for the specific language governing permissions and |
---|
13 | * limitations under the License. |
---|
14 | */ |
---|
15 | package org.codehaus.groovy.grails.plugins.springsecurity.ldap; |
---|
16 | |
---|
17 | import javax.naming.directory.Attributes; |
---|
18 | |
---|
19 | import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser; |
---|
20 | import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserImpl; |
---|
21 | import org.springframework.security.GrantedAuthority; |
---|
22 | import org.springframework.security.userdetails.ldap.LdapUserDetails; |
---|
23 | |
---|
24 | /** |
---|
25 | * A {@link GrailsUser} for use in LDAP authentication. |
---|
26 | * |
---|
27 | * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> |
---|
28 | */ |
---|
29 | public class GrailsLdapUser extends GrailsUserImpl implements GrailsUser, LdapUserDetails { |
---|
30 | |
---|
31 | private static final long serialVersionUID = -1557817722745366207L; |
---|
32 | |
---|
33 | private final Attributes _attributes; |
---|
34 | private final String _dn; |
---|
35 | |
---|
36 | /** |
---|
37 | * Constructor from {@link LdapUserDetails}. |
---|
38 | * @param details the original details |
---|
39 | * @param domainClass the domain instance |
---|
40 | */ |
---|
41 | @SuppressWarnings("deprecation") // just passing along the core impl |
---|
42 | public GrailsLdapUser(final LdapUserDetails details, final Object domainClass) { |
---|
43 | super(details.getUsername(), details.getPassword(), details.isEnabled(), |
---|
44 | details.isAccountNonExpired(), details.isCredentialsNonExpired(), |
---|
45 | details.isAccountNonLocked(), details.getAuthorities(), domainClass); |
---|
46 | _attributes = details.getAttributes(); |
---|
47 | _dn = details.getDn(); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * Full constructor. |
---|
52 | * @param username the username |
---|
53 | * @param password the password |
---|
54 | * @param enabled whether the user is enabled |
---|
55 | * @param accountNonExpired whether the user's account is expired |
---|
56 | * @param credentialsNonExpired whether the user's credentials are locked |
---|
57 | * @param accountNonLocked whether the user's account is locked |
---|
58 | * @param authorities authorities |
---|
59 | * @param attributes attributes |
---|
60 | * @param dn distinguished name |
---|
61 | * @param domainClass the domain instance |
---|
62 | */ |
---|
63 | public GrailsLdapUser(final String username, final String password, final boolean enabled, |
---|
64 | final boolean accountNonExpired, final boolean credentialsNonExpired, |
---|
65 | final boolean accountNonLocked, final GrantedAuthority[] authorities, |
---|
66 | final Attributes attributes, final String dn, final Object domainClass) { |
---|
67 | super(username, password, enabled, accountNonExpired, credentialsNonExpired, |
---|
68 | accountNonLocked, authorities, domainClass); |
---|
69 | _attributes = attributes; |
---|
70 | _dn = dn; |
---|
71 | } |
---|
72 | |
---|
73 | /** |
---|
74 | * {@inheritDoc} |
---|
75 | */ |
---|
76 | public Attributes getAttributes() { |
---|
77 | return _attributes; |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * {@inheritDoc} |
---|
82 | * @see org.springframework.security.userdetails.ldap.LdapUserDetails#getDn() |
---|
83 | */ |
---|
84 | public String getDn() { |
---|
85 | return _dn; |
---|
86 | } |
---|
87 | } |
---|