我正在创建一个Spring Boot应用程序,该应用程序只能由LDAP中的用户访问。此应用程序应该部署到Tomcat服务器(而不是嵌入式服务器)。对LDAP的配置在Tomcat本身做:通过Tomcat进行Spring Boot LDAP身份验证(预认证)
<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();
}
}
我知道我可以配置直接在应用程序(authenticationManagerBuilder.ldapAuthentication()...
)LDAP连接,但是这不是我想要的。
如何告诉Spring Boot使用来自Tomcat的LDAP身份验证进行应用程序?
UPDATE
它看起来像我不得不启用Pre-Authentication。这可以通过.and().jee().mappableRoles("ROLE_ADMIN")
完成。这似乎工作,但我仍然无法验证:No pre-authenticated principal found in request
。
我需要为Tomcats配置添加一些东西吗?