fire_point/src/main/java/com/xkrs/common/config/WebSecurityConfig.java

97 lines
6.0 KiB
Java
Raw Normal View History

2021-07-12 14:51:34 +08:00
package com.xkrs.common.config;
import com.xkrs.common.account.CustomAuthenticationProvider;
import com.xkrs.common.account.JwtAuthenticationFilter;
import com.xkrs.common.account.JwtLoginFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
@Configuration
@EnableWebSecurity
2022-06-03 18:52:59 +08:00
@EnableGlobalMethodSecurity(prePostEnabled = true)
2021-07-12 14:51:34 +08:00
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/**
* 设置 HTTP 验证规则
2022-06-03 18:52:59 +08:00
*
2021-07-12 14:51:34 +08:00
* @param http
* @throws Exception
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
// 关闭csrf验证
http.csrf().disable()
// 对请求进行认证
.authorizeRequests()
// 所有 / 的所有请求 都放行
//.antMatchers("/").permitAll()
// 所有OPTIONS请求都放行
.antMatchers(HttpMethod.OPTIONS).permitAll()
.antMatchers("/global/configuration/**").permitAll()
2022-09-06 17:15:58 +08:00
.antMatchers("/push/**").permitAll()
2023-02-03 10:17:25 +08:00
.antMatchers("/dispatch/**").permitAll()
.antMatchers("/queryFirePoint").permitAll()
2022-10-08 11:11:02 +08:00
.antMatchers(HttpMethod.POST, "/api/user/updateSysUser").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigDict").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfigValue").permitAll()
.antMatchers(HttpMethod.GET, "/selectGlobalConfig").permitAll()
.antMatchers(HttpMethod.POST, "/globalConfig").permitAll()
.antMatchers(HttpMethod.POST, "/globalConfigDict").permitAll()
2021-07-12 14:51:34 +08:00
.antMatchers(HttpMethod.POST, "/api/user/add").permitAll()
.antMatchers(HttpMethod.POST, "/api/user/check/duplicate").permitAll()
.antMatchers(HttpMethod.POST, "/api/login").permitAll()
// 所有 app 用户注册 的POST请求 都放行
2022-06-07 09:57:57 +08:00
.antMatchers(HttpMethod.POST, "/api/person-investigator/add").permitAll()
.antMatchers("/ws/asset").permitAll()
.antMatchers(HttpMethod.GET, "/api/user/booleanUserName").permitAll()
2022-07-26 15:57:08 +08:00
.antMatchers(HttpMethod.GET, "/queryzzhd").permitAll()
2022-06-07 09:57:57 +08:00
.antMatchers(HttpMethod.POST, "/insertFirePoint").permitAll()
.antMatchers(HttpMethod.POST, "/insertAppTask").permitAll()
.antMatchers(HttpMethod.GET, "/selectAppTask").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.GET, "/api/user/verificationCode").permitAll()
2022-07-07 08:57:51 +08:00
.antMatchers(HttpMethod.GET, "/api/user/selectAgentOrgList").permitAll()//获取代理组织列表
2022-06-07 09:57:57 +08:00
.antMatchers(HttpMethod.POST, "/uploadFileMore").permitAll()
.antMatchers(HttpMethod.POST, "/uploadFile").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()//获取省列表
2022-06-03 18:52:59 +08:00
.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.GET, "/selectTodayFirePoint").permitAll()
2023-01-30 13:57:46 +08:00
.antMatchers(HttpMethod.GET, "/api/user/selectVipUser").permitAll()
2021-07-12 14:51:34 +08:00
// 所有其它请求需要身份认证
2022-06-07 11:21:13 +08:00
.anyRequest().authenticated()
.and()
2021-07-12 14:51:34 +08:00
// 添加一个过滤器 所有访问 /login 的请求交给 JWTLoginFilter 来处理 这个类处理所有的JWT相关内容
2022-06-03 18:52:59 +08:00
.addFilterBefore(new JwtLoginFilter("/api/login", authenticationManager()), UsernamePasswordAuthenticationFilter.class)
2021-07-12 14:51:34 +08:00
// 添加一个过滤器验证其他请求的Token是否合法
2022-06-03 18:52:59 +08:00
.addFilterBefore(new JwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
;
}
2021-07-12 14:51:34 +08:00
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// 使用自定义身份验证组件
auth.authenticationProvider(new CustomAuthenticationProvider());
}
}