|
1 | 1 | package com.codingapi.springboot.security;
|
2 | 2 |
|
3 | 3 | import com.codingapi.springboot.security.configurer.HttpSecurityConfigurer;
|
4 |
| -import com.codingapi.springboot.security.filter.MyAccessDeniedHandler; |
5 |
| -import com.codingapi.springboot.security.filter.MyLogoutHandler; |
6 |
| -import com.codingapi.springboot.security.filter.MyLogoutSuccessHandler; |
7 |
| -import com.codingapi.springboot.security.filter.MyUnAuthenticationEntryPoint; |
| 4 | +import com.codingapi.springboot.security.dto.request.LoginRequest; |
| 5 | +import com.codingapi.springboot.security.filter.*; |
8 | 6 | import com.codingapi.springboot.security.handler.ServletExceptionHandler;
|
9 | 7 | import com.codingapi.springboot.security.jwt.Jwt;
|
10 | 8 | import com.codingapi.springboot.security.properties.SecurityJwtProperties;
|
|
27 | 25 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
28 | 26 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
29 | 27 |
|
| 28 | +import javax.servlet.http.HttpServletRequest; |
| 29 | +import javax.servlet.http.HttpServletResponse; |
| 30 | + |
30 | 31 | @Configuration
|
31 | 32 | @EnableMethodSecurity
|
32 | 33 | public class AutoConfiguration {
|
@@ -62,15 +63,25 @@ public HandlerExceptionResolver servletExceptionHandler() {
|
62 | 63 | return new ServletExceptionHandler();
|
63 | 64 | }
|
64 | 65 |
|
| 66 | + @Bean |
| 67 | + @ConditionalOnMissingBean |
| 68 | + public SecurityLoginHandler securityLoginHandler(){ |
| 69 | + return new SecurityLoginHandler() { |
| 70 | + @Override |
| 71 | + public void preHandle(HttpServletRequest request, HttpServletResponse response, LoginRequest handler) throws Exception { |
| 72 | + |
| 73 | + } |
| 74 | + }; |
| 75 | + } |
65 | 76 |
|
66 | 77 | @Bean
|
67 | 78 | @ConditionalOnMissingBean
|
68 |
| - public SecurityFilterChain filterChain(HttpSecurity http, Jwt jwt, SecurityJwtProperties properties) throws Exception { |
| 79 | + public SecurityFilterChain filterChain(HttpSecurity http, Jwt jwt,SecurityLoginHandler loginHandler, SecurityJwtProperties properties) throws Exception { |
69 | 80 | //before add addCorsMappings to enable cors.
|
70 | 81 | http.cors();
|
71 | 82 |
|
72 | 83 | http.csrf().disable();
|
73 |
| - http.apply(new HttpSecurityConfigurer(jwt, properties)); |
| 84 | + http.apply(new HttpSecurityConfigurer(jwt,loginHandler,properties)); |
74 | 85 | http
|
75 | 86 | .exceptionHandling()
|
76 | 87 | .authenticationEntryPoint(new MyUnAuthenticationEntryPoint())
|
|
0 commit comments