簡體   English   中英

Spring 授權 http 安全重定向,session 問題

[英]Spring autherization http security redirection, session issue

我正在使用 Spring http security(Enablewebsecurity) 來管理會話。 但我面臨的問題是,每當我啟動應用程序時,應用程序總是打開主頁而不是登錄頁面。 這里的要求是如果 session 出來了,需要到 go 登錄頁面。 session 也需要超時 30 分鍾。 下面的代碼有什么問題嗎,

http
            .authorizeRequests()
                .antMatchers("/", "/home").permitAll()
                .anyRequest().authenticated()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .permitAll();

public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/").setViewName("home");
        registry.addViewController("/login").setViewName("login");
    }

嘗試在 antmatcher 之后 remove.permitAll() 並重試

對於添加 session 管理,

 http
        .authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
         .sessionManagement()
            .invalidSessionUrl("/invalidSession.html")
            .and()
        .logout()
            .permitAll();

在應用程序屬性中,您需要添加 session 超時。

 server.servlet.session.timeout=30m

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM