|
|
|
@ -1,5 +1,9 @@
|
|
|
|
|
package com.ruoyi.framework.config;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.framework.config.properties.PermitAllUrlProperties;
|
|
|
|
|
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
|
|
|
|
|
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
|
|
|
|
|
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.http.HttpMethod;
|
|
|
|
@ -15,10 +19,6 @@ 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.config.properties.PermitAllUrlProperties;
|
|
|
|
|
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
|
|
|
|
|
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
|
|
|
|
|
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* spring security配置
|
|
|
|
@ -26,8 +26,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
*/
|
|
|
|
|
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
|
|
|
|
|
public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
{
|
|
|
|
|
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|
|
|
|
/**
|
|
|
|
|
* 自定义用户认证逻辑
|
|
|
|
|
*/
|
|
|
|
@ -72,8 +71,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
@Override
|
|
|
|
|
public AuthenticationManager authenticationManagerBean() throws Exception
|
|
|
|
|
{
|
|
|
|
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
|
|
|
|
return super.authenticationManagerBean();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -93,8 +91,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
* authenticated | 用户登录后可访问
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception
|
|
|
|
|
{
|
|
|
|
|
protected void configure(HttpSecurity httpSecurity) throws Exception {
|
|
|
|
|
// 注解标记允许匿名访问的url
|
|
|
|
|
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry = httpSecurity.authorizeRequests();
|
|
|
|
|
permitAllUrl.getUrls().forEach(url -> registry.antMatchers(url).permitAll());
|
|
|
|
@ -113,13 +110,13 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
|
|
|
|
|
.antMatchers("/login", "/register", "/captchaImage").permitAll()
|
|
|
|
|
// 静态资源,可匿名访问
|
|
|
|
|
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
|
|
|
|
|
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/tcZz/cy/**n","/tcZz/yqzs/**",
|
|
|
|
|
"/tcZz/networkSecurity/cybersecurity/**","/tcZz/networkSecurity/xtjc/**",
|
|
|
|
|
"/tcZz/networkSecurity/jgdw/**","/tcZz/netWorkYq/yqxxltj/**","/tcZz/netWorkYq/yqxxltj/**",
|
|
|
|
|
"/tcZz/yqzs/ListNoToken","/tcZz/cy/ListNoToken",
|
|
|
|
|
"/tcZz/networkSecurity/cybersecurity/ListNoToken","/tcZz/networkSecurity/jgdw/ListNoToken",
|
|
|
|
|
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**",
|
|
|
|
|
"/tcZz/netWorkYq/yqzs/ListNoToken", "/tcZz/netWorkYq/cy/ListNoToken",
|
|
|
|
|
"/tcZz/networkSecurity/cybersecurity/ListNoToken", "/tcZz/networkSecurity/cybersecurity/ListNoToken",
|
|
|
|
|
"/tcZz/networkSecurity/jgdw/ListNoToken",
|
|
|
|
|
"/tcZz/networkSecurity/xtjc/ListNoToken", "/tcZz/netWorkYq/yqxxltj/ListNoToken").permitAll()
|
|
|
|
|
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**"
|
|
|
|
|
).permitAll()
|
|
|
|
|
// 除上面外的所有请求全部需要鉴权认证
|
|
|
|
|
.anyRequest().authenticated()
|
|
|
|
|
.and()
|
|
|
|
@ -137,8 +134,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
* 强散列哈希加密实现
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public BCryptPasswordEncoder bCryptPasswordEncoder()
|
|
|
|
|
{
|
|
|
|
|
public BCryptPasswordEncoder bCryptPasswordEncoder() {
|
|
|
|
|
return new BCryptPasswordEncoder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -146,8 +142,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
|
|
|
|
* 身份认证接口
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception
|
|
|
|
|
{
|
|
|
|
|
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
|
|
|
auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|