【发布时间】:2018-04-06 12:38:57
【问题描述】:
尝试使用 apache 实现 sso。在 apache 中添加 auth 并通过 ajp 在 Spring Boot 应用程序 httpServletRequest.getRemoteUser() 中设置用户名。
一旦将 spring 安全依赖添加到启动项目中,就无法从 httpRequest 获取远程用户。
@GetMapping("/sso")
public String test(HttpServletRequest request, @RequestHeader Map<String, String> headers) {
String u1 = request.getRemoteUser();
return "--" + u1 + "--" + headers.toString();
}
u1 给出未添加 spring 安全依赖时从 Apache 发送的用户名
在 spring 安全配置中允许所有请求
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
在 Apache 中,通过命令添加了一个用户,并在虚拟主机中添加了以下几行以进行身份验证
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
【问题讨论】:
标签: spring-boot spring-security