Skip to content

Commit 29e2dff

Browse files
author
Queue-It
committed
Preparing release 1.0.26
1 parent 0429591 commit 29e2dff

21 files changed

Lines changed: 1034 additions & 431 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.vs
2+
/.vscode
23
/JWETest/target/
34
/JWETest/nbproject/
45
/queuetoken/target/
5-
/queuetoken/nbproject/
6+
/queuetoken/nbproject/

queuetoken/pom.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.queue-it</groupId>
66
<artifactId>queuetoken</artifactId>
7-
<version>1.0.41</version>
7+
<version>1.0.26</version>
88
<packaging>jar</packaging>
99
<name>QueueIt QueueToken</name>
1010
<description>Queue-it QueueToken Library</description>
@@ -47,11 +47,6 @@
4747
<version>1.3</version>
4848
<scope>test</scope>
4949
</dependency>
50-
<dependency>
51-
<groupId>javax.xml.bind</groupId>
52-
<artifactId>jaxb-api</artifactId>
53-
<version>2.3.1</version>
54-
</dependency>
5550
</dependencies>
5651
<properties>
5752
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -137,8 +132,8 @@
137132
<artifactId>maven-compiler-plugin</artifactId>
138133
<version>3.10.1</version>
139134
<configuration>
140-
<source>1.6</source>
141-
<target>1.6</target>
135+
<source>1.8</source>
136+
<target>1.8</target>
142137
</configuration>
143138
</plugin>
144139
<plugin>

queuetoken/src/main/java/com/queue_it/queuetoken/EnqueueToken.java

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.queue_it.queuetoken;
22

33
import java.nio.charset.Charset;
4-
import java.util.*;
4+
import java.nio.charset.StandardCharsets;
5+
import java.util.UUID;
6+
7+
import com.queue_it.queuetoken.enums.EncryptionType;
8+
import com.queue_it.queuetoken.enums.TokenVersion;
9+
import com.queue_it.queuetoken.security.Base64UrlEncoding;
10+
import com.queue_it.queuetoken.security.ShaHash;
511

612
class EnqueueToken implements IEnqueueToken {
713

@@ -11,7 +17,7 @@ class EnqueueToken implements IEnqueueToken {
1117
private String xForwaredFor;
1218
private IEnqueueTokenPayload payload;
1319
private long issued;
14-
private long expires = Long.MAX_VALUE;
20+
private long expires = Long.MAX_VALUE;
1521
private String tokenIdentifierPrefix;
1622
private String tokenIdentifier;
1723
private String token;
@@ -24,12 +30,8 @@ public EnqueueToken(String customerId, String tokenIdentifierPrefix) {
2430
this.tokenIdentifierPrefix = tokenIdentifierPrefix;
2531
}
2632

27-
private String getTokenIdentifier(String tokenIdentifierPrefix1) {
28-
return tokenIdentifierPrefix1 == null || tokenIdentifierPrefix1.isEmpty() ? UUID.randomUUID().toString() : tokenIdentifierPrefix1 + "~" + UUID.randomUUID().toString();
29-
}
30-
31-
public EnqueueToken(String tokenIdentifier, String customerId, String eventId, long issued, long expires, String ipAddress, String xForwaredFor, IEnqueueTokenPayload payload)
32-
{
33+
public EnqueueToken(String tokenIdentifier, String customerId, String eventId, long issued, long expires,
34+
String ipAddress, String xForwaredFor, IEnqueueTokenPayload payload) {
3335
this.tokenIdentifier = tokenIdentifier;
3436
this.customerId = customerId;
3537
this.eventId = eventId;
@@ -39,7 +41,7 @@ public EnqueueToken(String tokenIdentifier, String customerId, String eventId, l
3941
this.expires = expires;
4042
this.payload = payload;
4143
}
42-
44+
4345
@Override
4446
public TokenVersion getTokenVersion() {
4547
return TokenVersion.QT1;
@@ -79,12 +81,12 @@ public String getEventId() {
7981
public String getIpAddress() {
8082
return this.ipAddress;
8183
}
82-
84+
8385
@Override
8486
public String getXForwardedFor() {
8587
return this.xForwaredFor;
8688
}
87-
89+
8890
@Override
8991
public IEnqueueTokenPayload getPayload() {
9092
return this.payload;
@@ -99,11 +101,16 @@ public String getTokenWithoutHash() {
99101
public String getHash() {
100102
return this.hash;
101103
}
102-
104+
103105
@Override
104106
public String getToken() {
105107
return this.token + "." + this.hash;
106-
}
108+
}
109+
110+
private String getTokenIdentifier(String tokenIdentifierPrefix1) {
111+
return tokenIdentifierPrefix1 == null || tokenIdentifierPrefix1.isEmpty() ? UUID.randomUUID().toString()
112+
: tokenIdentifierPrefix1 + "~" + UUID.randomUUID().toString();
113+
}
107114

108115
void generate(String secretKey) throws TokenSerializationException {
109116
generate(secretKey, true);
@@ -112,16 +119,16 @@ void generate(String secretKey) throws TokenSerializationException {
112119
void generate(String secretKey, boolean resetTokenIdentifier) throws TokenSerializationException {
113120
if (resetTokenIdentifier)
114121
this.tokenIdentifier = getTokenIdentifier(this.tokenIdentifierPrefix);
115-
122+
116123
String serialized = serializeHeader() + ".";
117124
if (this.payload != null) {
118125
serialized = serialized + this.payload.encryptAndEncode(secretKey, tokenIdentifier);
119126
}
120127
this.token = serialized;
121128

122-
this.hash = Base64UrlEncoder.encode(ShaHash.GenerateHash(serialized, secretKey));
129+
this.hash = Base64UrlEncoding.encode(ShaHash.generateHash(serialized, secretKey));
123130
}
124-
131+
125132
private String serializeHeader() {
126133
StringBuilder sb = new StringBuilder();
127134
sb.append("{");
@@ -143,36 +150,38 @@ private String serializeHeader() {
143150
sb.append(this.getEventId());
144151
sb.append("\"");
145152
}
146-
if (this.getIpAddress()!= null) {
153+
if (this.getIpAddress() != null) {
147154
sb.append(",\"ip\":\"");
148155
sb.append(this.getIpAddress());
149156
sb.append("\"");
150157
}
151-
if (this.getXForwardedFor()!= null) {
158+
if (this.getXForwardedFor() != null) {
152159
sb.append(",\"xff\":\"");
153160
sb.append(this.getXForwardedFor());
154161
sb.append("\"");
155162
}
156163
sb.append("}");
157-
158-
return Base64UrlEncoder.encode(sb.toString().getBytes(Charset.forName("UTF-8")));
159-
}
160-
161-
static EnqueueToken addIPAddress(EnqueueToken token, String ipAddress, String xForwaredFor)
162-
{
163-
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(), token.getIssued(), token.getExpires(), ipAddress, xForwaredFor, token.getPayload());
164+
165+
return Base64UrlEncoding.encode(sb.toString().getBytes(Charset.forName(StandardCharsets.UTF_8.name())));
164166
}
165-
static EnqueueToken addEventId(EnqueueToken token, String eventId)
166-
{
167-
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), eventId, token.getIssued(), token.getExpires(), token.getIpAddress(), token.getXForwardedFor(), token.getPayload());
167+
168+
static EnqueueToken addIPAddress(EnqueueToken token, String ipAddress, String xForwaredFor) {
169+
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(),
170+
token.getIssued(), token.getExpires(), ipAddress, xForwaredFor, token.getPayload());
168171
}
169-
static EnqueueToken addExpires(EnqueueToken token, Long expires)
170-
{
171-
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(), token.getIssued(), expires, token.getIpAddress(), token.getXForwardedFor(), token.getPayload());
172+
173+
static EnqueueToken addEventId(EnqueueToken token, String eventId) {
174+
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), eventId, token.getIssued(),
175+
token.getExpires(), token.getIpAddress(), token.getXForwardedFor(), token.getPayload());
172176
}
173-
static EnqueueToken addPayload(EnqueueToken token, IEnqueueTokenPayload payload)
174-
{
175-
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(), token.getIssued(), token.getExpires(), token.getIpAddress(), token.getXForwardedFor(), payload);
177+
178+
static EnqueueToken addExpires(EnqueueToken token, Long expires) {
179+
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(),
180+
token.getIssued(), expires, token.getIpAddress(), token.getXForwardedFor(), token.getPayload());
176181
}
177182

183+
static EnqueueToken addPayload(EnqueueToken token, IEnqueueTokenPayload payload) {
184+
return new EnqueueToken(token.getTokenIdentifier(), token.getCustomerId(), token.getEventId(),
185+
token.getIssued(), token.getExpires(), token.getIpAddress(), token.getXForwardedFor(), payload);
186+
}
178187
}

queuetoken/src/main/java/com/queue_it/queuetoken/EnqueueTokenGenerator.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,40 @@
44

55
public class EnqueueTokenGenerator {
66
private EnqueueToken token;
7-
7+
88
public EnqueueTokenGenerator(String customerId) {
9-
this.token = new EnqueueToken(customerId, null);
9+
this.token = new EnqueueToken(customerId, null);
1010
}
1111

1212
public EnqueueTokenGenerator(String customerId, String tokenIdentifierPrefix) {
13-
this.token = new EnqueueToken(customerId, tokenIdentifierPrefix);
13+
this.token = new EnqueueToken(customerId, tokenIdentifierPrefix);
1414
}
15-
15+
1616
public EnqueueTokenGenerator withEventId(String eventId) {
1717
this.token = EnqueueToken.addEventId(this.token, eventId);
18-
1918
return this;
2019
}
21-
20+
2221
public EnqueueTokenGenerator withIpAddress(String ipAddress, String xForwaredFor) {
2322
this.token = EnqueueToken.addIPAddress(this.token, ipAddress, xForwaredFor);
24-
2523
return this;
2624
}
27-
25+
2826
public EnqueueTokenGenerator withValidity(long validityMillis) {
2927
this.token = EnqueueToken.addExpires(this.token, this.token.getIssued() + validityMillis);
30-
3128
return this;
3229
}
3330

3431
public EnqueueTokenGenerator withValidity(Date expires) {
3532
this.token = EnqueueToken.addExpires(this.token, expires.getTime());
36-
3733
return this;
3834
}
39-
35+
4036
public EnqueueTokenGenerator withPayload(IEnqueueTokenPayload payload) {
4137
this.token = EnqueueToken.addPayload(this.token, payload);
42-
4338
return this;
4439
}
45-
40+
4641
public IEnqueueToken generate(String secretKey) throws TokenSerializationException {
4742
token.generate(secretKey, true);
4843
return token;

0 commit comments

Comments
 (0)