【发布时间】:2023-04-08 20:30:01
【问题描述】:
我对 Spring Boot 很陌生,我正在尝试在我的应用程序中使用 Spring Boot 来实现 Spring Security 和会话管理。
我的问题如下
如何在不登录应用程序的情况下限制从静态文件夹直接访问页面? 示例:localhost:8080/view/pages/blank.html
是否需要添加任何额外的配置来实现会话管理?另外如何识别特定登录用户是否创建了会话?
我使用的 Spring Security 版本是 1.5.3.RELEASE。谁能告诉我如何实现弹簧安全规则和会话管理。在此先感谢您的帮助
以下是我在扩展 WebSecurityConfigurerAdapter 的安全配置类中添加的代码
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.authorizeRequests()
.antMatchers("/login")
.permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/homePage")
.defaultSuccessUrl("/homePage")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login")
.permitAll()
.and()
.sessionManagement()
.maximumSessions( 1 )
.expiredUrl( "/sessionExpired" )
.maxSessionsPreventsLogin( true )
.and()
.sessionCreationPolicy( SessionCreationPolicy.IF_REQUIRED );
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.userDetailsService(userDetailsService);
}
}
【问题讨论】:
-
请提问。还要描述你的代码的结果是什么(可能需要输出)
-
我已经修改了我的问题,请看一下
标签: spring-mvc session spring-boot spring-security