私は非常にばかげた質問で、SpringセキュリティコアとSpringセキュリティーのldapプラグインを使用してGrailsアプリケーション(書店)でLDAPロールベースの認証/ 。カスタムのUserDetailsContextMapperを作成し、LDAPロールとアプリケーションロールをマッピングしようとしました。ただし、メンバーの属性は属性に返されません。私はのldapsearchを使用してLDAP上でクエリを実行するとGrails Springアプリケーション内でLDAP属性memberofを取得しています
UserDetails mapUserFromContext(DirContextOperations ctx, String username,
Collection authorities) {
Attributes attributes = ctx.getAttributes();
Object[] groups = new Object[10];
groups = ctx.getObjectAttributes("memberof"); //returns empty array
Set<GrantedAuthority> authority = new HashSet<GrantedAuthority>();
for(Object group: groups){
if (group.toString().toLowerCase().contains("ROLE_FROM_LDAP".toLowerCase()) == true){
authority.add(new SimpleGrantedAuthority("ROLE_APP"));
break;
}
}
User userDetails = new User(username, "", false, false, false, false, authority);
return userDetails;
}
興味深いことに、私は属性が返さ入手できますか。 GrailsのLDAPの構成で(のldapsearchと下図のように)プラグインが「のmemberOf」属性を取得することができるように:私がで立ち往生しています何
は「をが要求する」と同等のものを設定する方法であります(私はGrails LDAPプラグインの設定にldap.search.attributesToReturnで追加しようとしましたが、役に立たなかった)。
ldapsearch -t -x -b "ou=people,dc=domain,dc=com" "cn=myusername" memberof
.....
# LDAPv3
# base <ou=people,dc=domain,dc=com> with scope subtree
# filter: cn=myusername
# requesting: memberof
#
.....
dn: cn=myusername,ou=people,dc=domain,dc=com
memberOf: cn=ROLE_FROM_LDAP,ou=groups,dc=domain,dc=com
後GrailsのLDAPの設定です:
grails {
plugin {
springsecurity {
providerNames: ['ldapAuthProvider', 'anonymousAuthenticationProvider']
ldap {
useRememberMe = false
context {
managerDn = 'cn=manager,dc=domain,dc=com'
managerPassword = 'secret'
server = 'ldap://localhost:389/'
}
search {
base = 'ou=people,dc=domain,dc=com'
filter = 'cn={0}'
searchSubtree = true
attributesToReturn: ['memberOf'] //extra attributes you want returned
}
auth {
hideUserNotFoundExceptions = false
}
authorities {
retrieveDatabaseRoles = false
retrieveGroupRoles = true
groupSearchBase = 'ou=groups,dc=domain,dc=com'
groupSearchFilter = 'member={0}'
}
}
}
}
}
おかげでマイク、それはmapUserFromContextコールバックで実際にコレクション当局が入手でき、助け権限オブジェクトが含まれていました。しかし、私の元の質問は、クエリがldapsearchを通して動作するので、Grailsプラグイン設定を介して "memberof"属性をどのように問い合わせるかということにあります。 – dchucks