Java Spring身份验证http安全重定向,会话问题

Java Spring身份验证http安全重定向,会话问题,java,spring,spring-boot,Java,Spring,Spring Boot,我正在使用SpringHTTP安全性(Enablewebsecurity)来管理会话。 但我面临的问题是,每当我启动应用程序时,应用程序总是打开主页,而不是登录页面。这里的要求是,如果会话已结束,则需要转到登录页面。 此外,会话需要暂停30分钟。下面的代码有什么错误吗 http .authorizeRequests() .antMatchers("/", "/home").permitAll()

我正在使用SpringHTTP安全性(Enablewebsecurity)来管理会话。 但我面临的问题是,每当我启动应用程序时,应用程序总是打开主页,而不是登录页面。这里的要求是,如果会话已结束,则需要转到登录页面。 此外,会话需要暂停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后的.permitAll(),然后重试

尝试删除antmatcher后的.permitAll(),然后重试

以添加会话管理

 http
        .authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
         .sessionManagement()
            .invalidSessionUrl("/invalidSession.html")
            .and()
        .logout()
            .permitAll();
在应用程序属性中,需要添加会话超时

 server.servlet.session.timeout=30m

要添加会话管理

 http
        .authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
         .sessionManagement()
            .invalidSessionUrl("/invalidSession.html")
            .and()
        .logout()
            .permitAll();
在应用程序属性中,需要添加会话超时

 server.servlet.session.timeout=30m

谢谢会话管理符合我的要求。是否仍要在30米后自动重定向?在.invalidSessionUrl(“/登录”)中添加登录URL,它将在30分钟后重定向到登录映射,但页面保持不变。单击“刷新”后,只有它将重定向到登录页面。谢谢。会话管理符合我的要求。是否在30分钟后自动重定向?在.invalidSessionUrl(“/登录”)中添加登录URL,它将在30分钟后重定向到登录映射,但这一页仍然是同一页。单击“刷新”后,只有它重定向到登录页面。