64850858
2021-06-07 df11956c3c203434d3ef54955a502c466f1382dd
src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java
@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.conf.security;
import com.genersoft.iot.vmp.conf.UserSetup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -22,8 +23,8 @@
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Value("${userSettings.interfaceAuthentication}")
    private boolean interfaceAuthentication;
    @Autowired
    private UserSetup userSetup;
    @Autowired
    private DefaultUserDetailsServiceImpl userDetailsService;
@@ -71,12 +72,13 @@
    @Override
    public void configure(WebSecurity web) {
        if (!interfaceAuthentication) {
        if (!userSetup.isInterfaceAuthentication()) {
            web.ignoring().antMatchers("**");
        }else {
            // 可以直接访问的静态数据
            web.ignoring()
                    .antMatchers("/")
                    .antMatchers("/#/**")
                    .antMatchers("/static/**")
                    .antMatchers("/index.html")
                    .antMatchers("/doc.html") // "/webjars/**", "/swagger-resources/**", "/v3/api-docs/**"
@@ -111,7 +113,7 @@
        http.headers().contentTypeOptions().disable();
        http.authorizeRequests()
                // 放行接口
                .antMatchers("/#/**", "/api/user/login","/index/hook/**").permitAll()
                .antMatchers("/api/user/login","/index/hook/**").permitAll()
                // 除上面外的所有请求全部需要鉴权认证
                .anyRequest().authenticated()
                // 异常处理(权限拒绝、登录失效等)