Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Grails-Active-Directory-LDAP-example/src/groovy/com/javazquez/ldapexample/MyUserDetailsContextMapper.groovy
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (27 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javazquez.ldapexample | |
/** | |
* Created by Juan Vazquez. | |
* URL: http://javazquez.com/juan | |
* Code is provide for educational purposes. Any use in a production system is at your own risk. | |
*/ | |
import org.springframework.ldap.core.DirContextAdapter | |
import org.springframework.ldap.core.DirContextOperations | |
import org.springframework.security.core.userdetails.UserDetails | |
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper | |
class MyUserDetailsContextMapper implements UserDetailsContextMapper { | |
UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection authorities) { | |
//Grab the specific Active Directory information you want | |
String fullname = ctx.originalAttrs.attrs['cn'].values[0] | |
String email = ctx.originalAttrs.attrs['mail'].values[0].toString().toLowerCase() | |
def titleobj = ctx.originalAttrs.attrs['sn'] | |
String title = (titleobj == null) ? '' : titleobj.values[0] | |
String phone = ctx.getStringAttribute('telephoneNumber') | |
String photo = ctx.getObjectAttribute('extensionAttribute10') | |
def userDetails = new MyUserDetails(username, '', true, true, true, true, | |
authorities, fullname, email, title , photo, phone) | |
return userDetails | |
} | |
void mapUserToContext(UserDetails user, DirContextAdapter ctx) { | |
throw new IllegalStateException("Only retrieving data from LDAP is currently supported") | |
} | |
} |