いつもお世話になっております。
Springsecurityのログイン失敗時の画面遷移について質問があります。
Springsecurityのjavaconfigファイル(SecurityConfig.java)でログインについての設定をしております。
java
1//SecurityConfig.java 2package com.tuyano.springboot.springsecurity; 3 4import org.springframework.context.annotation.Bean; 5import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 6import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 11import javax.sql.DataSource; 12 13import org.springframework.beans.factory.annotation.Autowired; 14import org.springframework.beans.factory.annotation.Qualifier; 15 16 17 18@EnableWebSecurity 19public class SecurityConfig extends WebSecurityConfigurerAdapter{ 20 @Autowired 21 private DataSource dataSource; 22 23 private static final String USER_QUERY="select name, password, 1 from Newaccount where name = ?"; 24 private static final 25 String ROLES_QUERY="select username, authority from AUTHORITIES where username = ?"; 26 27 @Override 28 protected void configure(HttpSecurity http) throws Exception{ 29 http 30 .authorizeRequests() 31 .antMatchers("/First.html").permitAll() 32 .antMatchers("/templates/**").hasAnyAuthority("ROLE_ADMIN") 33 .anyRequest().authenticated() 34 .and() 35 .formLogin() 36 .loginPage("/First.html") 37 .loginProcessingUrl("/processLogin") 38 .defaultSuccessUrl("/sucess.html") 39 .failureUrl("/failure.html") 40 .usernameParameter("name") 41 .passwordParameter("password") 42 .and() 43 .logout() 44 .logoutUrl("/processLogout") 45 .logoutSuccessUrl("/First") 46 .and() 47 .csrf() 48 .disable(); 49 50 } 51 @Override 52 public void configure(AuthenticationManagerBuilder auth) throws Exception { 53 auth.jdbcAuthentication() 54 .dataSource(dataSource) 55 .usersByUsernameQuery(USER_QUERY) 56 .authoritiesByUsernameQuery(ROLES_QUERY); 57 //passwordEncoder(new BCryptPasswordEncoder()); 58 //.authoritiesByUsernameQuery( 59 // "select mail_address, role from accounts where mail_address = ?"); 60 } 61 62 63} 64
.failureUrl("/failure.html")でログイン失敗時は("/failure.html")に画面遷移するようにしているのですが、初期表示画面である/First.htmlに画面遷移してしまいます。
これはSpringsecurityの初期設定上、ログイン失敗時は初期表示画面である/First.htmlに画面遷移するようになっているということでしょうか?
それとも、私の実装上どこか誤っている箇所があり、画面遷移が正常にできていないのでしょうか。
ご回答のほど宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/11 07:19