【问题标题】:How can I do an SSO to REST API with Spring security?如何使用 Spring 安全性对 REST API 进行 SSO?
【发布时间】: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


    【解决方案1】:

    显然我遇到了上下文问题,这在没有身份验证管理器配置的情况下有效

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 2017-12-05
      • 1970-01-01
      • 2014-04-27
      • 2016-01-24
      • 2023-03-31
      • 2016-03-22
      • 2014-08-07
      • 2015-05-22
      相关资源
      最近更新 更多