Skip to content

Commit 2e9092b

Browse files
committed
add #40
1 parent a54c8e3 commit 2e9092b

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<maven.gpg.plugin>3.1.0</maven.gpg.plugin>
3333
<codingapi.framework.version>${project.version}</codingapi.framework.version>
3434
<fastjson.version>2.0.42</fastjson.version>
35-
<jsonwebtoken.jjwt.version>0.12.3</jsonwebtoken.jjwt.version>
35+
<jsonwebtoken.jjwt.version>0.12.5</jsonwebtoken.jjwt.version>
3636
<commons-io.version>2.15.0</commons-io.version>
3737
<commons-dbutils.version>1.8.1</commons-dbutils.version>
3838
<commons-text.version>1.11.0</commons-text.version>

springboot-starter-security/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@
3333
<dependency>
3434
<groupId>io.jsonwebtoken</groupId>
3535
<artifactId>jjwt-api</artifactId>
36+
<scope>provided</scope>
3637
</dependency>
3738

3839
<dependency>
3940
<groupId>io.jsonwebtoken</groupId>
4041
<artifactId>jjwt-impl</artifactId>
42+
<scope>provided</scope>
4143
</dependency>
4244

4345
<dependency>
4446
<groupId>io.jsonwebtoken</groupId>
4547
<artifactId>jjwt-jackson</artifactId>
48+
<scope>provided</scope>
4649
</dependency>
4750

4851
<dependency>

springboot-starter-security/src/main/java/com/codingapi/springboot/security/gateway/TokenGateway.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ public interface TokenGateway {
66

77
Token create(String username, String password, List<String> authorities, String extra);
88

9+
default Token create(String username, String password, List<String> authorities) {
10+
return create(username, password, authorities, null);
11+
}
12+
13+
default Token create(String username, List<String> authorities) {
14+
return create(username, null, authorities, null);
15+
}
16+
17+
default Token create(String username, List<String> authorities, String extra) {
18+
return create(username, null, authorities, extra);
19+
}
20+
921
Token parser(String sign);
1022

1123
}

springboot-starter-security/src/main/java/com/codingapi/springboot/security/jwt/JWTTokenGatewayImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public JWTTokenGatewayImpl(SecurityJWTProperties properties) {
1515

1616
@Override
1717
public Token create(String username, String password, List<String> authorities, String extra) {
18-
return jwt.create(username, authorities, extra);
18+
return jwt.create(username, password, authorities, extra);
1919
}
2020

2121
@Override

springboot-starter-security/src/test/java/com/codingapi/springboot/security/jwt/TokenTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.codingapi.springboot.security.exception.TokenExpiredException;
44
import com.codingapi.springboot.security.gateway.Token;
5+
import com.codingapi.springboot.security.gateway.TokenGateway;
56
import org.junit.jupiter.api.Test;
67
import org.springframework.beans.factory.annotation.Autowired;
78
import org.springframework.boot.test.context.SpringBootTest;
@@ -15,18 +16,18 @@
1516
class TokenTest {
1617

1718
@Autowired
18-
private Jwt jwt;
19+
private TokenGateway tokenGateway;
1920

2021
@Test
2122
void verify1() throws TokenExpiredException {
2223
String username = "admin";
2324
String iv = "123456";
2425
List<String> authorities = Collections.singletonList("ADMIN");
2526

26-
Token token =jwt.create(username,iv,authorities);
27+
Token token =tokenGateway.create(username,iv,authorities);
2728
token.verify();
2829

29-
Token data = jwt.parser(token.getToken());
30+
Token data = tokenGateway.parser(token.getToken());
3031
assertEquals(data.decodeIv(),iv);
3132
assertEquals(data.getAuthorities(),authorities);
3233
}
@@ -36,10 +37,10 @@ void verify2() throws TokenExpiredException {
3637
String username = "admin";
3738
List<String> authorities = Collections.singletonList("ADMIN");
3839

39-
Token token =jwt.create(username,authorities);
40+
Token token =tokenGateway.create(username,authorities);
4041
token.verify();
4142

42-
Token data = jwt.parser(token.getToken());
43+
Token data = tokenGateway.parser(token.getToken());
4344
assertEquals(data.getUsername(),username);
4445
assertEquals(data.getAuthorities(),authorities);
4546
}
@@ -53,10 +54,10 @@ void verify3() throws TokenExpiredException {
5354
String extra = testVO.toJson();
5455
List<String> authorities = Collections.singletonList("ADMIN");
5556

56-
Token token =jwt.create(username,authorities,extra);
57+
Token token =tokenGateway.create(username,authorities,extra);
5758
token.verify();
5859

59-
Token data = jwt.parser(token.getToken());
60+
Token data = tokenGateway.parser(token.getToken());
6061
assertEquals(data.parseExtra(TestVO.class).getName(), testVO.getName());
6162
assertEquals(data.getAuthorities(),authorities);
6263
}

springboot-starter-security/src/test/resources/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ server.port=8088
33
codingapi.security.jwt.jwt-time=10000
44
codingapi.security.jwt.jwt-rest-time=5000
55

6+
codingapi.security.jwt.enable=true
67
# JWT密钥 需大于32位的字符串
78
codingapi.security.jwt.secret-key=codingapi.security.jwt.secretkey
89
# JWT AES密钥
@@ -27,3 +28,5 @@ codingapi.security.ignore-urls=/open/**
2728
codingapi.security.disable-csrf=true
2829
# 禁用CORS
2930
codingapi.security.disable-cors=true
31+
32+
spring.main.allow-bean-definition-overriding=true

0 commit comments

Comments
 (0)