@RequestMapping("/login")
public void login() {
}
// 로그인 실패처리
@GetMapping("/login?error")
public String fail() throws IOException{
return "redirect:/?error";
}
본인의 경우 다음과 같이 Controller를 구성하였습니다.
Spring Security Config **
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().formLogin().loginPage("/")
.loginProcessingUrl("/login").permitAll()
.failureUrl("/?error") // default
.usernameParameter("username")
.passwordParameter("password")
.permitAll()
.defaultSuccessUrl("/admin/home")
}
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
final String usernameQuery = "select mid as username,mpw as password,enabled from {Member테이블 이름} where mid=?";
final String authQuery = "select a.mid as username,b.role_name as authority from {Member테이블 이름} as a , {MemberRole 테이블 이름} as b where a.id=b.mem_no and a.mid=?";
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(usernameQuery)
.authoritiesByUsernameQuery(authQuery)
.passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
URL에 대한 권한을 설정할 때 hasRole("{권한}") 함수를 사용하게 되는데 이때, {권한}에는 ADMIN,MEMBER 등등이 사용됩니다.