Hi,
I am able to do the configuration of spring-security-core and spring-security-ldap in grails.
1. I installed spring-security-core and then I created classes User, Role, UserRole using s2-quickstart of security-core plugin functionality.
2. I intalled spring-security-ladp plugin.
3. Configure properties of ldap in config.groovy then db related in database.groovy, buildconfig.groovy and url related in urlmappings.groovy.
4. Then I created two classes
Code:
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.User
class MySecureUser extends User{
final String fullname
final String email
final String lastname
final String description
MySecureUser(String username, String password,
boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired,
boolean accountNonLocked, Collection<GrantedAuthority> authorities, String fullname,
String email, String lastname, String description) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities)
this.fullname = fullname
this.email = email
this.lastname = lastname
this.description = description
}
}
Another class:
Code:
import java.util.Collection;
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.ldap.userdetails.UserDetailsContextMapper;
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
import com.test.MySecureUser
class UserDetailsContextMapperImpl implements UserDetailsContextMapper {
@Override
public UserDetails mapUserFromContext(DirContextOperations ctx,
String username, Collection<GrantedAuthority> authorities) {
// TODO Auto-generated method stub
String fullname = ctx.originalAttrs.attrs[''].values[0]
String email = ctx.originalAttrs.attrs[''].values[0].toString().toLowerCase()
String lastname = ctx.originalAttrs.attrs[''].values[0].toString().toLowerCase()
String description = ctx.originalAttrs.attrs[''].values[0].toString().toLowerCase()
def userdetails = new MySecureUser(username, '', true, true, true, true, authorities, fullname, email, lastname, description) { }
return userdetails
}
@Override
public void mapUserToContext(UserDetails arg0, DirContextAdapter arg1) {
// TODO Auto-generated method stub
throw new IllegalStateException("Only retrieving data from AD is currently supported")
}
}
5. Crate entry in resource.groovy of spring
Code:
ldapUserDetailsMapper(UserDetailsContextMapperImpl) {
// bean attributes
}
After running the application, it authenticate and working as per expectation.
But the problem is:
1. public UserDetails mapUserFromContext(DirContextOperations ctx,
String username, Collection<GrantedAuthority> authorities) is looking for authorities in the form of "List"
2. The User class which I have created with spring-security-core return the autority in the form of Set
I tried to use the same User class before writing MySecureUser but not getting any success?
Can anyone have hint, how to use the same class which spring-security-core created for User.?
Or is ther anything I missed?
Any inputs, welcome
Malhar