wuheng 1 year ago
commit
2ba8fa13cb

+ 33 - 0
.gitignore

@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/

+ 17 - 0
common/pom.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>common</artifactId>
+    <name>common</name>
+    <description>common</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+
+</project>

+ 77 - 0
controller/pom.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>controller</artifactId>
+    <name>controller</name>
+    <description>controller</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.koobietech.eas</groupId>
+            <artifactId>security</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>11</source>
+                    <target>11</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot.version}</version>
+                <configuration>
+                    <mainClass>com.koobietech.eas.controller.ControllerApplication</mainClass>
+                    <skip>false</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
controller/src/main/java/com/koobietech/eas/ControllerApplication.java

@@ -0,0 +1,13 @@
+package com.koobietech.eas;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ControllerApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ControllerApplication.class, args);
+    }
+
+}

+ 14 - 0
controller/src/main/java/com/koobietech/eas/controller/EasUserController.java

@@ -0,0 +1,14 @@
+package com.koobietech.eas.controller;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class EasUserController {
+
+    @GetMapping("/test")
+    public String test(){
+        return "Hello";
+    }
+
+}

+ 2 - 0
controller/src/main/resources/application-dev.yaml

@@ -0,0 +1,2 @@
+server:
+  port: 8080

+ 10 - 0
controller/src/main/resources/application.yaml

@@ -0,0 +1,10 @@
+server:
+  port: 8080
+spring:
+  profiles:
+    active: dev
+
+security:
+  url:
+    ignored:
+      - /login

+ 38 - 0
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -0,0 +1,38 @@
+package com.koobietech.eas.controller;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.util.*;
+
+@SpringBootTest
+class ControllerApplicationTests {
+
+    @Test
+    void contextLoads() {
+
+//        String[] words = {"apple", "banana", "orange",
+//                "banana", "apple", "orange", "banana", "pear", "pear"};
+//        int k = 3;
+//        // getOrDefault 方法用户查询 指定单词 在Map 是否存在过  没有 返回 0 有返回之前存入数
+//        Map<String, Integer> wordCount = new HashMap<>();
+//        for (String word : words) {
+//            wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);
+//        }
+//        //Collections.sort  用于排序 按照Value降序排列   sort 默认升序
+//        // b.getValue().compareTo(a.getValue())  用来对比 两个值的 大小
+//        List<Map.Entry<String, Integer>> sortedWordCount = new ArrayList<>(wordCount.entrySet());
+//        Collections.sort(sortedWordCount, (a, b) -> b.getValue().compareTo(a.getValue()));
+//        //取出 排序后的  前 K 个值
+//        List<String> topKWords = new ArrayList<>();
+//        for (int i = 0; i < k && i < sortedWordCount.size(); i++) {
+//            topKWords.add(sortedWordCount.get(i).getKey());
+//        }
+
+
+
+
+
+    }
+
+}

+ 16 - 0
dao/pom.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>dao</artifactId>
+    <name>dao</name>
+    <description>dao</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+</project>

+ 71 - 0
jobs/pom.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>jobs</artifactId>
+    <name>jobs</name>
+    <description>jobs</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-dependencies</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+                <configuration>
+                    <source>11</source>
+                    <target>11</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>${spring-boot.version}</version>
+                <configuration>
+                    <mainClass>com.koobietech.eas.jobs.JobsApplication</mainClass>
+                    <skip>false</skip>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>repackage</id>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
jobs/src/main/java/com/koobietech/eas/jobs/JobsApplication.java

@@ -0,0 +1,13 @@
+package com.koobietech.eas.jobs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class JobsApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(JobsApplication.class, args);
+    }
+
+}

+ 2 - 0
jobs/src/main/resources/application-dev.yaml

@@ -0,0 +1,2 @@
+server:
+  port: 8081

+ 6 - 0
jobs/src/main/resources/application.yaml

@@ -0,0 +1,6 @@
+server:
+  port: 8081
+
+spring:
+  profiles:
+    active: dev

+ 13 - 0
jobs/src/test/java/com/koobietech/eas/jobs/JobsApplicationTests.java

@@ -0,0 +1,13 @@
+package com.koobietech.eas.jobs;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class JobsApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}

+ 17 - 0
mbg/pom.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>mbg</artifactId>
+    <name>mbg</name>
+    <description>mbg</description>
+
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+</project>

+ 41 - 0
pom.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.koobietech.eas</groupId>
+    <artifactId>eas-system</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>pom</packaging>
+
+    <properties>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
+        <java.version>11</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>2.7.6</spring-boot.version>
+        <lombok.version>1.18.24</lombok.version>
+        <project.version>0.0.1-SNAPSHOT</project.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>${lombok.version}</version>
+        </dependency>
+    </dependencies>
+
+    <modules>
+        <module>controller</module>
+        <module>common</module>
+        <module>dao</module>
+        <module>jobs</module>
+        <module>mbg</module>
+        <module>service</module>
+        <module>security</module>
+    </modules>
+
+</project>

+ 32 - 0
security/pom.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>security</artifactId>
+    <name>security</name>
+    <description>security</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>javax.servlet-api</artifactId>
+            <version>4.0.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
+            <version>${spring-boot.version}</version>
+        </dependency>
+
+    </dependencies>
+
+</project>

+ 15 - 0
security/src/main/java/com/koobietech/eas/security/config/IgnoreUrlsConfig.java

@@ -0,0 +1,15 @@
+package com.koobietech.eas.security.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "security.url")
+public class IgnoreUrlsConfig {
+    private List<String> ignored = new ArrayList<>();
+}

+ 44 - 0
security/src/main/java/com/koobietech/eas/security/config/SecurityConfig.java

@@ -0,0 +1,44 @@
+package com.koobietech.eas.security.config;
+
+import com.koobietech.eas.security.filter.EasSecurityFilter;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
+import org.springframework.security.config.http.SessionCreationPolicy;
+import org.springframework.security.web.SecurityFilterChain;
+import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
+
+import javax.annotation.Resource;
+
+@Configuration
+@EnableWebSecurity
+public class SecurityConfig {
+
+    @Resource
+    EasSecurityFilter easSecurityFilter;
+
+    @Resource
+    IgnoreUrlsConfig ignoreUrlsConfig;
+
+    @Bean
+    public SecurityFilterChain t(HttpSecurity httpSecurity) throws Exception {
+
+        ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry
+                registry = httpSecurity.authorizeRequests();
+
+        for (String url : ignoreUrlsConfig.getIgnored()) {
+            registry.antMatchers(url).permitAll();
+        }
+        registry.anyRequest().authenticated();
+
+        HttpSecurity and = httpSecurity
+                .sessionManagement()
+                .sessionCreationPolicy(SessionCreationPolicy.NEVER)
+                .and();
+        and.addFilterBefore( easSecurityFilter, UsernamePasswordAuthenticationFilter.class);
+
+        return and.build();
+    }
+}

+ 20 - 0
security/src/main/java/com/koobietech/eas/security/filter/EasSecurityFilter.java

@@ -0,0 +1,20 @@
+package com.koobietech.eas.security.filter;
+
+import org.springframework.stereotype.Component;
+import org.springframework.web.filter.OncePerRequestFilter;
+
+import java.io.IOException;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Component
+public class EasSecurityFilter extends OncePerRequestFilter {
+
+
+    @Override
+    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
+        filterChain.doFilter(request, response);
+    }
+}

+ 16 - 0
service/pom.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>service</artifactId>
+    <name>service</name>
+    <description>service</description>
+
+    <parent>
+        <artifactId>eas-system</artifactId>
+        <groupId>com.koobietech.eas</groupId>
+        <version>0.0.1-SNAPSHOT</version>
+    </parent>
+
+</project>