我正在编写一个要求用户登录的Web应用程序.我的公司有一个Active Directory服务器,我想为此目的使用它.但是,我在使用Spring验证用户凭据时遇到问题.
我正在使用Spring Security 3.2.2,Spring Ldap 2.0.1和Java 1.7.
Web应用程序启动良好,针对InMemory-Authentication的身份验证也运行良好,因此我的应用程序的其余部分似乎配置正确.
这是我的配置:
@Configuration
@EnableWebSecurity
public class LdapConfig extends WebSecurityConfigurerAdapter {
@Bean
public ActiveDirectoryLdapAuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
val provider = new ActiveDirectoryLdapAuthenticationProvider("my.domain", "ldap://LDAP_ID:389/OU=A_GROUP,DC=domain,DC=tld");
provider.setConvertSubErrorCodesToExceptions(true);
provider.setUseAuthenticationRequestCredentials(true);
provider.setUseAuthenticationRequestCredentials(true);
return provider;
}
@Bean
public LoggerListener loggerListener() {
return new LoggerListener();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(activeDirectoryLdapAuthenticationProvider());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// Configuration for Redirects, Login-Page and stuff
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用MY_USERNAME和MY_PASSWORD登录时,我得到了一个 Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
完整Stacktrace:
14:59:00,508 …Run Code Online (Sandbox Code Playgroud) 我基本上走在Active Directory中的LDAP树.
在每个级别,我查询"(objectClass=*)".当我在root上执行此操作时,例如,"dc=example,dc=com"我将获得以下异常.这适用于我们的其他LDAP实例.出于某种原因,仅在我们的Active Directory服务器上出现此异常.在Active Directory服务器上使用JXplorer时,我也会遇到相同的异常.
从网上阅读我发现有人说你应该打开跟随,不知道这意味着什么...所以在我javax.naming.directory.SearchControls通过我调用的查询传递的控件对象()上searchControls.setDerefLinkFlag(true).我也尝试过将其设置false为相同的结果.关于还有什么可能导致这个问题的任何建议?也许我怎么能解决它?
注意:在这篇文章中,我将baseDn更改dc=<my company domain>为我的公司隐私的示例.
javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name 'dc=example,dc=com'
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2794)
at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1826)
at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1749)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:368)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:338)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:321)
at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:248)
at com.motio.pi.gui.panels.useraccess.ldap.LDAPConnector.query(LDAPConnector.java:262)
at com.motio.pi.gui.selector.directory.CognosDirectoryBrowserController.expandCognosTreeNode(CognosDirectoryBrowserController.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.motio.pi.utils.PIThreadDelegate$1.run(PIThreadDelegate.java:54)
at java.lang.Thread.run(Thread.java:662)
Run Code Online (Sandbox Code Playgroud) 我必须配置Spring安全性以通过LDAP对用户进行身份验证.这是经理用户所在的子树:
ldaps://vldp.floal:636/CN=Administration,CN=fdam,DC=fg,DC=local
Run Code Online (Sandbox Code Playgroud)
这是用户所在的地方:
ldaps://vldp.floal:636/CN=ProxyUsers,CN=fdam,DC=fg,DC=local
Run Code Online (Sandbox Code Playgroud)
所以我使用这个设置:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.ldapAuthentication()
.contextSource()
.url("ldaps://vldp.floal:636/DC=fg,DC=local")
.managerDn("CN=A0XXX32,CN=Administration,CN=fdam,DC=fg,DC=local")
.managerPassword(password)
.and()
.userSearchBase("CN=ProxyUsers,CN=fdam")
.userSearchFilter("(CN={0})")
.ldapAuthoritiesPopulator(myAuthPopulator);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试通过用户登录时,问题是异常抛出,我收到此错误:
2016-03-25 14:43:14 [http-nio-8086-exec-6] ERROR o.s.s.w.a.UsernamePasswordAuthenticationFilter - An internal error occurred while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031522C9, problem 2001 (NO_OBJECT), data 0, best match of:
'CN=fdam,DC=fg,DC=local'
]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-031522C9, problem 2001 (NO_OBJECT), data 0, best match of:
'CN=fdam,DC=fg,DC=local'
]; …Run Code Online (Sandbox Code Playgroud) 我们有一个用户,我们的公司门户无法从AD获取组.
在门户日志中,我们看到此错误:
javax.naming.PartialResultException:未处理的Continuation Reference(s)剩余名称''
我已经用Google搜索了错误,似乎描述了这种情况的最佳症状以及解决方法如下:http://www-01.ibm.com/support/docview.wss?uid = swg21232921
假设我们不想仅仅因为一个用户而改变配置但是要修改这个特定用户的数据,有人可以解释一下在检查用户在AD中的记录时如何识别这个?这是否与他的小组作业有关,如果是,那么我应该寻找什么?
应用程序学问题很长,但总之我想知道如何org.springframework.ldap.core.LdapTemplate#ignorePartialResultException使用Spring Java Config 设置标志。
长期存在的问题是...
我想使用我们公司的Active Directory进行身份验证(这意味着用户/密码检查),然后再进行授权(因此他们有权使用哪些角色)。
我采用了春季ldap指南,并进行了更改以连接到我们公司的Active Directory,而不是使用指南的LDIF文件。通过调试,我知道程序连接到Active Directory并正确验证了用户身份,但是在检索权限时,出现以下异常:
Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud)
从谷歌搜索中,我看到这是一个常见的LDAP / ActiveDirectory问题,我需要设置标志以忽略引用。我遵循了这个SO问题中的示例。但是,我仍然遇到异常,通过调试,我可以发现在为用户搜索角色时,以下方法中发生了错误。
org.springframework.ldap.core.LdapTemplate#search(org.springframework.ldap.core.SearchExecutor, org.springframework.ldap.core.NameClassPairCallbackHandler, org.springframework.ldap.core.DirContextProcessor)
Run Code Online (Sandbox Code Playgroud)
作为参考,我的WebSecurityConfig文件:
Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException
Run Code Online (Sandbox Code Playgroud) active-directory spring-ldap spring-security-ldap spring-java-config