93 lines
3.5 KiB
Java
93 lines
3.5 KiB
Java
package com.gxwebsoft.common.core.security;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.http.HttpMethod;
|
|
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.config.http.SessionCreationPolicy;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
/**
|
|
* Spring Security配置
|
|
*
|
|
* @author WebSoft
|
|
* @since 2020-03-23 18:04:52
|
|
*/
|
|
@Configuration
|
|
@EnableWebSecurity
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
|
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
@Resource
|
|
private JwtAccessDeniedHandler jwtAccessDeniedHandler;
|
|
@Resource
|
|
private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
|
|
@Resource
|
|
private JwtAuthenticationFilter jwtAuthenticationFilter;
|
|
|
|
@Override
|
|
protected void configure(HttpSecurity http) throws Exception {
|
|
http.authorizeRequests()
|
|
.antMatchers(HttpMethod.OPTIONS, "/**")
|
|
.permitAll()
|
|
.antMatchers(HttpMethod.GET, "/api/file/**","/**", "/api/captcha", "/")
|
|
.permitAll()
|
|
.antMatchers(
|
|
"/api/login",
|
|
"/api/register",
|
|
"/api/existence",
|
|
"/api/oss/upload",
|
|
"/druid/**",
|
|
"/swagger-resources/**",
|
|
"/webjars/**",
|
|
"/hxz/v1/**",
|
|
"/api/sendSmsCaptcha",
|
|
"/api/loginBySms",
|
|
"/api/parseToken/*",
|
|
"/api/login-alipay/*",
|
|
"/api/wx-login/loginByMpWxPhone",
|
|
"/api/wx-login/loginByOpenId",
|
|
"/api/system/wx-native-pay/**",
|
|
"/api/system/wx-pay/**",
|
|
"/api/wxWorkQrConnect",
|
|
"/api/sys/user-plan-log/wx-pay/**",
|
|
"/api/wx-official/**",
|
|
"/lvQ4EoivKJ.txt",
|
|
"/api/think/think-recharge-log/refund-notify"
|
|
)
|
|
.permitAll()
|
|
.anyRequest()
|
|
.authenticated()
|
|
.and()
|
|
.sessionManagement()
|
|
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
|
.and()
|
|
.csrf()
|
|
.disable()
|
|
.cors()
|
|
.and()
|
|
.logout()
|
|
.disable()
|
|
.headers()
|
|
.frameOptions()
|
|
.disable()
|
|
.and()
|
|
.exceptionHandling()
|
|
.accessDeniedHandler(jwtAccessDeniedHandler)
|
|
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
|
|
.and()
|
|
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
|
|
}
|
|
|
|
@Bean
|
|
public BCryptPasswordEncoder bCryptPasswordEncoder() {
|
|
return new BCryptPasswordEncoder();
|
|
}
|
|
|
|
}
|