【发布时间】:2017-07-30 13:07:01
【问题描述】:
我正在创建一个 Spring Boot 应用程序,它应该只能由 LDAP 中的用户访问。此应用程序应部署到 Tomcat 服务器(而不是嵌入式服务器)。 LDAP 的配置是在 Tomcat 本身中完成的:
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Realm className="org.apache.catalina.realm.JNDIRealm"
connectionURL="ldap://someldapserver:389"
userPattern="uid={0},dc=example,dc=com"
roleBase="dc=example,dc=com"
roleName="cn"
roleSearch="(uniqueMember={0})"/>
</Realm>
如果我尝试访问 Tomcat 管理器,我可以使用 LDAP 凭据进行身份验证,因此连接基本上可以正常工作。
这是我的配置:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/test").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll()
.and()
.logout().permitAll()
.and()
.csrf().disable();
}
}
我知道我可以直接在应用程序中配置 LDAP 连接 (authenticationManagerBuilder.ldapAuthentication()...),但这不是我想要的。
我如何告诉 Spring Boot 使用来自 Tomcat 的 LDAP 身份验证来进行应用程序?
更新
看来我必须启用Pre-Authentication。这可以通过.and().jee().mappableRoles("ROLE_ADMIN") 完成。这似乎可行,但我仍然无法验证:No pre-authenticated principal found in request。
我必须在 Tomcats 配置中添加一些东西吗?
【问题讨论】:
标签: tomcat authentication spring-boot spring-security ldap