001    /*
002     * Copyright 2007 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.codehaus.groovy.grails.plugins.springsecurity.ldap;
017    
018    import javax.naming.directory.Attributes;
019    
020    import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser;
021    import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserImpl;
022    import org.springframework.security.userdetails.ldap.LdapUserDetails;
023    
024    /**
025     * A <code>GrailsUser</code> for use in LDAP authentication.
026     *
027     * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
028     */
029    public class GrailsLdapUser extends GrailsUserImpl implements GrailsUser, LdapUserDetails {
030    
031            private static final long serialVersionUID = -1557817722745366207L;
032    
033            private final Attributes _attributes;
034            private final String _dn;
035    
036            /**
037             * Full constructor.
038             * @param details  the original details
039             * @param domainClass  the domain instance
040             */
041            @SuppressWarnings("deprecation") // just passing along the core impl
042            public GrailsLdapUser(final LdapUserDetails details, final Object domainClass) {
043                    super(details.getUsername(), details.getPassword(), details.isEnabled(),
044                                    details.isAccountNonExpired(), details.isCredentialsNonExpired(),
045                                    details.isAccountNonLocked(), details.getAuthorities(), domainClass);
046                    _attributes = details.getAttributes();
047                    _dn = details.getDn();
048            }
049    
050            /**
051             * {@inheritDoc}
052             */
053            public Attributes getAttributes() {
054                    return _attributes;
055            }
056    
057            /**
058             * {@inheritDoc}
059             * @see org.springframework.security.userdetails.ldap.LdapUserDetails#getDn()
060             */
061            public String getDn() {
062                    return _dn;
063            }
064    }