-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from yinjihuan/encrypt1.1
支持spring boot配置
- Loading branch information
Showing
48 changed files
with
798 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# maven ignore | ||
target/ | ||
bin/ | ||
*.jar | ||
*.war | ||
*.zip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# maven ignore | ||
target/ | ||
*.jar | ||
*.war | ||
*.zip | ||
*.tar | ||
*.tar.gz | ||
|
||
# eclipse ignore | ||
.settings/ | ||
.project | ||
.classpath | ||
|
||
# idea ignore | ||
.idea/ | ||
*.ipr | ||
*.iml | ||
*.iws | ||
|
||
# temp ignore | ||
*.log | ||
*.cache | ||
*.diff | ||
*.patch | ||
*.tmp | ||
*.java~ | ||
*.properties~ | ||
*.xml~ | ||
|
||
# system ignore | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ypt-core/src/main/java/com/cxytiandi/encrypt/springboot/HttpMethodTypePrefixConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.cxytiandi.encrypt.springboot; | ||
|
||
public class HttpMethodTypePrefixConstant { | ||
|
||
public static final String GET = "get:"; | ||
|
||
public static final String POST = "post:"; | ||
|
||
public static final String DELETE = "delete:"; | ||
|
||
public static final String PUT = "put:"; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
encrypt-core/src/main/java/com/cxytiandi/encrypt/springboot/annotation/Decrypt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.cxytiandi.encrypt.springboot.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 解密注解 | ||
* | ||
* <p>加了此注解的接口将进行数据解密操作<p> | ||
* | ||
* @author yinjihuan | ||
* | ||
* @about http://cxytiandi.com/about | ||
* | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface Decrypt { | ||
|
||
String value() default ""; | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
encrypt-core/src/main/java/com/cxytiandi/encrypt/springboot/annotation/EnableEncrypt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.cxytiandi.encrypt.springboot.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import com.cxytiandi.encrypt.springboot.autoconfigure.EncryptAutoConfiguration; | ||
|
||
/** | ||
* 启用加密Starter | ||
* | ||
* <p>在Spring Boot启动类上加上此注解<p> | ||
* | ||
* <pre class="code"> | ||
* @SpringBootApplication | ||
* @EnableEncrypt | ||
* public class App { | ||
* public static void main(String[] args) { | ||
* SpringApplication.run(App.class, args); | ||
* } | ||
* } | ||
* <pre> | ||
* | ||
* @author yinjihuan | ||
* | ||
* @about http://cxytiandi.com/about | ||
*/ | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Inherited | ||
@Import({EncryptAutoConfiguration.class}) | ||
public @interface EnableEncrypt { | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
encrypt-core/src/main/java/com/cxytiandi/encrypt/springboot/annotation/Encrypt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.cxytiandi.encrypt.springboot.annotation; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* 加密注解 | ||
* | ||
* <p>加了此注解的接口将进行数据加密操作<p> | ||
* | ||
* @author yinjihuan | ||
* | ||
* @about http://cxytiandi.com/about | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
public @interface Encrypt { | ||
|
||
String value() default ""; | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...rc/main/java/com/cxytiandi/encrypt/springboot/autoconfigure/EncryptAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.cxytiandi.encrypt.springboot.autoconfigure; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.cxytiandi.encrypt.core.EncryptionConfig; | ||
import com.cxytiandi.encrypt.core.EncryptionFilter; | ||
import com.cxytiandi.encrypt.springboot.init.ApiEncryptDataInit; | ||
|
||
|
||
/** | ||
* 加解密自动配置 | ||
* | ||
* @author yinjihuan | ||
* | ||
* @about http://cxytiandi.com/about | ||
* | ||
*/ | ||
@Configuration | ||
@EnableAutoConfiguration | ||
@EnableConfigurationProperties(EncryptionConfig.class) | ||
public class EncryptAutoConfiguration { | ||
|
||
@Autowired | ||
private EncryptionConfig encryptionConfig; | ||
|
||
/** | ||
* 不要用泛型注册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)); | ||
registration.addUrlPatterns(encryptionConfig.getUrlPatterns()); | ||
registration.setName("EncryptionFilter"); | ||
registration.setOrder(encryptionConfig.getOrder()); | ||
return registration; | ||
} | ||
|
||
@Bean | ||
public ApiEncryptDataInit apiEncryptDataInit() { | ||
return new ApiEncryptDataInit(); | ||
} | ||
} |
Oops, something went wrong.