2016-06-29 4 views
2

私のJava Spring SecurityにexpiredUrl(" ")機能を設定したいと思います。
私は方法を以下にしようとした私の同時セッションの取得が
の有効期限が切れたときにHTMLページを表示する: -Spring Security - sessionManagementのexpiredUrlにHTMLページを表示

JAVA

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

私のコンテキストパスがlocalhost:8080/context_path しかし
として設定され、私はないですexpiredUrlコールでsession_expired.htmlページを表示する方法を取得する
JS側でangularJsを使用しています
Pl私はexpiredUrlコール

にHTMLページを表示するのに役立つ緩和、私はのJsの助けを借りてみました場合は、私のコードは次のとおりです。 -

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"); 
    }); 
}); 
ここ

セッションのgetは、それがリンクlocalhost:8080/context_path/session_expired#/landing...
に行くだろうが、私はそう案内してください、私はexpiredUrl
に直接HTMLページを表示するリンク
localhost:8080/context_path/#/session_expired

OR

に行きたい期限切れ私にこれを行う方法。

+0

あなたはこのhttp://stackoverflow.com/questions/2070179/how-to-check-session-has-been-expiredようにStackOverflowから何かを試してみました-in-java?あなたのページに転送するだけですか?または、フィルタを作成して確認して(リダイレクトする)たぶんここhttp://stackoverflow.com/questions/1026846/how-to-redirect-to-login-page-when-session-is-expired-in-java-web-application – Hrabosch

答えて

0

この構成では、私のために働いている:

@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"); 
    } 
+0

はい、HTMLページを表示したいセッションが期限切れになったので、セッションが 'localhost:8080/context_path/session_expired#/ ...'のようになりました。これは 'localhost:8080/context_path /#/ session_expired'にリダイレクトしたいのですが、 ** OR **私は 'expiredUrl'のhtmlページを返したいと思います –

+0

私の例では、セッションが終了したときにログインページにリダイレクトされます。 – FuSsA

+0

と'/Access_Denied'とは何ですか?それはどんなリンクですか? –