对于Spring Boot应用程序,我LdapTemplate使用注释成功配置了Spring ,包括LdapContextSource与@Valueapplication.properties中的s 的依赖关系.(哇!我找不到一个例子,所以也许这会帮助别人.)
片段(下面)设置上下文源,将其注入LdapTemplate到我的DirectoryService中,然后自动装入到我的DirectoryService中.
是否有更好/更清晰的方法来设置ContextSourceSpring Boot应用程序?
application.properties(在类路径上):
ldap.url=ldap://server.domain.com:389
ldap.base:OU=Employees,OU=Users,DC=domain,DC=com
ldap.username:CN=myuserid,OU=employees,OU=Users,DC=domain,DC=com
ldap.password:secretthingy
Run Code Online (Sandbox Code Playgroud)
MyLdapContextSource.java:
@Component
public class MyLdapContextSource extends LdapContextSource implements ContextSource {
@Value("${ldap.url}")
@Override
public void setUrl(String url) { super.setUrl(url); }
@Value("${ldap.base}")
@Override
public void setBase(String base) {super.setBase(base); }
@Value("${ldap.username}")
@Override
public void setUserDn(String userDn) {super.setUserDn(userDn); }
@Value("${ldap.password}")
@Override
public void setPassword(String password) { super.setPassword(password); }
}
Run Code Online (Sandbox Code Playgroud)
MyLdapTemplate.java:
@Component
public class MyLdapTemplate extends LdapTemplate {
@Autowired
public MyLdapTemplate(ContextSource …Run Code Online (Sandbox Code Playgroud) 我正在编写一个要求用户登录的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) 在我们的Spring Boot应用程序中,我们spring-security-ldap用于验证可以访问我们应用程序的用户.我们在功能上看不到任何与身份验证有关的问题,但是当我们点击/authenticator/healthURL时,我们会获得ldap的以下状态:
"ldap": {
"status": "DOWN",
"error": "java.lang.NullPointerException: null"
}
Run Code Online (Sandbox Code Playgroud)
跟踪此空指针异常,我们在尝试访问时获取此跟踪env.put(Context.SECURITY_PRINCIPAL, userDn);:
java.lang.NullPointerException: null
at java.util.Hashtable.put(Unknown Source) ~[na:1.8.0_111]
at org.springframework.ldap.core.support.SimpleDirContextAuthenticationStrategy.setupEnvironment(SimpleDirContextAuthenticationStrategy.java:42) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.setupAuthenticatedEnvironment(AbstractContextSource.java:194) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.getAuthenticatedEnv(AbstractContextSource.java:582) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:134) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:158) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.ldap.core.LdapTemplate.executeReadOnly(LdapTemplate.java:802) ~[spring-ldap-core-2.3.1.RELEASE.jar:2.3.1.RELEASE]
at org.springframework.boot.actuate.health.LdapHealthIndicator.doHealthCheck(LdapHealthIndicator.java:46) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:43) ~[spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.health.CompositeHealthIndicator.health(CompositeHealthIndicator.java:68) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.HealthEndpoint.invoke(HealthEndpoint.java:81) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.getHealth(HealthMvcEndpoint.java:171) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(HealthMvcEndpoint.java:145) [spring-boot-actuator-1.5.4.RELEASE.jar:1.5.4.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_111]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) [spring-web-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at …Run Code Online (Sandbox Code Playgroud) 我是ldap的新手,我正在尝试一下我认为是一个简单的例子来测试一个有人已经设置用于测试的ldap实例的spring ldap模块.
有关我正在使用的ldap实例的详细信息,请访问:http: //blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/
我使用了ldap浏览器/管理工具(Softerra LDAP Admin),我可以毫无问题地访问该目录.
当我使用java和spring-ldap(2.0.1)尝试它时,我得到上面提到的身份验证异常.在设置我自己的ldap实例以尝试进一步排除故障之前,我想在这里查看,以防有经验的人可以指出我错过的一些明显的东西.
以下是我使用的代码:
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import java.util.List;
public class LdapTest {
public List<String> getListing() {
LdapTemplate template = getTemplate();
List<String> children = template.list("dc=testathon,dc=net");
return children;
}
private LdapTemplate getTemplate(){
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://ldap.testathon.net:389");
contextSource.setUserDn("cn=john");
contextSource.setPassword("john");
try {
contextSource.afterPropertiesSet();
} catch (Exception ex) {
ex.printStackTrace();
}
LdapTemplate template = new LdapTemplate();
template.setContextSource(contextSource);
return template;
}
public static void main(String[] args){
LdapTest sClient = new LdapTest();
List<String> children = sClient.getListing(); …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) 我目前正在尝试使用嵌入式ldap服务器进行单元测试.
在Spring Security中,您可以快速定义嵌入式ldap服务器,以便使用从指定的ldif加载的一些示例数据对标记进行测试.
我将使用Spring Ldap执行ldap操作,并考虑测试用户服务对象的常用CRUD功能.
但是,有没有办法确保嵌入式服务器中的条目处于相同的一致状态(有点像删除所有并重新加载ldif条目)我正在运行的每个测试?
我想到了以下内容:1)表明该方法污染了上下文,并强制重新创建嵌入式ldap服务器,这听起来很痛苦,因为它必须为每个方法重新启动服务器2)在测试组织中创建测试条目,这样我就可以取消绑定它们,然后再在那里再次加载ldif文件.
我更喜欢2,但似乎Spring LDAP没有好的帮助器来加载和发送ldif文件的内容.
有关如何使用spring的嵌入式ldap服务器或我提到的两种可能解决方案执行ldap测试的任何建议?
谢谢
我无法使用LDAP对用户进行身份验证.我有以下细节:
URL=ldap://10.10.10.10:389
LDAP BASE:DC=lab2,DC=ins
LDAP Bind Account: CN=Ldap Bind,OU=Service Accounts,OU=TECH,DC=lab2,DC=ins
LDAP Bind Account Pw: secret
Run Code Online (Sandbox Code Playgroud)
我可以sAMAccountName使用上面的详细信息搜索值,但是如何使用用户名和密码验证用户?
如果您按照我之前的问题进行操作,那么您将了解到,我已成功连接到LDAP服务器但无法对其进行身份验证.
用户进行身份验证:
user: someusername
password: somepwd
Run Code Online (Sandbox Code Playgroud)
我无法连接到LDAP服务器,'somepwd'我应该如何使用someusername.我能够搜索给定的用户sAMAccountName.
我目前正在使用Spring Boot创建一个新的Web应用程序,并开始集成Spring Security进行身份验证.在成功遵循基于Spring Boot的LDAP教程之后,我想将基于JavaConfig的配置指向我的Active Directory实例.
我的应用程序现在按预期处理错误的凭据,但现在导致有效的凭据
javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name ''
Run Code Online (Sandbox Code Playgroud)
这是一个常见的问题-有一个数量 的 地方在那里已经遇到了这个问题.解决方案似乎是将Context.REFERRAL设置为"follow",但我找不到任何指示如何使用JavaConfig设置该选项的文档.这是我唯一可以恢复基于XML的配置吗?看起来Spring正在将开发人员推向JavaConfig,所以如果可能的话,我想避免混合这两种方法.
以下是我的安全配置:
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/css/**").permitAll().anyRequest()
.fullyAuthenticated().and().formLogin();
}
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.userSearchBase("")
.userSearchFilter("(&(cn={0}))").contextSource()
.managerDn("<username>")
.managerPassword("<password>")
.url("ldap://<url>");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要通过带有SSL的spring-ldap与LDAP服务器通信,另一端有自签名证书.
任何善良的灵魂,请指点我的一些说明来设置它?
为了使用 LDAP 保护 Reactive Spring Boot 应用程序,需要进行哪些自定义?到目前为止,我看到的示例都是基于 Spring MVC 的,而保护 WebFlux 的示例仅显示了一个带有内存映射的简单反应式示例。
spring-ldap ×10
java ×7
spring ×4
spring-boot ×3
ldap ×2
adam ×1
annotations ×1
reactive ×1
ssl ×1