繁体   English   中英

登录后保持相同的URL Spring安全性

[英]Keep same URL after login Spring security

我想在登录后留在同一页面上,但春季不得不让您重定向到defaultSuccessUrl我的代码是这样的

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
                .anyRequest()
                    .authenticated()
        .and()
            .formLogin()
                .loginPage("/login")
                    .defaultSuccessUrl("/index.html")
                    .failureUrl("/login?error=true")
                    .permitAll()
                    .and().logout().logoutSuccessUrl("/login?logout")
                    .and().exceptionHandling().accessDeniedPage("/pages/303.html");

    }

始终使用默认目标=“真”

这将迫使spring-security转到/index.html

我认为您应该添加一个身份验证成功处理程序

    @Override
protected void configure(HttpSecurity http) throws Exception {
   SavedRequestAwareAuthenticationSuccessHandler successHandler = new    SavedRequestAwareAuthenticationSuccessHandler();
   successHandler.setUseReferer(true);//redirect to the previous page
    http
        .csrf().disable()
        .authorizeRequests()
        .antMatchers("/css/**","/fonts/**","/js/**","/app/**","/images/**","/partials/**").permitAll()
            .anyRequest()
                .authenticated()
    .and()
        .formLogin()
            .loginPage("/login")
                .defaultSuccessUrl("/index.html")
                .failureUrl("/login?error=true")
                .permitAll()
                .successHandler(successHandler)//enable success handler
                .and().logout().logoutSuccessUrl("/login?logout")
                .and().exceptionHandling().accessDeniedPage("/pages/303.html");

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM