Spring security 如果未经验证,如何恢复到zuul代理url上/登录到zuul代理url
我有两个spring boot应用程序,一个作为“网关”运行,以管理身份验证和路由(使用zuul代理),另一个作为网关后面的UI(“/admin”) 当我点击“/login”(或网关本身上的任何其他端点)时,我将被路由到“login.html”页面,然后我可以输入我的凭据并正确地进行身份验证。之后,我可以毫无问题地访问“/admin” 我的问题是,如果在进行身份验证之前点击“/admin”,我不会被路由到“/login.html”,而只会得到“basic auth”弹出窗口,要求提供凭据,这是我不想要的 这是我在网关服务器上的配置Spring security 如果未经验证,如何恢复到zuul代理url上/登录到zuul代理url,spring-security,spring-boot,netflix-zuul,Spring Security,Spring Boot,Netflix Zuul,我有两个spring boot应用程序,一个作为“网关”运行,以管理身份验证和路由(使用zuul代理),另一个作为网关后面的UI(“/admin”) 当我点击“/login”(或网关本身上的任何其他端点)时,我将被路由到“login.html”页面,然后我可以输入我的凭据并正确地进行身份验证。之后,我可以毫无问题地访问“/admin” 我的问题是,如果在进行身份验证之前点击“/admin”,我不会被路由到“/login.html”,而只会得到“basic auth”弹出窗口,要求提供凭据,这是我
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.sessionManagement()
.maximumSessions(1)
.expiredUrl("/login")
.maxSessionsPreventsLogin(false)
.sessionRegistry(sessionRegistry())
.and()
.sessionCreationPolicy( SessionCreationPolicy.ALWAYS)
.invalidSessionUrl( "/login" );
http.addFilterBefore(new ApiKeyAuthenticationFilter(macSigner()), BasicAuthenticationFilter.class);
http.httpBasic().and()
.authorizeRequests()
.antMatchers("/", "/home", "/index","/support.html", "/about.html","/features.html","/fonts/**","/ws/**",
"/contacts.html","/img/**","/logos/**","/docs/**").permitAll()
.antMatchers("/admin**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.csrf().ignoringAntMatchers("/resource/api/**","/api/**").csrfTokenRepository(csrfTokenRepository())
.and()
.addFilterAfter(csrfHeaderFilter(), SessionManagementFilter.class)
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login")
.permitAll();
}
这是我的管理服务器上的配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and().authorizeRequests().anyRequest().authenticated();
http.csrf().disable();
}
有谁能给我一些关于在哪里挖掘的建议吗?尝试使用authenticationEntryPoint和LoginUrauThenticationEntryPoint 比如说
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.httpBasic().and().exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).and()
.logout().and()
.authorizeRequests()
.antMatchers("/index.html", "/login", "/").permitAll()
.anyRequest().authenticated()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// @formatter:on
}
@RequestMapping("/login")
public String login() {
return "forward:/";
}