我通过以下方式使用Spring LDAP身份验证:
auth
.ldapAuthentication()
.userSearchFilter("userPrincipalName={0}")
.contextSource()
.managerDn(ldapAuthenticationConfig.getManagerDn())
.managerPassword(ldapAuthenticationConfig.getManagerPassword())
.url(ldapAuthenticationConfig.getUrl());然而,当LDAP服务器不可用时,它在登录页面上花费了太多时间。我想知道我是否可以在相当长的时间内登录。
下面是我使用的依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>如何在Spring Boot中设置LDAP身份验证的超时值?
发布于 2018-02-27 18:42:57
我也遇到了这个问题,并找到了几个指出com.sun.jndi.ldap.connect.timeout环境变量的答案,但无法找到如何使用Java Config添加到Spring Security中。
为此,首先提取上下文源的创建:
@Autowired
private DefaultSpringSecurityContextSource context;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder
.ldapAuthentication()
.userSearchFilter(LDAP_USER_SEARCH_FILTER)
.contextSource(context);
}然后,在创建上下文源时(我是在相同的配置类中创建的,没有构建器),您可以指定环境属性,并且可以在其中添加timeout属性:
@Bean
public DefaultSpringSecurityContextSource createContext() {
DefaultSpringSecurityContextSource contextSource = new DefaultSpringSecurityContextSource(LDAP_SERVER);
contextSource.setUserDn(LDAP_MANAGER_DN);
contextSource.setPassword(LDAP_MANAGER_PASSWORD);
Map<String, Object> environment = new HashMap<>();
environment.put("com.sun.jndi.ldap.connect.timeout", LDAP_TIMEOUT);
contextSource.setBaseEnvironmentProperties(environment);
return contextSource;
}注意,在我的LDAP_类中,大写的config变量都是常量。
发布于 2019-10-25 17:57:03
适用于使用.yml或.properties文件的用户
ldap:
urls: LDAP://[YOUR FAKE DOMAIN OR IP]
base: dc=fakedomain,dc=com
username: [AD_USER_NAME]
password: [AD_USER_PASSWORD]
base-environment:
com.sun.jndi.ldap.connect.timeout: 500我把com.sun.jndi.ldap.connect.timeout: 500放在spring.ldap.base-enviroment里
注意:我使用的是spring
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>https://stackoverflow.com/questions/42517398
复制相似问题