Skip to content

Commit 9f8ca7c

Browse files
committed
time variable update
1 parent 56d3030 commit 9f8ca7c

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ EdgeAuth-Token-Java supports Java 1.6+.
1414

1515

1616
## Build
17-
[Click Here](http://search.maven.org/#artifactdetails%7Ccom.akamai%7Cedgeauth%7C0.1.0%7C)
17+
[Click Here](http://search.maven.org/#artifactdetails%7Ccom.akamai%7Cedgeauth%7C0.2.0%7C)
1818

1919

2020
## Example
@@ -115,30 +115,30 @@ try {
115115
## Usage
116116

117117
#### EdgeAuth, EdgeAuthBuilder Class
118+
118119
| Parameter | Description |
119120
|-----------|-------------|
120121
| tokenType | Select a preset. (Not Supported Yet) |
121122
| tokenName | Parameter name for the new token. [ Default: \_\_token\_\_ ] |
122123
| key | Secret required to generate the token. It must be hexadecimal digit string with even-length. |
123-
| algorithm | Algorithm to use to generate the token. (sha1, sha256, or md5) [ Default:sha256 ] |
124+
| algorithm | Algorithm to use to generate the token. ("sha1", "sha256", or "md5") [ Default: "sha256" ] |
124125
| salt | Additional data validated by the token but NOT included in the token body. (It will be deprecated) |
125126
| ip | IP Address to restrict this token to. (Troublesome in many cases (roaming, NAT, etc) so not often used) |
126127
| payload | Additional text added to the calculated digest. |
127128
| sessionId | The session identifier for single use tokens or other advanced cases. |
128-
| starTime | What is the start time? (Use 'EdgeAuth.NOW' for the current time) |
129-
| endTime | When does this token expire? 'endTime' overrides 'windowSeconds' |
129+
| startTime | What is the start time? (Use EdgeAuth.NOW for the current time) |
130+
| endTime | When does this token expire? endTime overrides windowSeconds |
130131
| windowSeconds | How long is this token valid for? |
131132
| fieldDelimiter | Character used to delimit token body fields. [ Default: ~ ] |
132133
| aclDelimiter | Character used to delimit acl. [ Default: ! ] |
133-
| escapeEarly | Causes strings to be 'url' encoded before being used. |
134+
| escapeEarly | Causes strings to be url encoded before being used. |
134135
| verbose | Print all parameters. |
135136

136137
#### EdgeAuth Static Variable
137138
```java
138139
public static final Long NOW = 0L; // When using startTime, 0L means "from NOW".
139140
```
140141

141-
142142
#### EdgeAuth's Method
143143
| Method | Description |
144144
|--------|-------------|

build.gradle.production

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "com.akamai"
9-
version = "0.1.0"
9+
version = "0.2.0"
1010

1111
repositories {
1212
mavenCentral()

src/main/java/com/akamai/edgeauth/EdgeAuth.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,31 @@ private String escapeEarly(final String text) throws EdgeAuthException {
180180
* @throws EdgeAuthException EdgeAuthException
181181
*/
182182
private String generateToken(String path, boolean isUrl) throws EdgeAuthException {
183-
if (this.startTime == EdgeAuth.NOW) {
184-
this.startTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() / 1000L;
185-
} else if(this.startTime != null && this.startTime < 0) {
183+
Long startTime = this.startTime;
184+
Long endTime = this.endTime;
185+
186+
if (startTime == EdgeAuth.NOW) {
187+
startTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() / 1000L;
188+
} else if(startTime != null && startTime < 0) {
186189
throw new EdgeAuthException("startTime must be ( > 0 )");
187190
}
188191

189-
if (this.endTime == null) {
192+
if (endTime == null) {
190193
if (this.windowSeconds != null && this.windowSeconds > 0) {
191-
if (this.startTime == null) {
192-
this.endTime = (Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() / 1000L) +
194+
if (startTime == null) {
195+
endTime = (Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis() / 1000L) +
193196
this.windowSeconds;
194197
} else {
195-
this.endTime = this.startTime + this.windowSeconds;
198+
endTime = startTime + this.windowSeconds;
196199
}
197200
} else {
198201
throw new EdgeAuthException("You must provide an expiration time or a duration window ( > 0 )");
199202
}
200-
} else if(this.endTime <= 0) {
203+
} else if(endTime <= 0) {
201204
throw new EdgeAuthException("endTime must be ( > 0 )");
202205
}
203206

204-
if (this.startTime != null && (this.endTime <= this.startTime)) {
207+
if (startTime != null && (endTime <= startTime)) {
205208
throw new EdgeAuthException("Token will have already expired.");
206209
}
207210

@@ -236,11 +239,11 @@ private String generateToken(String path, boolean isUrl) throws EdgeAuthExceptio
236239
}
237240
if (this.startTime != null) {
238241
newToken.append("st=");
239-
newToken.append(Long.toString(this.startTime));
242+
newToken.append(startTime.toString());
240243
newToken.append(this.fieldDelimiter);
241244
}
242245
newToken.append("exp=");
243-
newToken.append(Long.toString(this.endTime));
246+
newToken.append(endTime.toString());
244247
newToken.append(this.fieldDelimiter);
245248

246249
if (!isUrl) {
@@ -513,21 +516,21 @@ public String getSessionId() {
513516
/**
514517
* @return startTime
515518
*/
516-
public long getStartTime() {
519+
public Long getStartTime() {
517520
return this.startTime;
518521
}
519522

520523
/**
521524
* @return endTime
522525
*/
523-
public long getEndTime() {
526+
public Long getEndTime() {
524527
return this.endTime;
525528
}
526529

527530
/**
528531
* @return windowSeconds
529532
*/
530-
public long getwindowSeconds() {
533+
public Long getwindowSeconds() {
531534
return this.windowSeconds;
532535
}
533536

src/test/java/com/akamai/edgeauth/EdgeAuthTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ public void test_acl_deli_escape_on__ignoreQuery_yes() throws UnknownHostExcepti
324324

325325
statusCode = EdgeAuthTest.requests(this.eaHostname, "/q_escape_ignore/world/", qs, null);
326326
assertEquals("404", statusCode);
327+
328+
assertEquals(null, ead.getStartTime());
329+
assertEquals(null, ead.getEndTime());
327330
}
328331

329332
@Test

0 commit comments

Comments
 (0)