質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

0回答

3842閲覧

Spring SecurityのsessionFixationの設定が反映されない

koronatail

総合スコア433

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring

Spring Framework は、Javaプラットフォーム向けのオープンソースアプリケーションフレームワークです。 Java Platform上に、 Web ベースのアプリケーションを設計するための拡張機能が数多く用意されています。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

1クリップ

投稿2016/10/17 09:54

編集2016/10/18 05:41

###前提・実現したいこと
Spring Boot+Spring Securityで独自認証処理を実装したのですが、WebSecurityConfigurerAdapterを継承した設定用クラスで設定した内容が反映されませんでした。

###試したこと
内容的には以下のURLに乗っている現象と同じだと思ったのですが、principalにあたるDTOにhashCodeとequalsを実装しても現象が変わりませんでした。
http://stackoverflow.com/questions/37090378/custom-authenticationprovider-ignore-sessionmanagement

###該当のソースコード
長くなってしまいますが設定クラス・プリンシパル・独自認証処理部分を載せます。
####WebSecurityConfig
sessionManagement().sessionFixation().newSession()の部分が反映されません。
セッションIDが変わらないことを確認しました。
SessionFixationProtectionEventも拾えませんでした。

java

1@Configuration 2@EnableWebSecurity 3@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) 4public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 5 @Autowired 6 private AuthenticationProviderImpl authenticationProvider; 7 8 @Override 9 protected void configure(final HttpSecurity pHttp) throws Exception { 10 pHttp 11 .authorizeRequests() 12 .antMatchers("/hoge","/fuga").permitAll() 13 .anyRequest().fullyAuthenticated() 14 .and().formLogin() 15 .loginPage("/") 16 .loginProcessingUrl("/login") 17 .defaultSuccessUrl("/hogehoge") 18 .usernameParameter("id") 19 .passwordParameter("pw") 20 .failureUrl("/hogefailure").permitAll() 21 .and().sessionManagement()//これらの設定が反映されない 22 .sessionFixation()//これらの設定が反映されない 23 .newSession()//これらの設定が反映されない 24 .and().logout() 25 .addLogoutHandler(customLogoutHandler()) 26 .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 27 .logoutSuccessUrl("/hogesuccess") 28 .deleteCookies("JSESSIONID") 29 .invalidateHttpSession(true).permitAll() 30 .and().addFilterBefore(idPassAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) 31 ; 32 } 33 34 35 @Bean 36 //Bean色々省略 37 38 @Autowired 39 public void configureGlobal(AuthenticationManagerBuilder pAuth) { 40 pAuth 41 .authenticationProvider(authenticationProvider) 42 .authenticationEventPublisher(defaultAuthenticationEventPublisher(); 43 } 44}

####LoginInfoDto.java(プリンシパルにあたるもの)

java

1public class LoginInfoDTO extends User { 2 private int userId; 3 private String loginId; 4 private String password; 5 private String name; 6 private LocalDateTime currentLoginTime; 7 private String locationCd; 8 private String locationGrpCd; 9 10 //ゲッターセッター省略 11 12 @Override 13 public int hashCode() { 14 final int prime = 31; 15 int result = super.hashCode(); 16 result = prime * result + ((currentLoginTime == null) ? 0 : currentLoginTime.hashCode()); 17 result = prime * result + ((locationCd == null) ? 0 : locationCd.hashCode()); 18 result = prime * result + ((locationGrpCd == null) ? 0 : locationGrpCd.hashCode()); 19 result = prime * result + ((loginId == null) ? 0 : loginId.hashCode()); 20 result = prime * result + ((name == null) ? 0 : name.hashCode()); 21 result = prime * result + ((password == null) ? 0 : password.hashCode()); 22 result = prime * result + userId; 23 return result; 24 } 25 26 @Override 27 public boolean equals(Object obj) { 28 if (this == obj) 29 return true; 30 if (!super.equals(obj)) 31 return false; 32 if (getClass() != obj.getClass()) 33 return false; 34 LoginInfoDTO other = (LoginInfoDTO) obj; 35 if (currentLoginTime == null) { 36 if (other.currentLoginTime != null) 37 return false; 38 } else if (!currentLoginTime.equals(other.currentLoginTime)) 39 return false; 40 if (locationCd == null) { 41 if (other.locationCd != null) 42 return false; 43 } else if (!locationCd.equals(other.locationCd)) 44 return false; 45 if (locationGrpCd == null) { 46 if (other.locationGrpCd != null) 47 return false; 48 } else if (!locationGrpCd.equals(other.locationGrpCd)) 49 return false; 50 if (loginId == null) { 51 if (other.loginId != null) 52 return false; 53 } else if (!loginId.equals(other.loginId)) 54 return false; 55 if (name == null) { 56 if (other.name != null) 57 return false; 58 } else if (!name.equals(other.name)) 59 return false; 60 if (password == null) { 61 if (other.password != null) 62 return false; 63 } else if (!password.equals(other.password)) 64 return false; 65 if (userId != other.userId) 66 return false; 67 return true; 68 } 69 70}

####AuthenticationProviderImpl.java

java

1@Component 2public class AuthenticationProviderImpl implements AuthenticationProvider { 3 @Autowired 4 private UserMstDao userMstDao; 5 6 /** 7 * 独自認証処理. 8 */ 9 @Override 10 public Authentication authenticate(final Authentication pAuth){ 11 12 try { 13 //独自認証処理省略 14 return new UsernamePasswordAuthenticationToken(new LoginInfoDTO(user), 15 inputPassword.getString(), pAuth.getAuthorities()); 16 } catch (AuthenticationCredentialsNotFoundException pE) { 17 18 pE.printStackTrace(); 19 throw pE; 20 } 21 } 22 @Override 23 public boolean supports(final Class<?> pToken) { 24 25 return UsernamePasswordAuthenticationToken.class.isAssignableFrom(pToken); 26 } 27 28 @Override 29 public int hashCode() { 30 final int prime = 31; 31 int result = 1; 32 result = prime * result + ((userMstDao == null) ? 0 : userMstDao.hashCode()); 33 return result; 34 } 35 36 @Override 37 public boolean equals(Object obj) { 38 if (this == obj) 39 return true; 40 if (obj == null) 41 return false; 42 if (getClass() != obj.getClass()) 43 return false; 44 AuthenticationProviderImpl other = (AuthenticationProviderImpl) obj; 45 if (userMstDao == null) { 46 if (other.userMstDao != null) 47 return false; 48 } else if (!userMstDao.equals(other.userMstDao)) 49 return false; 50 return true; 51 } 52}

###補足情報(言語/FW/ツール等のバージョンなど)
Spring Bootのバージョンは1.3.6になります

長くなってしまいましたがどうかよろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問