-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuridong
committed
Jun 5, 2022
0 parents
commit 9f43766
Showing
24 changed files
with
1,136 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,125 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>cn.archliu</groupId> | ||
<artifactId>archliu-common-starter</artifactId> | ||
<version>1.0.1.RELEASE</version> | ||
<packaging>jar</packaging> | ||
<description>archliu's tools</description> | ||
|
||
<name>archliu-common-starter</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<projectlombok.version>1.18.22</projectlombok.version> | ||
<spring.boot.version>2.6.3</spring.boot.version> | ||
<hutool.version>5.8.0.M3</hutool.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
<!-- 在META-INF中生成属性配置的元数据给IDE,用于编辑属性文件时的代码提示,可选--> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
<version>2.5.4</version> | ||
</dependency> | ||
<!-- 在META-INF中生成忽略配置元数据,加快自动配置的初始化速度,可选 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${projectlombok.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>cn.hutool</groupId> | ||
<artifactId>hutool-all</artifactId> | ||
<version>${hutool.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
</configuration> | ||
</plugin> | ||
<!-- 要将源码放上去,需要加入这个插件 --> | ||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.0.1</version> | ||
<configuration> | ||
<attach>true</attach> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
<extensions> | ||
<extension> | ||
<groupId>org.apache.maven.wagon</groupId> | ||
<artifactId>wagon-ssh</artifactId> | ||
<version>2.10</version> | ||
</extension> | ||
</extensions> | ||
</build> | ||
|
||
<repositories> | ||
<repository> | ||
<id>archliu_repository</id> | ||
<url>http://192.168.31.106/maven_repository/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<distributionManagement> | ||
<repository> | ||
<id>archliu_repository</id> | ||
<url>scp://192.168.31.106/home/maven/repository/</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
</project> |
49 changes: 49 additions & 0 deletions
49
src/main/java/cn/archliu/common/config/ArchAutoConfigure.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,49 @@ | ||
package cn.archliu.common.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import cn.archliu.common.config.ArchComProperties.SecurityProperties; | ||
import cn.archliu.common.interceptor.AuthInterceptor; | ||
import cn.hutool.core.codec.Base64; | ||
import cn.hutool.crypto.asymmetric.RSA; | ||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm; | ||
import cn.hutool.crypto.symmetric.SymmetricCrypto; | ||
|
||
/** | ||
* @Author: Arch | ||
* @Date: 2022-03-29 21:40:14 | ||
* @Description: 自动装配配置类 | ||
*/ | ||
@Configuration | ||
@EnableConfigurationProperties({ ArchComProperties.class }) | ||
@ComponentScan(basePackages = { "cn.archliu.common" }) | ||
public class ArchAutoConfigure { | ||
|
||
@Autowired | ||
private ArchComProperties archComProperties; | ||
|
||
@Bean(name = "archRSA") | ||
public RSA archRSA() { | ||
SecurityProperties securityProperties = archComProperties.getSecurityProperties(); | ||
return new RSA(securityProperties.getPrivateKey(), securityProperties.getPublicKey()); | ||
} | ||
|
||
@Bean(name = "archAES") | ||
public SymmetricCrypto symmetricCrypto() { | ||
SecurityProperties securityProperties = archComProperties.getSecurityProperties(); | ||
return new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(securityProperties.getAesKey())); | ||
} | ||
|
||
@Bean(name = "archInterceptorConfig") | ||
@ConditionalOnProperty(prefix = "archliu.common.security-properties", name = "security-enabled", havingValue = "true", matchIfMissing = false) | ||
public ArchInterceptorConfig archInterceptorConfig(AuthInterceptor authInterceptor) { | ||
SecurityProperties securityProperties = archComProperties.getSecurityProperties(); | ||
return new ArchInterceptorConfig(authInterceptor, securityProperties.getAuthPathPattern()); | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/cn/archliu/common/config/ArchComProperties.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,76 @@ | ||
package cn.archliu.common.config; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
@Data | ||
@Component | ||
@ConfigurationProperties(prefix = "archliu.common") | ||
public class ArchComProperties { | ||
|
||
/** 是否添加统一异常处理类 */ | ||
private boolean addAdvice = Boolean.TRUE; | ||
|
||
/** 是否打印接口请求日志 */ | ||
private boolean apiLog = Boolean.FALSE; | ||
|
||
/** 跨域配置 */ | ||
private CORSProperties corsProperties = new CORSProperties(); | ||
|
||
/** 安全配置 */ | ||
private SecurityProperties securityProperties = new SecurityProperties(); | ||
|
||
@Data | ||
@Accessors(chain = true) | ||
public static class CORSProperties { | ||
|
||
/** 是否开启跨域 */ | ||
private boolean corsOrigin = Boolean.FALSE; | ||
|
||
private String credentials = "true"; | ||
|
||
private String origin = "*"; | ||
|
||
private String methods = "GET, POST, DELETE, PUT"; | ||
|
||
private String headers = "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN,X-ArchToken"; | ||
} | ||
|
||
@SuppressWarnings({ "squid:S1075" }) | ||
@Data | ||
@Accessors(chain = true) | ||
public static class SecurityProperties { | ||
|
||
/** 是否开启鉴权 */ | ||
private boolean securityEnabled = Boolean.FALSE; | ||
|
||
/** RSA私钥 */ | ||
private String privateKey = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJJsG0ikcKl/JlTay4LPt3zWtgjIPmuWvLrV/V6imC97eQglGxZ/uJa6gvX2g+LqHZU+lv+AybjMewnif0DDVYwmZVcNMsPRiYVCDzM7xpub1nTQZvvTb6aAW9U9D7FysAmzf40Co59esQ0c9FOS6ZPODq6Crp9CRLFQtjODQW/FAgMBAAECgYAsMBfjykx9unOU9BqqtYkIUbvJ1rSPv4PhVqcKIkOPQNH71UbheVX5lvviwqx2lHStD6B+Jx25eWxARWxl3Q05s5CVv6uMSCSmnxbzHLoOIpf7ymOHtxvGTUMGGOHHiqBV4/57yA3TfTebD166L3ICe7rpM1b+0dAjX7U9IqbGWQJBAMZPYyYHDg5sNNWXj8LaY3zkcjXaFF2LIZuDKy1RuhMWIvHIv2ZluS10bS2cSQByL8xp7EHYRSYMCWmi2vz/0LcCQQC9BIN4kC3va+yUXYP/XdPgbQWaET0qTuXawk5RZNtHyVIA87gQqYtxlB7SdNVy9X0lesHp2nCsbWYf99EOrw9jAkBI0BdIfCimFQblMewAEG2dCsgAi90UZ6RkVCoDTtGydltISXw1Xb47OVdo+sw3FLYGKRItLvpcuOiv17LuWANLAkBzK1jgERmsFFpmXESdSJJc4JDVO0PFj6VGEbaeqZFiwCwTIG062dN5NQNCwKV+Ek5ak92rm8mjhlT/jYP4Knp5AkAxB0uModtRfKFU29yOh1q2EHYzPY7tkqEAq/1ciTIWt8E4nTg8Du2R4phPln+JnZKS5FXxiRKT0/YFA5S0Ggin"; | ||
|
||
/** RSA公钥 */ | ||
private String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCSbBtIpHCpfyZU2suCz7d81rYIyD5rlry61f1eopgve3kIJRsWf7iWuoL19oPi6h2VPpb/gMm4zHsJ4n9Aw1WMJmVXDTLD0YmFQg8zO8abm9Z00Gb702+mgFvVPQ+xcrAJs3+NAqOfXrENHPRTkumTzg6ugq6fQkSxULYzg0FvxQIDAQAB"; | ||
|
||
/** aes base64 的 key */ | ||
private String aesKey = "pqYtPHFARCKgIoahAQa5pw=="; | ||
|
||
/** 暴露给外网需要鉴权的 url; 服务器内网接口不做鉴权,仅提供给其他服务器调用 */ | ||
private String authPathPattern = "/api/**"; | ||
|
||
/** 无需登录即可访问的 url 前缀 */ | ||
private String noLoginUrlPrefix = "/api/noLogin"; | ||
|
||
/** 管理员请求 url 前缀 */ | ||
private String adminUrlPrefix = "/api/admin"; | ||
|
||
/** token 失效时间,单位分钟 */ | ||
private long tokenExpireTime = 30; | ||
|
||
/** token 续签时间,单位分钟 */ | ||
private long tokenRenewTime; | ||
|
||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/cn/archliu/common/config/ArchInterceptorConfig.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,31 @@ | ||
package cn.archliu.common.config; | ||
|
||
import org.springframework.core.Ordered; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import cn.archliu.common.interceptor.AuthInterceptor; | ||
|
||
/** | ||
* @Author: Arch | ||
* @Date: 2022-05-09 15:32:59 | ||
* @Description: 拦截器注册器 | ||
*/ | ||
public class ArchInterceptorConfig implements WebMvcConfigurer { | ||
|
||
private AuthInterceptor authInterceptor; | ||
|
||
/** 需要鉴权的 url */ | ||
private String authPathPattern; | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(authInterceptor).addPathPatterns(authPathPattern).order(Ordered.HIGHEST_PRECEDENCE); | ||
} | ||
|
||
public ArchInterceptorConfig(AuthInterceptor authInterceptor, String authPathPattern) { | ||
this.authInterceptor = authInterceptor; | ||
this.authPathPattern = authPathPattern; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/cn/archliu/common/constants/AuthConstant.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 cn.archliu.common.constants; | ||
|
||
/** | ||
* @Author: Arch | ||
* @Date: 2022-05-09 15:02:27 | ||
* @Description: 权限相关的常量 | ||
*/ | ||
public final class AuthConstant { | ||
|
||
/** cookie 的 name */ | ||
public static final String ARCH_TOKEN = "ArchToken"; | ||
|
||
/** header 的 name */ | ||
public static final String X_ARCH_TOKEN = "X-ArchToken"; | ||
|
||
/** request 请求域中设置的登录用户信息 */ | ||
public static final String LOGIN_USER_INFO = "loginUserInfo"; | ||
|
||
/** 请求域中设置的客户端 IP */ | ||
public static final String CLIENT_IP = "clientIp"; | ||
|
||
private AuthConstant() { | ||
} | ||
|
||
} |
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,38 @@ | ||
package cn.archliu.common.entity; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.Data; | ||
import lombok.experimental.Accessors; | ||
|
||
/** | ||
* @Author: Arch | ||
* @Date: 2022-05-09 14:27:08 | ||
* @Description: 登录用户信息 | ||
*/ | ||
@Data | ||
@Accessors(chain = true) | ||
public class LoginUser { | ||
|
||
/** 帐号名 */ | ||
private String UserName; | ||
|
||
/** 昵称 */ | ||
private String nickName; | ||
|
||
/** 是否是管理员 */ | ||
private Boolean isAdmin = false; | ||
|
||
/** token */ | ||
private String token; | ||
|
||
/** token 创建时间 */ | ||
private LocalDateTime tokenCreateTime; | ||
|
||
/** 客户端 IP */ | ||
private String clientIp; | ||
|
||
/** 用户信息 */ | ||
private Object userInfo; | ||
|
||
} |
Oops, something went wrong.