Как я могу сделать это с помощью java-config в приложении Spring Boot с (встроенный Tomcat)?Я ожидал, что эти параметры будут декларативными и настраиваемыми в WebSecurityConfigurerAdapter, например:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/api/*").permitAll()
.antMatchers("/login*","/signin/**","/signup/**").permitAll()
.antMatchers("/USER/**").hasAnyRole("USER")
.formLogin()
// setSessionMaxInactiveInterval(60*60);
}
Но таких настроек нет?
Единственный способ, которым я могу это сделать, - это расширить настройки по умолчанию. SavedRequestAwareAuthenticationSuccessHandler (какое поведение довольно подходит для моего приложения) и программно добавьте туда необходимую логику:
@Slf4j
@Component
public class SessionSettingsHandler extends SavedRequestAwareAuthenticationSuccessHandler {
private static final int MAX_INACTIVE_INTERVAL = 60; // sec
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
super.onAuthenticationSuccess(request, response, authentication);
request.getSession().setMaxInactiveInterval(MAX_INACTIVE_INTERVAL);
log.debug("Session inactive interval: {}", MAX_INACTIVE_INTERVAL);
}
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/api/*").permitAll()
.antMatchers("/login*","/signin/**","/signup/**").permitAll()
.antMatchers("/USER/**").hasAnyRole("USER")
.formLogin()
.successHandler(sessionSettingsHandler);
}
Это работает, но я чувствую, что эти настройки должны существовать в Spring Boot?
Я также пытался установить application.properties: spring.session.timeout = 3600
Но Spring Security, похоже, просто игнорирует эти настройки.