Spring Security - display HTML page on expiredUrl

2019-07-19 04:42发布

问题:

I want to configure expiredUrl(" ") feature in my java spring security.
I want to display HTML page when my concurrent session get expired
I tried in following way:-

JAVA

@Override
public void configure(HttpSecurity http) throws Exception {
    http
            .sessionManagement()
            .sessionFixation()
            .changeSessionId()
            .maximumSessions(1)
            .expiredUrl("/session_expired.html")
}

My context path set as localhost:8080/context_path but
I am not getting how to display session_expired.html page on expiredUrl call
I am using angularJs on Js side
Please help me to display Html page on expiredUrl call

AND

If I tried with the help of Js then my code is:-

JAVA

@Override
public void configure(HttpSecurity http) throws Exception {
    http
            .sessionManagement()
            .sessionFixation()
            .changeSessionId()
            .maximumSessions(1)
            .expiredUrl("/access/session_expired")
}

ANGULARJS

$stateProvider.state('session_expired', {
     'url': '/session_expired',
     'templateUrl': '/session_expired.html',
     'controller': 'SessionExpiredController'
})

.factory('SessionService', function ($resource, restRoot, contextPath) {
return $resource({
    'session_expired': {
        'url': contextPath + '/access/session_expired'
    },
})

.controller('SessionExpiredController', function (SessionService, $state) {
     SessionService.session_expired(function () {
         $state.go("session_expired");
     });
 });

here when session get expired it will goes on link localhost:8080/context_path/session_expired#/landing...
but I want to go on link
localhost:8080/context_path/#/session_expired

OR

I want to display direct HTML page on expiredUrl
so please guide me how to do this.

回答1:

This configuration is working for me:

 @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/", "/list")
                .access("hasRole('USER') or hasRole('ADMIN') or hasRole('DBA')")
                .antMatchers("/newuser/**", "/delete-user-*").access("hasRole('ADMIN')").antMatchers("/edit-user-*")
                .access("hasRole('ADMIN') or hasRole('DBA')").and().formLogin().loginPage("/login")
                .loginProcessingUrl("/login").usernameParameter("ssoId").passwordParameter("password").and()
                .rememberMe().rememberMeParameter("remember-me").tokenRepository(tokenRepository)
                .tokenValiditySeconds(86400).and().csrf().and().exceptionHandling().accessDeniedPage("/Access_Denied");
    }