| | |
| | | package com.gkhy.hazmat.framework.security; |
| | | |
| | | import com.gkhy.hazmat.framework.security.filter.JwtAuthenticationTokenFilter; |
| | | import com.gkhy.hazmat.framework.security.filter.ThirdPartyTokenFilter; |
| | | import com.gkhy.hazmat.framework.security.handle.AuthenticationEntryPointImpl; |
| | | import com.gkhy.hazmat.framework.security.handle.LogoutSuccessHandlerImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | */ |
| | | @Autowired |
| | | private JwtAuthenticationTokenFilter authenticationTokenFilter; |
| | | |
| | | @Autowired |
| | | private ThirdPartyTokenFilter thirdPartyTokenFilter; |
| | | |
| | | /** |
| | | * 跨域过滤器 |
| | |
| | | |
| | | httpSecurity |
| | | // CSRF禁用,因为不使用session |
| | | .cors().and() |
| | | // .cors().and() |
| | | .csrf().disable() |
| | | // 禁用HTTP响应标头 |
| | | .headers().cacheControl().disable().and() |
| | |
| | | .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() |
| | | // 过滤请求 |
| | | .authorizeRequests() |
| | | .antMatchers("/api/hazmat/zkd/data/**").permitAll() |
| | | // 对于登录login 注册register 验证码captchaImage 允许匿名访问 |
| | | .antMatchers("/**/login", "/register", "/system/captcha/captchaImage").permitAll() |
| | | // 静态资源,可匿名访问 |
| | |
| | | // 添加Logout filter |
| | | httpSecurity.logout().logoutUrl("/logout").logoutSuccessHandler(logoutSuccessHandler); |
| | | // 添加JWT filter |
| | | httpSecurity.addFilterBefore(corsFilter, UsernamePasswordAuthenticationFilter.class); |
| | | // 2. 第三方固定Token过滤器 |
| | | httpSecurity.addFilterBefore(thirdPartyTokenFilter, UsernamePasswordAuthenticationFilter.class); |
| | | // 3. 登录用户JWT过滤器 |
| | | httpSecurity.addFilterBefore(authenticationTokenFilter, UsernamePasswordAuthenticationFilter.class); |
| | | // 添加CORS filter |
| | | httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationTokenFilter.class); |
| | | httpSecurity.addFilterBefore(corsFilter, LogoutFilter.class); |
| | | } |
| | | |
| | | /** |