2017-09-12 9 views
0

Webアプリケーションを更新して、特定のページにしかアクセスできない新しいユーザーロールを追加しています。このアップデートの前に、ユーザがログインしてセッションが切れ、ページが更新されたときはいつでも、ログイン画面が表示されます。これで、ログインしていないためにデータをロードできないため、NULLポインタ例外を引き起こすページをロードしようとします。ここで Spring MVC - ログインしていない場合にログインにリダイレクトする方法

は、私は知らない私は、私がログインページにリダイレクトするために、このXML設定を使用していた

http.csrf().ignoringAntMatchers("/notification/**"); 
    http.csrf().ignoringAntMatchers("/embed/**/apply"); 
    http.csrf().ignoringAntMatchers("/view/**/apply"); 
    http.csrf().ignoringAntMatchers("/login"); 
    http.csrf().ignoringAntMatchers("/logout"); 
    http.csrf().ignoringAntMatchers("/register"); 

    http.authorizeRequests() 

      .antMatchers("/").permitAll() 
      .antMatchers("/index").permitAll() 
      .antMatchers("/static/**").permitAll() 
      .antMatchers("/assets/**").permitAll() 
      .antMatchers("/register").permitAll() 
      .antMatchers("/skillRequest/**").permitAll() 
      .antMatchers("/skillRequest/skillFormUpdate/**").permitAll() 
      .antMatchers("/password/reset").permitAll() 
      .antMatchers("/password/reset/complete").permitAll() 
      .antMatchers("/email/verify").permitAll() 
      .antMatchers("/view/**").permitAll() 
      .antMatchers("/embed/**").permitAll() 
      .antMatchers("/dashboard").fullyAuthenticated() 
      .antMatchers("/profile").fullyAuthenticated() 
      .antMatchers("/candidate-profile/**").fullyAuthenticated() 
      .antMatchers("/users.json").fullyAuthenticated() 
      .antMatchers("/candidate/**/add").fullyAuthenticated() 
      .antMatchers("/candidate/**/edit").fullyAuthenticated() 
      .antMatchers("/**").not().hasAnyAuthority("ROLE_CANDIDATE") 
      .anyRequest().authenticated() 
      .and() 
      .formLogin() 
      .loginPage("/login") 
      .defaultSuccessUrl("/dashboard", false) //Force user to always go to the home page. 
      //.successHandler(successHandler()) 
      .permitAll() 
      .and() 
      .httpBasic() 
      .and() 
      .logout() 
      .permitAll(); 

答えて

0

に取り組んできた私の設定、

<security:session-management invalid-session-url="/login" session-authentication-error-url="/login" session-fixation-protection="newSession"> 
      <security:concurrency-control error-if-maximum-exceeded="true" max-sessions="1" expired-url="/login"/> 
     </security:session-management> 
+0

これは何のXML設定ですか? web.xml? – Dylan

+0

設定クラスに同じ設定を追加できるはずです – Bala

0

あり、そして多分それが聞こえます愚かな、これはあなたが探している答えであれば、私はまた、春のブートに比較的新しいと春のMVCに新しいですが、私が知っている限り、それは多分大きなプロジェクトには適用されません非常に簡単なソリューションです:

アクセス制限なしのすべてのページについては
  1. 、それが制限されたページにリダイレクトし、それらの機能について
  2. をログインするリダイレクト意味がない、私はちょうど注釈@PreAuthorize(「hasAnyRole( 『ADMINを』)」)、追加しました@PreAuthorize(「hasAnyRole( 'ADMIN、USER')」)または@PreAuthorize(「hasAnyRole( 'USER')」)は、ページにアクセスできるロールに応じて異なります。

認証機構と一緒に、これはあなたが求めたものとまったく同じです。

関連する問題