In my case, my app runs on Tomcat server, application.properties set did not work.
This one works:
@Component
public class SavedRequestAwareAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException {
SavedRequest savedRequest = requestCache.getRequest(request, response);
String userRole = authentication.getAuthorities().stream().findFirst().get().getAuthority();
//see here timeout duration set
request.getSession().setMaxInactiveInterval(3600);
List<String> permissions = new ArrayList<>();
...
}
and set it to security configure method's
.successHandler()
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private SavedRequestAwareAuthenticationSuccessHandler successHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/rest/api/**", "/logout")
.authenticated()
.and()
.cors()
.configurationSource(corsConfigurationSource())
.and()
.formLogin()
.failureHandler(new SimpleUrlAuthenticationFailureHandler())
.successHandler(successHandler)
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout", HttpMethod.POST.toString()))
.clearAuthentication(true)
.invalidateHttpSession(true)
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler())
.and()
.exceptionHandling()
.authenticationEntryPoint(restAuthenticationEntryPoint)
.and()
.csrf()
.disable();
}
server.*
properties will only work if you use the embedded container. If you are deploying to Tomcat those won't work as Spring Boot isn't controlling the container. – Athleticsweb.xml
orweb-fragment.xml
and set the session timeout in that way just as you regularly would do. – Athleticsweb.xml
in spring boot project ? In resource folder ? – WordenWEB-INF
folder. It is a regular WAR you are deploying, there is no magic in there. – Athletics