Skip to content

Commit

Permalink
Merge pull request #25 from yinjihuan/encrypt1.1
Browse files Browse the repository at this point in the history
Encrypt1.1
  • Loading branch information
yinjihuan authored Mar 1, 2019
2 parents 4227c96 + 27f946d commit f86384a
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 20 deletions.
10 changes: 7 additions & 3 deletions encrypt-core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
4 changes: 2 additions & 2 deletions encrypt-core/.project
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class EncryptionFilter implements Filter {

private EncryptionConfig encryptionConfig;

private EncryptAlgorithm encryptAlgorithm = new AesEncryptAlgorithm();;
private EncryptAlgorithm encryptAlgorithm = new AesEncryptAlgorithm();

public EncryptionFilter() {
this.encryptionConfig = new EncryptionConfig();
Expand Down Expand Up @@ -137,6 +137,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
try {
responeData = encryptAlgorithm.encrypt(responeData, encryptionConfig.getKey());
logger.debug("EncryptResponeData: {}", responeData);
response.setContentLength(responeData.length());
response.setCharacterEncoding(encryptionConfig.getResponseCharset());
out = response.getOutputStream();
out.write(responeData.getBytes(encryptionConfig.getResponseCharset()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cxytiandi.encrypt.algorithm.EncryptAlgorithm;
import com.cxytiandi.encrypt.core.EncryptionConfig;
import com.cxytiandi.encrypt.core.EncryptionFilter;
import com.cxytiandi.encrypt.springboot.init.ApiEncryptDataInit;
Expand All @@ -28,19 +29,22 @@ public class EncryptAutoConfiguration {
@Autowired
private EncryptionConfig encryptionConfig;

@Autowired(required=false)
private EncryptAlgorithm encryptAlgorithm;

/**
* 不要用泛型注册Filter,泛型在Spring Boot 2.x版本中才有
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@Bean
public FilterRegistrationBean filterRegistration() {
EncryptionConfig config = new EncryptionConfig();
config.setKey(encryptionConfig.getKey());
config.setRequestDecyptUriList(encryptionConfig.getRequestDecyptUriList());
config.setResponseEncryptUriList(encryptionConfig.getResponseEncryptUriList());
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(new EncryptionFilter(config));
if (encryptAlgorithm != null) {
registration.setFilter(new EncryptionFilter(encryptionConfig, encryptAlgorithm));
} else {
registration.setFilter(new EncryptionFilter(encryptionConfig));
}
registration.addUrlPatterns(encryptionConfig.getUrlPatterns());
registration.setName("EncryptionFilter");
registration.setOrder(encryptionConfig.getOrder());
Expand Down
8 changes: 6 additions & 2 deletions encrypt-springboot-example/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
4 changes: 2 additions & 2 deletions encrypt-springboot-example/.project
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.8
2 changes: 1 addition & 1 deletion encrypt-springboot-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>com.cxytiandi</groupId>
<groupId>com.cxytiandi</groupId>
<artifactId>monkey-api-encrypt-core</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cxytiandi.encrypt_springboot_example.algorithm;

import org.springframework.stereotype.Component;

import com.cxytiandi.encrypt.algorithm.EncryptAlgorithm;
import com.cxytiandi.encrypt_springboot_example.util.RSAUtils;
/**
Expand All @@ -12,6 +14,7 @@
* @about http://cxytiandi.com/about
*
*/
//@Component
public class RsaEncryptAlgorithm implements EncryptAlgorithm {

public String encrypt(String content, String encryptKey) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@RestController
public class UserController {


@Encrypt
@GetMapping("/encryptStr")
public String encryptStr() {
return "加密字符串";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
server.port=8011
logging.level.com.cxytiandi.encrypt=DEBUG

spring.freemarker.cache=true
Expand Down

0 comments on commit f86384a

Please sign in to comment.