Commit 6f1aafa2a767c79dc8306bd38f9a8152efcd738c
1 parent
9e9e2f3e
spring boot admin增加登陆权限验证
Showing
5 changed files
with
297 additions
and
0 deletions
zteits-project-admin/pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
4 | + <modelVersion>4.0.0</modelVersion> | ||
5 | + | ||
6 | + <groupId>com.zteits.admin</groupId> | ||
7 | + <artifactId>zteits-project-admin</artifactId> | ||
8 | + <version>2.0.1-SNAPSHOT</version> | ||
9 | + <packaging>jar</packaging> | ||
10 | + | ||
11 | + <name>zteits-admin</name> | ||
12 | + <parent> | ||
13 | + <groupId>org.springframework.boot</groupId> | ||
14 | + <artifactId>spring-boot-starter-parent</artifactId> | ||
15 | + <version>2.0.5.RELEASE</version> | ||
16 | + <relativePath /> <!-- lookup parent from repository --> | ||
17 | + </parent> | ||
18 | + | ||
19 | + <dependencies> | ||
20 | + <dependency> | ||
21 | + <groupId>de.codecentric</groupId> | ||
22 | + <artifactId>spring-boot-admin-starter-server</artifactId> | ||
23 | + <version>2.0.3</version> | ||
24 | + </dependency> | ||
25 | + <dependency> | ||
26 | + <groupId>org.springframework.boot</groupId> | ||
27 | + <artifactId>spring-boot-starter-security</artifactId> | ||
28 | + </dependency> | ||
29 | + <dependency> | ||
30 | + <groupId>org.springframework.boot</groupId> | ||
31 | + <artifactId>spring-boot-starter-web</artifactId> | ||
32 | + </dependency> | ||
33 | + <dependency> | ||
34 | + <groupId>org.springframework.boot</groupId> | ||
35 | + <artifactId>spring-boot-starter-mail</artifactId> | ||
36 | + </dependency> | ||
37 | + | ||
38 | + <dependency> | ||
39 | + <groupId>org.springframework.session</groupId> | ||
40 | + <artifactId>spring-session-core</artifactId> | ||
41 | + </dependency> | ||
42 | + <dependency> | ||
43 | + <groupId>org.springframework.boot</groupId> | ||
44 | + <artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
45 | + </dependency> | ||
46 | + <!-- Test --> | ||
47 | + <dependency> | ||
48 | + <groupId>org.springframework.boot</groupId> | ||
49 | + <artifactId>spring-boot-starter-test</artifactId> | ||
50 | + <scope>test</scope> | ||
51 | + </dependency> | ||
52 | + <dependency> | ||
53 | + <groupId>org.springframework.boot</groupId> | ||
54 | + <artifactId>spring-boot-devtools</artifactId> | ||
55 | + <optional>true</optional> | ||
56 | + </dependency> | ||
57 | + </dependencies> | ||
58 | + | ||
59 | + <build> | ||
60 | + <defaultGoal>compile</defaultGoal> | ||
61 | + <finalName>zteits-project-admin</finalName> | ||
62 | + <plugins> | ||
63 | + <plugin> | ||
64 | + <groupId>org.springframework.boot</groupId> | ||
65 | + <artifactId>spring-boot-maven-plugin</artifactId> | ||
66 | + <configuration> | ||
67 | + <mainClass>com.zteits.admin.SpringBootAdminApplication</mainClass> | ||
68 | + </configuration> | ||
69 | + </plugin> | ||
70 | + <plugin> | ||
71 | + <groupId>org.apache.maven.plugins</groupId> | ||
72 | + <artifactId>maven-compiler-plugin</artifactId> | ||
73 | + <configuration> | ||
74 | + <source>1.8</source> | ||
75 | + <target>1.8</target> | ||
76 | + </configuration> | ||
77 | + </plugin> | ||
78 | + </plugins> | ||
79 | + <!-- <resources> | ||
80 | + <resource> | ||
81 | + <directory>src/lib</directory> | ||
82 | + <targetPath>BOOT-INF/lib/</targetPath> | ||
83 | + <includes> | ||
84 | + <include>**/*.jar</include> | ||
85 | + </includes> | ||
86 | + </resource> | ||
87 | + <resource> | ||
88 | + <directory>src/main/resources</directory> | ||
89 | + <targetPath>BOOT-INF/classes/</targetPath> | ||
90 | + </resource> | ||
91 | + </resources>--> | ||
92 | + </build> | ||
93 | + <distributionManagement> | ||
94 | + <repository> | ||
95 | + <id>nexus_releases</id> | ||
96 | + <name>core Release Repository</name> | ||
97 | + <url>http://192.168.1.195:9999/nexus/content/repositories/releases/</url> | ||
98 | + </repository> | ||
99 | + <snapshotRepository> | ||
100 | + <id>nexus_snapshots</id> | ||
101 | + <name>core Snapshots Repository</name> | ||
102 | + <url>http://192.168.1.195:9999/nexus/content/repositories/snapshots/</url> | ||
103 | + </snapshotRepository> | ||
104 | + </distributionManagement> | ||
105 | + | ||
106 | + | ||
107 | +</project> |
zteits-project-admin/src/main/java/com/zteits/admin/SpringBootAdminApplication.java
0 → 100644
1 | +package com.zteits.admin; | ||
2 | + | ||
3 | +import de.codecentric.boot.admin.server.config.EnableAdminServer; | ||
4 | +import org.springframework.boot.SpringApplication; | ||
5 | +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
6 | +import org.springframework.context.annotation.ComponentScan; | ||
7 | +import org.springframework.context.annotation.Configuration; | ||
8 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
9 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
10 | + | ||
11 | +@Configuration | ||
12 | +@EnableAutoConfiguration | ||
13 | +@EnableAdminServer | ||
14 | +@ComponentScan(basePackages={"com.zteits.admin"}) | ||
15 | +public class SpringBootAdminApplication { | ||
16 | + public static void main(String[] args) { | ||
17 | + SpringApplication.run(SpringBootAdminApplication.class, args); | ||
18 | + } | ||
19 | +} | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
zteits-project-admin/src/main/java/com/zteits/admin/config/SecuritySecureConfig.java
0 → 100644
1 | +package com.zteits.admin.config; | ||
2 | + | ||
3 | +import de.codecentric.boot.admin.server.config.AdminServerProperties; | ||
4 | +import org.springframework.context.annotation.Configuration; | ||
5 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
6 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
7 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
8 | +import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
9 | +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; | ||
10 | + | ||
11 | +@Configuration | ||
12 | +@EnableWebSecurity | ||
13 | +public class SecuritySecureConfig extends WebSecurityConfigurerAdapter { | ||
14 | + private final String adminContextPath; | ||
15 | + | ||
16 | + public SecuritySecureConfig(AdminServerProperties adminServerProperties) { | ||
17 | + this.adminContextPath = adminServerProperties.getContextPath(); | ||
18 | + } | ||
19 | + | ||
20 | + @Override | ||
21 | + protected void configure(HttpSecurity http) throws Exception { | ||
22 | + SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); | ||
23 | + successHandler.setTargetUrlParameter("redirectTo"); | ||
24 | + successHandler.setDefaultTargetUrl(adminContextPath + "/"); | ||
25 | + | ||
26 | + http.authorizeRequests() | ||
27 | + .antMatchers(adminContextPath + "/assets/**").permitAll() | ||
28 | + .antMatchers(adminContextPath + "/login").permitAll() | ||
29 | + .anyRequest().authenticated() | ||
30 | + .and() | ||
31 | + .formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and() | ||
32 | + .logout().logoutUrl(adminContextPath + "/logout").and() | ||
33 | + .httpBasic().and() | ||
34 | + .csrf() | ||
35 | + .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) | ||
36 | + .ignoringAntMatchers( | ||
37 | + adminContextPath + "/instances", | ||
38 | + adminContextPath + "/actuator/**" | ||
39 | + ); | ||
40 | + // @formatter:on | ||
41 | + } | ||
42 | +} | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
zteits-project-admin/src/main/resources/application.yml
0 → 100644
zteits-project-admin/zteits-project-admin.iml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
3 | + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
4 | + <output url="file://$MODULE_DIR$/target/classes" /> | ||
5 | + <output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
6 | + <content url="file://$MODULE_DIR$"> | ||
7 | + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
8 | + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
9 | + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
10 | + <excludeFolder url="file://$MODULE_DIR$/target" /> | ||
11 | + </content> | ||
12 | + <orderEntry type="inheritedJdk" /> | ||
13 | + <orderEntry type="sourceFolder" forTests="false" /> | ||
14 | + <orderEntry type="library" name="Maven: de.codecentric:spring-boot-admin-starter-server:2.0.3" level="project" /> | ||
15 | + <orderEntry type="library" name="Maven: de.codecentric:spring-boot-admin-server:2.0.3" level="project" /> | ||
16 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-webflux:2.0.5.RELEASE" level="project" /> | ||
17 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-reactor-netty:2.0.5.RELEASE" level="project" /> | ||
18 | + <orderEntry type="library" name="Maven: io.projectreactor.ipc:reactor-netty:0.7.9.RELEASE" level="project" /> | ||
19 | + <orderEntry type="library" name="Maven: io.netty:netty-codec-http:4.1.29.Final" level="project" /> | ||
20 | + <orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.29.Final" level="project" /> | ||
21 | + <orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.29.Final" level="project" /> | ||
22 | + <orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.29.Final" level="project" /> | ||
23 | + <orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.29.Final" level="project" /> | ||
24 | + <orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.29.Final" level="project" /> | ||
25 | + <orderEntry type="library" name="Maven: io.netty:netty-handler-proxy:4.1.29.Final" level="project" /> | ||
26 | + <orderEntry type="library" name="Maven: io.netty:netty-codec-socks:4.1.29.Final" level="project" /> | ||
27 | + <orderEntry type="library" name="Maven: io.netty:netty-transport-native-epoll:linux-x86_64:4.1.29.Final" level="project" /> | ||
28 | + <orderEntry type="library" name="Maven: io.netty:netty-common:4.1.29.Final" level="project" /> | ||
29 | + <orderEntry type="library" name="Maven: io.netty:netty-transport-native-unix-common:4.1.29.Final" level="project" /> | ||
30 | + <orderEntry type="library" name="Maven: org.springframework:spring-webflux:5.0.9.RELEASE" level="project" /> | ||
31 | + <orderEntry type="library" name="Maven: org.synchronoss.cloud:nio-multipart-parser:1.1.0" level="project" /> | ||
32 | + <orderEntry type="library" name="Maven: org.synchronoss.cloud:nio-stream-storage:1.1.3" level="project" /> | ||
33 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-actuator:2.0.5.RELEASE" level="project" /> | ||
34 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator-autoconfigure:2.0.5.RELEASE" level="project" /> | ||
35 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-actuator:2.0.5.RELEASE" level="project" /> | ||
36 | + <orderEntry type="library" name="Maven: io.micrometer:micrometer-core:1.0.6" level="project" /> | ||
37 | + <orderEntry type="library" name="Maven: org.hdrhistogram:HdrHistogram:2.1.10" level="project" /> | ||
38 | + <orderEntry type="library" name="Maven: org.latencyutils:LatencyUtils:2.0.3" level="project" /> | ||
39 | + <orderEntry type="library" name="Maven: io.projectreactor.addons:reactor-extra:3.1.7.RELEASE" level="project" /> | ||
40 | + <orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.1.9.RELEASE" level="project" /> | ||
41 | + <orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" /> | ||
42 | + <orderEntry type="library" name="Maven: de.codecentric:spring-boot-admin-server-ui:2.0.3" level="project" /> | ||
43 | + <orderEntry type="library" name="Maven: de.codecentric:spring-boot-admin-server-cloud:2.0.3" level="project" /> | ||
44 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-security:2.0.5.RELEASE" level="project" /> | ||
45 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.0.5.RELEASE" level="project" /> | ||
46 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.0.5.RELEASE" level="project" /> | ||
47 | + <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" /> | ||
48 | + <orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" /> | ||
49 | + <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.10.0" level="project" /> | ||
50 | + <orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.10.0" level="project" /> | ||
51 | + <orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" /> | ||
52 | + <orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" /> | ||
53 | + <orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.19" level="project" /> | ||
54 | + <orderEntry type="library" name="Maven: org.springframework:spring-aop:5.0.9.RELEASE" level="project" /> | ||
55 | + <orderEntry type="library" name="Maven: org.springframework:spring-beans:5.0.9.RELEASE" level="project" /> | ||
56 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:5.0.8.RELEASE" level="project" /> | ||
57 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-core:5.0.8.RELEASE" level="project" /> | ||
58 | + <orderEntry type="library" name="Maven: org.springframework.security:spring-security-web:5.0.8.RELEASE" level="project" /> | ||
59 | + <orderEntry type="library" name="Maven: org.springframework:spring-expression:5.0.9.RELEASE" level="project" /> | ||
60 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:2.0.5.RELEASE" level="project" /> | ||
61 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.0.5.RELEASE" level="project" /> | ||
62 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" /> | ||
63 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" /> | ||
64 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.6" level="project" /> | ||
65 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.6" level="project" /> | ||
66 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.6" level="project" /> | ||
67 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.6" level="project" /> | ||
68 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:2.0.5.RELEASE" level="project" /> | ||
69 | + <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.34" level="project" /> | ||
70 | + <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.34" level="project" /> | ||
71 | + <orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.34" level="project" /> | ||
72 | + <orderEntry type="library" name="Maven: org.hibernate.validator:hibernate-validator:6.0.12.Final" level="project" /> | ||
73 | + <orderEntry type="library" name="Maven: javax.validation:validation-api:2.0.1.Final" level="project" /> | ||
74 | + <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.2.Final" level="project" /> | ||
75 | + <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" /> | ||
76 | + <orderEntry type="library" name="Maven: org.springframework:spring-web:5.0.9.RELEASE" level="project" /> | ||
77 | + <orderEntry type="library" name="Maven: org.springframework:spring-webmvc:5.0.9.RELEASE" level="project" /> | ||
78 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-mail:2.0.5.RELEASE" level="project" /> | ||
79 | + <orderEntry type="library" name="Maven: org.springframework:spring-context:5.0.9.RELEASE" level="project" /> | ||
80 | + <orderEntry type="library" name="Maven: org.springframework:spring-context-support:5.0.9.RELEASE" level="project" /> | ||
81 | + <orderEntry type="library" name="Maven: com.sun.mail:javax.mail:1.6.2" level="project" /> | ||
82 | + <orderEntry type="library" name="Maven: javax.activation:activation:1.1" level="project" /> | ||
83 | + <orderEntry type="library" name="Maven: org.springframework.session:spring-session-core:2.0.6.RELEASE" level="project" /> | ||
84 | + <orderEntry type="library" name="Maven: org.springframework:spring-jcl:5.0.9.RELEASE" level="project" /> | ||
85 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:2.0.5.RELEASE" level="project" /> | ||
86 | + <orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring5:3.0.9.RELEASE" level="project" /> | ||
87 | + <orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf:3.0.9.RELEASE" level="project" /> | ||
88 | + <orderEntry type="library" name="Maven: org.attoparser:attoparser:2.0.4.RELEASE" level="project" /> | ||
89 | + <orderEntry type="library" name="Maven: org.unbescape:unbescape:1.1.5.RELEASE" level="project" /> | ||
90 | + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> | ||
91 | + <orderEntry type="library" name="Maven: org.thymeleaf.extras:thymeleaf-extras-java8time:3.0.1.RELEASE" level="project" /> | ||
92 | + <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.0.5.RELEASE" level="project" /> | ||
93 | + <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.0.5.RELEASE" level="project" /> | ||
94 | + <orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.0.5.RELEASE" level="project" /> | ||
95 | + <orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" /> | ||
96 | + <orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.3" level="project" /> | ||
97 | + <orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.2" level="project" /> | ||
98 | + <orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.4" level="project" /> | ||
99 | + <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" /> | ||
100 | + <orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.9.1" level="project" /> | ||
101 | + <orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.15.0" level="project" /> | ||
102 | + <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.7.11" level="project" /> | ||
103 | + <orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.7.11" level="project" /> | ||
104 | + <orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" /> | ||
105 | + <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | ||
106 | + <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" /> | ||
107 | + <orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" /> | ||
108 | + <orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" /> | ||
109 | + <orderEntry type="library" name="Maven: org.springframework:spring-core:5.0.9.RELEASE" level="project" /> | ||
110 | + <orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.9.RELEASE" level="project" /> | ||
111 | + <orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.5.1" level="project" /> | ||
112 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-devtools:2.0.5.RELEASE" level="project" /> | ||
113 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.0.5.RELEASE" level="project" /> | ||
114 | + <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.5.RELEASE" level="project" /> | ||
115 | + </component> | ||
116 | +</module> | ||
0 | \ No newline at end of file | 117 | \ No newline at end of file |