簡體   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