|
|
|
@ -12,6 +12,8 @@ import org.springframework.security.config.http.SessionCreationPolicy;
|
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
|
|
import org.springframework.security.web.authentication.logout.LogoutFilter;
|
|
|
|
|
import org.springframework.web.filter.CorsFilter;
|
|
|
|
|
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
|
|
|
|
|
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
|
|
|
|
|
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
|
|
|
@ -47,6 +49,12 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtAuthenticationTokenFilter authenticationTokenFilter;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 跨域过滤器
|
|
|
|
|
*/
|
|
|
|
|
@Autowired
|
|
|
|
|
private CorsFilter corsFilter;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解决 无法直接注入 AuthenticationManager
|
|
|
|
@ -112,6 +120,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler);
|
|
|
|
|
// 添加JWT filter
|
|
|
|
|
httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
|
|
|
|
|
// 添加CORS filter
|
|
|
|
|
httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class);
|
|
|
|
|
httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|