Commit 689d7c0cc4f4dcee6c6588263f1c90eca81942e7
1 parent
5ba0fba0
添加接口鉴权开关
Showing
2 changed files
with
21 additions
and
10 deletions
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