Skip to content

Commit f86384a

Browse files
authoredMar 1, 2019
Merge pull request #25 from yinjihuan/encrypt1.1
Encrypt1.1
2 parents 4227c96 + 27f946d commit f86384a

File tree

12 files changed

+39
-20
lines changed

12 files changed

+39
-20
lines changed
 

‎encrypt-core/.classpath

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@
2626
<attribute name="m2e-apt" value="true"/>
2727
</attributes>
2828
</classpathentry>
29+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
30+
<attributes>
31+
<attribute name="maven.pomderived" value="true"/>
32+
</attributes>
33+
</classpathentry>
2934
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
3035
<attributes>
31-
<attribute name="ignore_optional_problems" value="true"/>
32-
<attribute name="test" value="true"/>
3336
<attribute name="optional" value="true"/>
3437
<attribute name="maven.pomderived" value="true"/>
38+
<attribute name="ignore_optional_problems" value="true"/>
3539
<attribute name="m2e-apt" value="true"/>
40+
<attribute name="test" value="true"/>
3641
</attributes>
3742
</classpathentry>
38-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
3943
<classpathentry kind="output" path="target/classes"/>
4044
</classpath>

‎encrypt-core/.project

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
</arguments>
1212
</buildCommand>
1313
<buildCommand>
14-
<name>org.eclipse.m2e.core.maven2Builder</name>
14+
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
1515
<arguments>
1616
</arguments>
1717
</buildCommand>
1818
<buildCommand>
19-
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
19+
<name>org.eclipse.m2e.core.maven2Builder</name>
2020
<arguments>
2121
</arguments>
2222
</buildCommand>

‎encrypt-core/src/main/java/com/cxytiandi/encrypt/core/EncryptionFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class EncryptionFilter implements Filter {
3535

3636
private EncryptionConfig encryptionConfig;
3737

38-
private EncryptAlgorithm encryptAlgorithm = new AesEncryptAlgorithm();;
38+
private EncryptAlgorithm encryptAlgorithm = new AesEncryptAlgorithm();
3939

4040
public EncryptionFilter() {
4141
this.encryptionConfig = new EncryptionConfig();
@@ -137,6 +137,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
137137
try {
138138
responeData = encryptAlgorithm.encrypt(responeData, encryptionConfig.getKey());
139139
logger.debug("EncryptResponeData: {}", responeData);
140+
response.setContentLength(responeData.length());
140141
response.setCharacterEncoding(encryptionConfig.getResponseCharset());
141142
out = response.getOutputStream();
142143
out.write(responeData.getBytes(encryptionConfig.getResponseCharset()));

‎encrypt-core/src/main/java/com/cxytiandi/encrypt/springboot/autoconfigure/EncryptAutoConfiguration.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
99

10+
import com.cxytiandi.encrypt.algorithm.EncryptAlgorithm;
1011
import com.cxytiandi.encrypt.core.EncryptionConfig;
1112
import com.cxytiandi.encrypt.core.EncryptionFilter;
1213
import com.cxytiandi.encrypt.springboot.init.ApiEncryptDataInit;
@@ -28,19 +29,22 @@ public class EncryptAutoConfiguration {
2829
@Autowired
2930
private EncryptionConfig encryptionConfig;
3031

32+
@Autowired(required=false)
33+
private EncryptAlgorithm encryptAlgorithm;
34+
3135
/**
3236
* 不要用泛型注册Filter,泛型在Spring Boot 2.x版本中才有
3337
* @return
3438
*/
3539
@SuppressWarnings({ "rawtypes", "unchecked" })
3640
@Bean
3741
public FilterRegistrationBean filterRegistration() {
38-
EncryptionConfig config = new EncryptionConfig();
39-
config.setKey(encryptionConfig.getKey());
40-
config.setRequestDecyptUriList(encryptionConfig.getRequestDecyptUriList());
41-
config.setResponseEncryptUriList(encryptionConfig.getResponseEncryptUriList());
4242
FilterRegistrationBean registration = new FilterRegistrationBean();
43-
registration.setFilter(new EncryptionFilter(config));
43+
if (encryptAlgorithm != null) {
44+
registration.setFilter(new EncryptionFilter(encryptionConfig, encryptAlgorithm));
45+
} else {
46+
registration.setFilter(new EncryptionFilter(encryptionConfig));
47+
}
4448
registration.addUrlPatterns(encryptionConfig.getUrlPatterns());
4549
registration.setName("EncryptionFilter");
4650
registration.setOrder(encryptionConfig.getOrder());

‎encrypt-springboot-example/.classpath

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
<attribute name="test" value="true"/>
1414
</attributes>
1515
</classpathentry>
16-
<classpathentry kind="src" path="src/main/resources"/>
17-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
16+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
1822
<attributes>
1923
<attribute name="maven.pomderived" value="true"/>
2024
</attributes>

‎encrypt-springboot-example/.project

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
</arguments>
1212
</buildCommand>
1313
<buildCommand>
14-
<name>org.eclipse.m2e.core.maven2Builder</name>
14+
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
1515
<arguments>
1616
</arguments>
1717
</buildCommand>
1818
<buildCommand>
19-
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
19+
<name>org.eclipse.m2e.core.maven2Builder</name>
2020
<arguments>
2121
</arguments>
2222
</buildCommand>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
eclipse.preferences.version=1
22
encoding//src/main/java=UTF-8
3+
encoding//src/main/resources=UTF-8
34
encoding//src/test/java=UTF-8
45
encoding/<project>=UTF-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3-
org.eclipse.jdt.core.compiler.compliance=1.5
2+
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
45
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
56
org.eclipse.jdt.core.compiler.processAnnotations=disabled
67
org.eclipse.jdt.core.compiler.release=disabled
7-
org.eclipse.jdt.core.compiler.source=1.5
8+
org.eclipse.jdt.core.compiler.source=1.8

‎encrypt-springboot-example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<artifactId>jackson-dataformat-xml</artifactId>
3333
</dependency>
3434
<dependency>
35-
<groupId>com.cxytiandi</groupId>
35+
<groupId>com.cxytiandi</groupId>
3636
<artifactId>monkey-api-encrypt-core</artifactId>
3737
<version>1.1-SNAPSHOT</version>
3838
</dependency>

‎encrypt-springboot-example/src/main/java/com/cxytiandi/encrypt_springboot_example/algorithm/RsaEncryptAlgorithm.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.cxytiandi.encrypt_springboot_example.algorithm;
22

3+
import org.springframework.stereotype.Component;
4+
35
import com.cxytiandi.encrypt.algorithm.EncryptAlgorithm;
46
import com.cxytiandi.encrypt_springboot_example.util.RSAUtils;
57
/**
@@ -12,6 +14,7 @@
1214
* @about http://cxytiandi.com/about
1315
*
1416
*/
17+
//@Component
1518
public class RsaEncryptAlgorithm implements EncryptAlgorithm {
1619

1720
public String encrypt(String content, String encryptKey) throws Exception {

‎encrypt-springboot-example/src/main/java/com/cxytiandi/encrypt_springboot_example/controller/UserController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@RestController
1616
public class UserController {
1717

18-
18+
@Encrypt
1919
@GetMapping("/encryptStr")
2020
public String encryptStr() {
2121
return "加密字符串";

‎encrypt-springboot-example/src/main/resources/application.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
server.port=8011
12
logging.level.com.cxytiandi.encrypt=DEBUG
23

34
spring.freemarker.cache=true

0 commit comments

Comments
 (0)
Please sign in to comment.