Skip to content

Commit

Permalink
Merge pull request #62 from yinjihuan/encrypt1.2.1
Browse files Browse the repository at this point in the history
Encrypt1.2.1
  • Loading branch information
yinjihuan authored Jun 17, 2020
2 parents 873ce6a + 7ea03cf commit 0207676
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 25 deletions.
28 changes: 27 additions & 1 deletion monkey-api-encrypt-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.cxytiandi</groupId>
<artifactId>monkey-api-encrypt-core</artifactId>
<version>1.2.RELEASE</version>
<version>1.2.1.RELEASE</version>
<packaging>jar</packaging>

<name>monkey-api-encrypt-core</name>
Expand Down Expand Up @@ -103,6 +103,12 @@
<version>2.0.6.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>2.0.6.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -160,6 +166,26 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.cxytiandi.encrypt.core;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.springframework.boot.context.properties.ConfigurationProperties;

Expand Down Expand Up @@ -93,23 +96,15 @@ public void setKey(String key) {
}

public List<String> getResponseEncryptUriList() {
// 配置了注解则用注解获取的URI
if (ApiEncryptDataInit.responseEncryptUriList.size() > 0) {
return ApiEncryptDataInit.responseEncryptUriList;
}
return responseEncryptUriList;
return Stream.of(responseEncryptUriList, ApiEncryptDataInit.responseEncryptUriList).flatMap(Collection::stream).collect(Collectors.toList());
}

public void setResponseEncryptUriList(List<String> responseEncryptUriList) {
this.responseEncryptUriList = responseEncryptUriList;
}

public List<String> getRequestDecryptUriList() {
// 配置了注解则用注解获取的URI
if (ApiEncryptDataInit.requestDecryptUriList.size() > 0) {
return ApiEncryptDataInit.requestDecryptUriList;
}
return requestDecryptUriList;
return Stream.of(requestDecryptUriList, ApiEncryptDataInit.requestDecryptUriList).flatMap(Collection::stream).collect(Collectors.toList());
}

public void setRequestDecryptUriList(List<String> requestDecryptUriList) {
Expand Down Expand Up @@ -149,23 +144,17 @@ public int getOrder() {
}

public List<String> getResponseEncryptUriIgnoreList() {
// 配置了注解则用注解获取的URI
if (ApiEncryptDataInit.responseEncryptUriIgnoreList.size() > 0) {
return ApiEncryptDataInit.responseEncryptUriIgnoreList;
}
return responseEncryptUriIgnoreList;
// 配置和注解两种方式合并
return Stream.of(responseEncryptUriIgnoreList, ApiEncryptDataInit.responseEncryptUriIgnoreList).flatMap(Collection::stream).collect(Collectors.toList());
}

public void setResponseEncryptUriIgnoreList(List<String> responseEncryptUriIgnoreList) {
this.responseEncryptUriIgnoreList = responseEncryptUriIgnoreList;
}

public List<String> getRequestDecryptUriIgnoreList() {
// 配置了注解则用注解获取的URI
if (ApiEncryptDataInit.requestDecryptUriIgnoreList.size() > 0) {
return ApiEncryptDataInit.requestDecryptUriIgnoreList;
}
return requestDecryptUriIgnoreList;
// 配置和注解两种方式合并
return Stream.of(requestDecryptUriIgnoreList, ApiEncryptDataInit.requestDecryptUriIgnoreList).flatMap(Collection::stream).collect(Collectors.toList());
}

public void setRequestDecryptUriIgnoreList(List<String> requestDecyptUriIgnoreList) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cxytiandi.encrypt.springboot.autoconfigure;

import com.cxytiandi.encrypt.springboot.endpoint.EncryptEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down Expand Up @@ -53,4 +54,9 @@ public FilterRegistrationBean filterRegistration() {
public ApiEncryptDataInit apiEncryptDataInit() {
return new ApiEncryptDataInit();
}

@Bean
public EncryptEndpoint encryptEndpoint() {
return new EncryptEndpoint();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cxytiandi.encrypt.springboot.endpoint;

import com.cxytiandi.encrypt.core.EncryptionConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;

import java.util.HashMap;
import java.util.Map;

/**
* 加解密配置信息端点
*
* @author yinjihuan http://cxytiandi.com/about
*/
@Endpoint(id = "encrypt-config")
public class EncryptEndpoint {

@Autowired
private EncryptionConfig encryptionConfig;

@ReadOperation
public Map<String, Object> encryptConfig() {
Map<String, Object> data = new HashMap<>();
data.put("responseEncryptUriList", encryptionConfig.getResponseEncryptUriList());
data.put("responseEncryptUriIgnoreList", encryptionConfig.getResponseEncryptUriIgnoreList());
data.put("requestDecryptUriList", encryptionConfig.getRequestDecryptUriList());
data.put("requestDecryptUriIgnoreList", encryptionConfig.getRequestDecryptUriIgnoreList());
return data;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,20 @@ private String getApiUri(Class<?> clz, Method method) {
uri.append(formatUri(deleteMapping.value()[0]));

} else if (requestMapping != null) {
RequestMethod m = requestMapping.method()[0];
methodType = m.name().toLowerCase() + ":";
RequestMethod requestMethod = RequestMethod.GET;
if (requestMapping.method().length > 0) {
requestMethod = requestMapping.method()[0];
}

methodType = requestMethod.name().toLowerCase() + ":";
uri.append(formatUri(requestMapping.value()[0]));

}

if (StringUtils.hasText(this.contextPath) && !"/".equals(this.contextPath)) {
if (this.contextPath.endsWith("/")) {
this.contextPath = this.contextPath.substring(0, this.contextPath.length() - 1);
}
return methodType + this.contextPath + uri.toString();
}

Expand Down
6 changes: 5 additions & 1 deletion monkey-api-encrypt-springboot-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.cxytiandi</groupId>
<artifactId>monkey-api-encrypt-core</artifactId>
<version>1.2.RELEASE</version>
<version>1.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -44,6 +44,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ server.port=8011
#server.servlet.context-path=/example
#logging.level.com.cxytiandi.encrypt=DEBUG

management.endpoints.web.exposure.include=*

spring.freemarker.cache=true
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
Expand Down
2 changes: 1 addition & 1 deletion monkey-api-encrypt-springmvc-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>com.cxytiandi</groupId>
<artifactId>monkey-api-encrypt-core</artifactId>
<version>1.2.RELEASE</version>
<version>1.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down

0 comments on commit 0207676

Please sign in to comment.