我正在使用 Spring Security 和基于 Java 的 @Configuration 构建一个应用程序。我们的 JBoss EAP 6 服务器配置了一个在 jboss-web.xml 文件中定义的安全域。
jboss-web.xml
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 4.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
<security-domain>ldapcomponent</security-domain>
</jboss-web>
有没有办法在我的 Spring Security WebSecurityConfigurerAdapter 中使用这个安全域?
Spring Security Java 配置
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.?????
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated()
.anyRequest().hasRole("my-required-role").and().httpBasic();
}
}
最佳答案
JBoss 身份验证需要
org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider
可以通过以下方法添加:
auth.authenticationProvider(...);
除此之外
org.springframework.security.web.authentication.preauth.j2ee.J2eePreAuthenticatedProcessingFilter
应该注册。
关于使用 JBoss <安全域> 的 Spring Security,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28172056/