Commit 689d7c0cc4f4dcee6c6588263f1c90eca81942e7

Authored by panlinlin
1 parent 5ba0fba0

添加接口鉴权开关

src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java
1 1 package com.genersoft.iot.vmp.conf.security;
2 2  
3 3 import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.beans.factory.annotation.Value;
4 5 import org.springframework.context.annotation.Bean;
5 6 import org.springframework.context.annotation.Configuration;
6 7 import org.springframework.security.authentication.AuthenticationManager;
... ... @@ -21,6 +22,9 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
21 22 @EnableGlobalMethodSecurity(prePostEnabled = true)
22 23 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
23 24  
  25 + @Value("${userSettings.interfaceAuthentication}")
  26 + private boolean interfaceAuthentication;
  27 +
24 28 @Autowired
25 29 private DefaultUserDetailsServiceImpl userDetailsService;
26 30 /**
... ... @@ -66,16 +70,21 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
66 70 **/
67 71 @Override
68 72 public void configure(WebSecurity web) {
69   - // 可以直接访问的静态数据
70   - web.ignoring()
71   - .antMatchers("/")
72   - .antMatchers("/static/**")
73   - .antMatchers("/index.html")
74   - .antMatchers("/doc.html") // "/webjars/**", "/swagger-resources/**", "/v3/api-docs/**"
75   - .antMatchers("/webjars/**")
76   - .antMatchers("/swagger-resources/**")
77   - .antMatchers("/v3/api-docs/**")
78   - .antMatchers("/js/**");
  73 +
  74 + if (!interfaceAuthentication) {
  75 + web.ignoring().antMatchers("**");
  76 + }else {
  77 + // 可以直接访问的静态数据
  78 + web.ignoring()
  79 + .antMatchers("/")
  80 + .antMatchers("/static/**")
  81 + .antMatchers("/index.html")
  82 + .antMatchers("/doc.html") // "/webjars/**", "/swagger-resources/**", "/v3/api-docs/**"
  83 + .antMatchers("/webjars/**")
  84 + .antMatchers("/swagger-resources/**")
  85 + .antMatchers("/v3/api-docs/**")
  86 + .antMatchers("/js/**");
  87 + }
79 88 }
80 89  
81 90 /**
... ...
src/main/resources/application-dev.yml
... ... @@ -104,6 +104,8 @@ userSettings:
104 104 playTimeout: 3000
105 105 # 等待音视频编码信息再返回, true: 可以根据编码选择合适的播放器,false: 可以更快点播
106 106 waitTrack: false
  107 + # 是否开启接口鉴权
  108 + interfaceAuthentication: true
107 109  
108 110 # 在线文档: swagger-ui(生产环境建议关闭)
109 111 springfox:
... ...