为了使用 Netflix 堆栈,我进行了此设置:
- 尤里卡服务器
- 一个模块,通过 Zuul 代理暴露给外界(注册到 Eureka)
- 多个后端微服务(注册到Eureka)
我的问题是,当我第二次/第三次调用代理中的 URL(要重定向到微服务)时,经过身份验证的主体丢失了。
这些是日志条目:
09:14:31.300 INFO 8720 --- [nio-8080-exec-7] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Mon Sep 14 09:14:31 CEST 2015, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={message=Access is denied, type=org.springframework.security.access.AccessDeniedException}]
09:14:33.387 INFO 8720 --- [io-8080-exec-10] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Mon Sep 14 09:14:33 CEST 2015, principal=eadmin, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@fffde5d4: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: DE9DEDCB6A809133C54ABC3403A46B38}]
09:14:33.387 INFO 8720 --- [io-8080-exec-10] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Mon Sep 14 09:14:33 CEST 2015, principal=eadmin, type=AUTHENTICATION_SUCCESS, data={details=org.springframework.security.web.authentication.WebAuthenticationDetails@fffde5d4: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: DE9DEDCB6A809133C54ABC3403A46B38}]
09:14:35.407 INFO 8720 --- [nio-8080-exec-1] o.s.c.n.zuul.filters.ProxyRouteLocator : Finding route for path: /userregistryservice/user-registry/getAllRoles
09:23:40.119 INFO 8720 --- [nio-8080-exec-2] o.s.c.n.zuul.filters.ProxyRouteLocator : Finding route for path: /userregistryservice/user-registry/getAllRoles
09:24:06.689 INFO 8720 --- [nio-8080-exec-3] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=Mon Sep 14 09:24:06 CEST 2015, principal=anonymousUser, type=AUTHORIZATION_FAILURE, data={message=Access is denied, type=org.springframework.security.access.AccessDeniedException}]
我已经实现了一个 Zuul 代理,我将主体传递给要重定向的请求标头,但是当第二次发送请求时,不会调用此过滤器(Spring Security 捕获请求,因为它是匿名请求)。
关于这里发生了什么的任何想法?
谢谢
编辑:使用 Fiddler 进行调查,我发现在两次成功请求后,被拒绝的请求会用 HTTP 302 代码回答:
编辑#2:这是我的 Spring 启动安全配置
@Autowired
private RequestHeaderAuthenticationFilter siteminderFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.anonymous().and().addFilter(siteminderFilter)
.authorizeRequests()
.antMatchers("/authfallback/**", "/access_requests.css")
.permitAll()
.antMatchers("/auth/**")
.fullyAuthenticated()
.antMatchers("/**/metrics")
.hasAnyRole("SYSTEM", "ADMIN")
.antMatchers("/logs")
.hasAnyRole("SYSTEM", "ADMIN")
.antMatchers("/user-registry/**")
.hasAnyRole("SYSTEM", "ADMIN")
.antMatchers("/AdminTools/**", "/api-docs")
.hasAnyRole("ADMIN")
.antMatchers("/sdoc.jsp", "o2c.html")
.denyAll()
.antMatchers("/**")
.hasAnyRole("SYSTEM", "ENGINEERING", "CUSTOMER", "EXECUTIVE", "ADMIN").and().formLogin()
.loginPage("/authfallback/login").defaultSuccessUrl("/index.html", false)
.permitAll().and().logout()
.invalidateHttpSession(true).logoutUrl("/logout").logoutSuccessHandler(wamLogoutHandler).and()
.exceptionHandling().accessDeniedPage("/auth/authorizationrequest").and().csrf().disable();
// @formatter:on
}