Skip to content
Go to file
Cannot retrieve contributors at this time
34 lines (27 sloc) 1.38 KB
package com.javazquez.ldapexample
* Created by Juan Vazquez.
* URL:
* 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
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")
You can’t perform that action at this time.