【发布时间】:2016-06-22 17:06:40
【问题描述】:
我有一个由 NGINX 服务器、前端服务器和后端服务器组成的应用程序。
NGINX 和前端处理登录(我现在必须使用一些遗留代码),并且成功完成。
我需要使用 Spring Security 对 RESTfull API 执行 SSO。 该 API 在嵌入式 tomcat 8 服务器上的 Spring-boot 应用程序中运行。
spring-security版本是4.0.3,spring-boot版本是1.3.3。
我开始:
@Configuration
@EnableWebSecurity()
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().permitAll();
}
}
现在我从 API 得到 401(未经授权),查看遗留代码并咨询其他开发人员(我是该组织的新手),我可以看到在使用他们使用的 XML 配置时:
<authentication-manager alias="authenticationManager"/>
所以身份验证管理器只是通过请求(他们在过滤器中进行其余的验证)。
我想做类似的事情,或者在这个阶段添加对标题中存在的数据的验证,但是我找不到一个明确的文档,它不适用于 XML 配置。
我认为这可能相当于遗留系统中使用的 XML 代码,但它不起作用:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.parentAuthenticationManager(authentication -> {
authentication.setAuthenticated(true);
return authentication;
});
}
我正在寻找对我的想法的更正,或替代方法。
【问题讨论】:
标签: spring-security spring-boot spring-4