Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit a3cf008

Browse files
authored
Merge pull request #2 from ModaOperandi/code_refactor
Should work.
2 parents 6970352 + e34053d commit a3cf008

File tree

3 files changed

+47
-54
lines changed

3 files changed

+47
-54
lines changed

build.gradle

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,15 @@ plugins {
22
id 'java-library'
33
}
44

5-
repositories {
6-
mavenCentral()
7-
maven {
8-
url "https://jitpack.io"
9-
credentials { username 'jp_am1gb3ih8jb1jq01hdtbo1q23t' }
10-
}
11-
}
5+
repositories { mavenCentral() }
126

137
version = '0.1.0'
148

159
dependencies {
16-
1710
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
1811
compile group: 'com.auth0', name: 'java-jwt', version: '3.7.0'
1912

20-
testImplementation 'junit:junit:4.12'
13+
testImplementation group: 'junit', name: 'junit', version: '4.12'
2114
}
2215

2316
jar {

src/main/java/com/modaoperandi/jwt/java/DecodedToken.java

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ public class DecodedToken {
1313
private String scopes;
1414
private String[] groups;
1515
private String[] roles;
16-
private String[] permissions;
16+
private String[] permissions;
1717

18-
public DecodedToken() {
19-
this.authToken = null;
20-
this.scopes = null;
21-
this.groups = null;
22-
this.roles = null;
23-
this.permissions = null;
24-
}
18+
public DecodedToken() {
19+
this.authToken = null;
20+
this.scopes = null;
21+
this.groups = null;
22+
this.roles = null;
23+
this.permissions = null;
24+
}
2525

26-
public DecodedToken(HttpServletRequest request) {
27-
helper(request);
28-
decodeClaims(this.authToken);
29-
}
26+
public DecodedToken(HttpServletRequest request) {
27+
helper(request);
28+
decodeClaims(this.authToken);
29+
}
3030

31-
public DecodedToken(String token) {
32-
this.authToken = token;
33-
decodeClaims(token);
34-
}
31+
public DecodedToken(String token) {
32+
this.authToken = token;
33+
decodeClaims(token);
34+
}
3535

3636
public String getToken() {
3737
return this.authToken;
@@ -64,23 +64,23 @@ public void printScopes() {
6464
}
6565

6666
public void printGroups() {
67-
System.out.println("Groups: " + arrayToString(this.groups));
67+
System.out.println("Groups: " + arrayToString(this.groups));
6868
}
6969

7070
public void printRoles() {
71-
System.out.println("Roles: " + arrayToString(this.roles));
71+
System.out.println("Roles: " + arrayToString(this.roles));
7272
}
7373

7474
public void printPermissions() {
75-
System.out.println("Permissions: " + arrayToString(this.permissions));
75+
System.out.println("Permissions: " + arrayToString(this.permissions));
7676
}
7777

7878
public void printUserInfo() {
7979
try {
80-
printScopes();
81-
printGroups();
82-
printRoles();
83-
printPermissions();
80+
printScopes();
81+
printGroups();
82+
printRoles();
83+
printPermissions();
8484
} catch (Exception e) {
8585
System.err.println(e.getMessage());
8686
}
@@ -96,24 +96,24 @@ private void helper(HttpServletRequest request) {
9696
}
9797

9898
private void decodeClaims(String token) {
99-
try {
100-
DecodedJWT jwt = JWT.decode(token);
101-
this.scopes = jwt.getClaim("scope").asString();
102-
this.groups = jwt.getClaim(namespace + "groups").asArray(String.class);
103-
this.roles = jwt.getClaim(namespace + "roles").asArray(String.class);
104-
this.permissions = jwt.getClaim(namespace + "permissions").asArray(String.class);
105-
} catch (NullPointerException e) {
106-
System.out.println("Token is null.");
107-
} catch (JWTDecodeException e){
108-
System.out.println("Invalid token.");
109-
}
99+
try {
100+
DecodedJWT jwt = JWT.decode(token);
101+
this.scopes = jwt.getClaim("scope").asString();
102+
this.groups = jwt.getClaim(namespace + "groups").asArray(String.class);
103+
this.roles = jwt.getClaim(namespace + "roles").asArray(String.class);
104+
this.permissions = jwt.getClaim(namespace + "permissions").asArray(String.class);
105+
} catch (NullPointerException e) {
106+
System.out.println("Token is null.");
107+
} catch (JWTDecodeException e){
108+
System.out.println("Invalid token.");
109+
}
110110
}
111111

112112
private String arrayToString(String[] array) {
113-
StringBuilder sb = new StringBuilder();
114-
for (String str : array) {
115-
sb.append(str).append(" ");
116-
}
117-
return sb.toString().trim();
113+
StringBuilder sb = new StringBuilder();
114+
for (String str : array) {
115+
sb.append(str).append(" ");
116+
}
117+
return sb.toString().trim();
118118
}
119-
}
119+
}

src/test/java/com/modaoperandi/jwt/java/DecodedTokenTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ public void getPermissions() throws Exception {
4949
}
5050

5151
private String arrayToString(String[] array) {
52-
StringBuilder sb = new StringBuilder();
53-
for (String str : array) {
54-
sb.append(str).append(" ");
55-
}
56-
return sb.toString().trim();
52+
StringBuilder sb = new StringBuilder();
53+
for (String str : array) {
54+
sb.append(str).append(" ");
55+
}
56+
return sb.toString().trim();
5757
}
5858
}

0 commit comments

Comments
 (0)