|
@ -40,16 +40,12 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private UserDetailServiceImpl userDetailService; |
|
|
private UserDetailServiceImpl userDetailService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private static BookStoreAccessDeniedHandler bookStoreAccessDeniedHandler; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
public void configureGlobal(AuthenticationManagerBuilder authManagerBuilder) |
|
|
public void configureGlobal(AuthenticationManagerBuilder authManagerBuilder) |
|
|
throws Exception { |
|
|
throws Exception { |
|
|
authManagerBuilder.userDetailsService(userDetailService); |
|
|
authManagerBuilder.userDetailsService(userDetailService); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Have different HTTP security policies for: |
|
|
* Have different HTTP security policies for: |
|
|
* |
|
|
* |
|
@ -70,9 +66,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
authorize -> authorize |
|
|
authorize -> authorize |
|
|
.anyRequest().hasAuthority("ADMIN") |
|
|
.anyRequest().hasAuthority("ADMIN") |
|
|
) |
|
|
) |
|
|
.httpBasic() |
|
|
|
|
|
|
|
|
.httpBasic() |
|
|
.and() |
|
|
.and() |
|
|
.csrf().disable() |
|
|
|
|
|
|
|
|
.csrf() |
|
|
|
|
|
.disable() |
|
|
; |
|
|
; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -89,9 +86,11 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception { |
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception { |
|
|
|
|
|
|
|
|
httpSecurity |
|
|
httpSecurity |
|
|
.authorizeRequests() |
|
|
.authorizeRequests() |
|
|
.antMatchers( |
|
|
.antMatchers( |
|
|
|
|
|
"/h2-console/**", |
|
|
"/", |
|
|
"/", |
|
|
"/booklist", |
|
|
"/booklist", |
|
|
"/error", |
|
|
"/error", |
|
@ -105,24 +104,27 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { |
|
|
.authenticated() |
|
|
.authenticated() |
|
|
.and() |
|
|
.and() |
|
|
.formLogin() |
|
|
.formLogin() |
|
|
// TODO do not expose /login URI end point (prevent direct access) |
|
|
|
|
|
.defaultSuccessUrl("/booklist") |
|
|
|
|
|
// .loginPage("/booklist") |
|
|
|
|
|
// .permitAll() |
|
|
|
|
|
|
|
|
.defaultSuccessUrl("/booklist") |
|
|
|
|
|
.permitAll() |
|
|
.and() |
|
|
.and() |
|
|
.logout() |
|
|
.logout() |
|
|
.logoutSuccessUrl("/booklist") |
|
|
.logoutSuccessUrl("/booklist") |
|
|
.permitAll() |
|
|
.permitAll() |
|
|
.invalidateHttpSession(true) |
|
|
.invalidateHttpSession(true) |
|
|
.clearAuthentication(true) |
|
|
.clearAuthentication(true) |
|
|
|
|
|
.deleteCookies("JSESSIONID") |
|
|
.and() |
|
|
.and() |
|
|
.exceptionHandling() |
|
|
.exceptionHandling() |
|
|
.accessDeniedHandler(bookStoreAccessDeniedHandler) |
|
|
|
|
|
|
|
|
.accessDeniedHandler(new BookStoreAccessDeniedHandler()) |
|
|
.and() |
|
|
.and() |
|
|
.csrf() |
|
|
.csrf() |
|
|
|
|
|
.ignoringAntMatchers("/h2-console/**") |
|
|
.and() |
|
|
.and() |
|
|
.sessionManagement() |
|
|
.sessionManagement() |
|
|
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) |
|
|
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED) |
|
|
|
|
|
.and() |
|
|
|
|
|
.headers() |
|
|
|
|
|
.frameOptions().sameOrigin() |
|
|
; |
|
|
; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|