zhangqiankun 2 years ago
parent
commit
7232417783
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/main/java/com/persagy/calendar/config/SecurityConfiguration.java

+ 31 - 0
src/main/java/com/persagy/calendar/config/SecurityConfiguration.java

@@ -0,0 +1,31 @@
+package com.persagy.calendar.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+
+/**
+ * 
+ * @version 1.0.0
+ * @company persagy 
+ * @author zhangqiankun
+ * @date 2022年7月25日 下午4:12:04
+ */
+@Configuration
+public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
+
+	@Value("${spring.security.enable:false}")
+	private boolean enable;
+	
+	@Override
+	protected void configure(HttpSecurity http) throws Exception {
+		//禁用csrf校验
+		//用来关闭端点的安全校验。
+		http.csrf().disable();
+		if (enable) {
+			super.configure(http); // 开启认证
+		}
+	}
+	
+}