From 5e94f58b5db4f42e849db597351c702247f99c8e Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 3 Jun 2022 18:52:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/common/config/WebSecurityConfig.java | 60 +++++-------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java index fb1d610..9cae962 100644 --- a/src/main/java/com/xkrs/common/config/WebSecurityConfig.java +++ b/src/main/java/com/xkrs/common/config/WebSecurityConfig.java @@ -14,11 +14,12 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic @Configuration @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled=true) +@EnableGlobalMethodSecurity(prePostEnabled = true) class WebSecurityConfig extends WebSecurityConfigurerAdapter { /** * 设置 HTTP 验证规则 + * * @param http * @throws Exception */ @@ -39,52 +40,23 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter { // 所有 /login 用户登录 的POST请求 都放行 .antMatchers(HttpMethod.POST, "/api/login").permitAll() // 所有 app 用户注册 的POST请求 都放行 - .antMatchers(HttpMethod.POST, "/api/person-investigator/add").permitAll() - .antMatchers("/ws/asset").permitAll() - .antMatchers(HttpMethod.GET,"/api/user/booleanUserName").permitAll() - .antMatchers(HttpMethod.POST,"/insertFirePoint").permitAll() - .antMatchers(HttpMethod.POST,"/insertfirepointchanneltwo").permitAll() - .antMatchers(HttpMethod.POST,"/insertAppTask").permitAll() - .antMatchers(HttpMethod.GET,"/selectAppTask").permitAll() - .antMatchers(HttpMethod.GET,"/selectFirePointBetweenSeven").permitAll() - .antMatchers(HttpMethod.GET,"/selectFirePointNum").permitAll() - .antMatchers(HttpMethod.GET,"/api/user/booleanUserName").permitAll() - .antMatchers(HttpMethod.GET,"/websocketTest").permitAll() - .antMatchers(HttpMethod.GET,"/selectCityName").permitAll() - .antMatchers(HttpMethod.GET,"/weather/cityName").permitAll() - .antMatchers(HttpMethod.GET,"/weather/cityId").permitAll() - .antMatchers(HttpMethod.GET,"/selectFirePointByCode").permitAll() - .antMatchers(HttpMethod.POST,"/updateTypeByFireCode").permitAll() - .antMatchers(HttpMethod.GET,"/api/user/verificationCode").permitAll() - .antMatchers(HttpMethod.POST,"/uploadFileMore").permitAll() - .antMatchers(HttpMethod.POST,"/uploadFile").permitAll() - .antMatchers(HttpMethod.POST,"/insertFireTest").permitAll() - .antMatchers(HttpMethod.POST,"/importCityExcel").permitAll() - .antMatchers(HttpMethod.POST,"/deleteShuiTi").permitAll() - .antMatchers(HttpMethod.GET,"/selectBeijing").permitAll() - .antMatchers(HttpMethod.GET,"/api/user/verificationCodeUpdate").permitAll() - .antMatchers(HttpMethod.GET,"/api/user/getVerificationCode").permitAll() - .antMatchers(HttpMethod.POST,"/api/user/userUnRememberPassword").permitAll() - .antMatchers(HttpMethod.POST,"/updateBeforeFireAndAfterFireImage").permitAll() - .antMatchers(HttpMethod.GET,"/getProvinceList").permitAll()//获取省列表 - .antMatchers(HttpMethod.GET,"/getCityList").permitAll()//根据省编号获取市列表 - .antMatchers(HttpMethod.GET,"/getCountyList").permitAll()//根据市编号获取区县列表 - .antMatchers(HttpMethod.GET,"/getStreetList").permitAll()//根据区县编号获取街道列表 - .antMatchers(HttpMethod.GET,"/api/adm/getProvinceList").permitAll()//获取省列表 - .antMatchers(HttpMethod.GET,"/api/adm/getCityList").permitAll()//根据省编号获取市列表 - .antMatchers(HttpMethod.GET,"/api/adm/getCountyList").permitAll()//根据市编号获取区县列表 - .antMatchers(HttpMethod.GET,"/api/adm/getStreetList").permitAll()//根据区县编号获取街道列表 - .antMatchers(HttpMethod.GET,"/updateFirePointStreetCode").permitAll() + .antMatchers(HttpMethod.POST, "/api/person-investigator/add").permitAll().antMatchers("/ws/asset").permitAll().antMatchers(HttpMethod.GET, "/api/user/booleanUserName").permitAll().antMatchers(HttpMethod.POST, "/insertFirePoint").permitAll().antMatchers(HttpMethod.POST, "/insertfirepointchanneltwo").permitAll().antMatchers(HttpMethod.POST, "/insertAppTask").permitAll().antMatchers(HttpMethod.GET, "/selectAppTask").permitAll().antMatchers(HttpMethod.GET, "/selectFirePointBetweenSeven").permitAll().antMatchers(HttpMethod.GET, "/selectFirePointNum").permitAll().antMatchers(HttpMethod.GET, "/api/user/booleanUserName").permitAll().antMatchers(HttpMethod.GET, "/websocketTest").permitAll().antMatchers(HttpMethod.GET, "/selectCityName").permitAll().antMatchers(HttpMethod.GET, "/weather/cityName").permitAll().antMatchers(HttpMethod.GET, "/weather/cityId").permitAll().antMatchers(HttpMethod.GET, "/selectFirePointByCode").permitAll().antMatchers(HttpMethod.POST, "/updateTypeByFireCode").permitAll().antMatchers(HttpMethod.GET, "/api/user/verificationCode").permitAll().antMatchers(HttpMethod.POST, "/uploadFileMore").permitAll().antMatchers(HttpMethod.POST, "/uploadFile").permitAll().antMatchers(HttpMethod.POST, "/insertFireTest").permitAll().antMatchers(HttpMethod.POST, "/importCityExcel").permitAll().antMatchers(HttpMethod.POST, "/deleteShuiTi").permitAll().antMatchers(HttpMethod.GET, "/selectBeijing").permitAll().antMatchers(HttpMethod.GET, "/api/user/verificationCodeUpdate").permitAll().antMatchers(HttpMethod.GET, "/api/user/getVerificationCode").permitAll().antMatchers(HttpMethod.POST, "/api/user/userUnRememberPassword").permitAll().antMatchers(HttpMethod.POST, "/updateBeforeFireAndAfterFireImage").permitAll().antMatchers(HttpMethod.GET, "/getProvinceList").permitAll()//获取省列表 + .antMatchers(HttpMethod.GET, "/getCityList").permitAll()//根据省编号获取市列表 + .antMatchers(HttpMethod.GET, "/getCountyList").permitAll()//根据市编号获取区县列表 + .antMatchers(HttpMethod.GET, "/getStreetList").permitAll()//根据区县编号获取街道列表 + .antMatchers(HttpMethod.GET, "/api/adm/getProvinceList").permitAll()//获取省列表 + .antMatchers(HttpMethod.GET, "/api/adm/getCityList").permitAll()//根据省编号获取市列表 + .antMatchers(HttpMethod.GET, "/api/adm/getCountyList").permitAll()//根据市编号获取区县列表 + .antMatchers(HttpMethod.GET, "/api/adm/getStreetList").permitAll()//根据区县编号获取街道列表 + .antMatchers(HttpMethod.GET, "/updateFirePointStreetCode").permitAll() // 所有其它请求需要身份认证 - .anyRequest().authenticated() - .and() + .anyRequest().authenticated().and() // 添加一个过滤器 所有访问 /login 的请求交给 JWTLoginFilter 来处理 这个类处理所有的JWT相关内容 - .addFilterBefore(new JwtLoginFilter("/api/login", authenticationManager()), - UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(new JwtLoginFilter("/api/login", authenticationManager()), UsernamePasswordAuthenticationFilter.class) // 添加一个过滤器验证其他请求的Token是否合法 - .addFilterBefore(new JwtAuthenticationFilter(), - UsernamePasswordAuthenticationFilter.class); - ;} + .addFilterBefore(new JwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); + ; + } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception {