我正在努力让grails spring ldap工作。无论我尝试什么,我都没有成功进行身份验证。我不确定是什么导致了我的错误。这是我的配置:
grails.plugin.springsecurity.ldap.context.managerDn = 'cn=root'
grails.plugin.springsecurity.ldap.context.managerPassword = '<value>'
grails.plugin.springsecurity.ldap.context.server = 'ldap://myserver.com:389'
grails.plugin.springsecurity.ldap.authorities.ignorePartialResultException = true
grails.plugin.springsecurity.ldap.search.base ='o=<value>,c=<value'
grails.plugin.springsecurity.ldap.search.filter = 'sAMAccountName={0}'
grails.plugin.springsecurity.ldap.search.searchSubtree = true
//grails.plugin.springsecurity.password.algorithm = 'SHA-1'
//grails.plugins.springsecurity.ldap.search.derefLink = true
grails.plugin.springsecurity.ldap.auth.hideUserNotFoundExceptions = false
//grails.plugin.springsecurity.ldap.mapper.userDetailsClass = 'person'
//grails.plugin.springsecurity.ldap.search.attributesToReturn = ['cn', 'displayName'] // extra attributes you want returned
grails.plugin.springsecurity.providerNames = ['ldapAuthProvider', 'anonymousAuthenticationProvider']
// role-specific LDAP config
//grails.plugin.springsecurity.ldap.useRememberMe = false
//grails.plugin.springsecurity.ldap.authorities.retrieveGroupRoles = true
//grails.plugin.springsecurity.ldap.authorities.retrieveDatabaseRoles = false
//grails.plugin.springsecurity.ldap.authenticator.useBind = true
grails.plugin.springsecurity.ldap.authorities.groupSearchBase='cn=myUser'
grails.plugin.springsecurity.ldap.authorities.groupSearchFilter = 'member={0}'
日志:
2014-04-30 10:24:52,374 [http-bio-8099-exec-8] DEBUG authentication.ProviderManager - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
2014-04-30 10:24:52,418 [http-bio-8099-exec-8] DEBUG authentication.LdapAuthenticationProvider - Processing authentication request for user: cn=<userid> 2014-04-30 10:24:52,418
[http-bio-8099-exec-8] DEBUG search.FilterBasedLdapUserSearch - Searching for user 'cn= <userid>', with user search [ searchFilter: '(uid={0})', searchBase: 'o=<value>,c=<value>', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ]
2014-04-30 10:24:52,422 [http-bio-8099-exec-8] DEBUG ldap.SpringSecurityLdapTemplate - Searching for entry under DN '', base = 'o=<value>,c=<value>', filter = '(uid={0})'
2014-04-30 10:24:52,422 [http-bio-8099-exec-8] DEBUG rememberme.TokenBasedRememberMeServices - Interactive login attempt was unsuccessful.
2014-04-30 10:24:52,423 [http-bio-8099-exec-8] DEBUG rememberme.TokenBasedRememberMeServices - Cancelling cookie 2014-04-30 10:24:52,423
[http-bio-8099-exec-8] DEBUG web.DefaultRedirectStrategy - Redirecting to '/LDAPTest1/login/authfail?login_error=1'
请告知
Java代码: `
public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
public static String MY_HOST = "ldap://myserver:389";
public static String MY_SEARCHBASE = "o=<value>,c=<value>";
public static String MY_FILTER = "cn=<userid>";
public static String MGR_DN = "cn=root";
public static String MGR_PW = "<pwd>";
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,INITCTX);
env.put(Context.PROVIDER_URL,MY_HOST);
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,MGR_DN);
env.put(Context.SECURITY_CREDENTIALS,MGR_PW);
DirContext ctx = new InitialDirContext(env);
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
//performs the actual search
//We give it a searchbase, a filter and the contraints containing the scope
//of the search
NamingEnumeration results = ctx.search(MY_SEARCHBASE,MY_FILTER,constraints);
`
答案 0 :(得分:2)
所以,another user had a similar problem。
看起来他改变的主要价值也与你的不同是
grails.plugins.springsecurity.conf.ldap.authorities.retrieveGroupRoles = false
此外,您的groupSearchBase应该是组,而不是特定用户。而不是
grails.plugin.springsecurity.ldap.authorities.groupSearchBase='cn=myUser'
应该更像是
grails.plugins.springsecurity.ldap.authorities.groupSearchBase ='DC=Group,DC=com'
在您的工作Java代码中,您似乎使用的是与grails配置中不同的搜索过滤器。您的Java代码的过滤器为"cn=<userid>"
,但您的Grails配置使用的是'sAMAccountName = {0}'。我认为sAMAccountName是Microsoft Active Directory系统的首选,但您的LDAP服务器可能不同。
要检查的最后一件事:您还需要为Spring Security Core配置一些内容。以下是上述链接中的示例:
// Added by the Spring Security Core plugin:
grails.plugins.springsecurity.userLookup.userDomainClassName = 'org.example.SecUser'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 'org.example.SecUserSecRole'
grails.plugins.springsecurity.authority.className = 'org.example.SecRole'
如果您不确定要为这些设置使用哪些值,请查看Spring Security Plugin文档。您需要设置一些必需的域类。 http://grails-plugins.github.io/grails-spring-security-core/docs/manual/