forked from GJWT/javaOIDCMsg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRiscJWT.java
More file actions
106 lines (92 loc) · 3.75 KB
/
RiscJWT.java
File metadata and controls
106 lines (92 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2017 The Authors of 'JWTS for Java'
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package com.auth0.jwt.jwts;
import com.auth0.jwt.ClockImpl;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.Clock;
import com.auth0.jwt.interfaces.Verification;
import java.util.List;
public class RiscJWT extends JWT.BaseVerification implements Verification {
RiscJWT(Algorithm algorithm) throws IllegalArgumentException {
super(algorithm);
}
/**
* Create Verification object for verification purposes
* @param jti
* @param issuer
* @param audience
* @param iatLeeway
* @param expLeeway
* @return
*/
public Verification createVerifierForRisc(String jti, List<String> issuer,
List<String> audience, long iatLeeway, long expLeeway, long nbf) {
Verification verification = withJWTId(jti).withIssuer(issuer.toArray(new String[issuer.size()])).acceptIssuedAt(iatLeeway);
if(audience != null && !audience.isEmpty()) {
verification.withAudience(audience.toArray(new String[audience.size()]));
}
if(nbf >= 0) {
verification.acceptNotBefore(iatLeeway);
}
if(expLeeway >= 0) {
verification.acceptExpiresAt(expLeeway);
}
return verification;
}
/**
* Returns a {Verification} to be used to validate token signature.
*
* @param algorithm that will be used to verify the token's signature.
* @return Verification
* @throws IllegalArgumentException if the provided algorithm is null.
*/
public static Verification require(Algorithm algorithm) {
return RiscJWT.init(algorithm);
}
/**
* Initialize a Verification instance using the given Algorithm.
*
* @param algorithm the Algorithm to use on the JWT verification.
* @return a RiscJWT instance to configure.
* @throws IllegalArgumentException if the provided algorithm is null.
*/
static Verification init(Algorithm algorithm) throws IllegalArgumentException {
return new RiscJWT(algorithm);
}
/**
* Creates a new and reusable instance of the JWT with the configuration already provided.
*
* @return a new JWT instance.
*/
@Override
public JWT build() {
return this.build(new ClockImpl());
}
/**
* Creates a new and reusable instance of the JWT the configuration already provided.
* ONLY FOR TEST PURPOSES.
*
* @param clock the instance that will handle the current time.
* @return a new JWT instance with a custom Clock.
*/
public JWT build(Clock clock) {
addLeewayToDateClaims();
return new JWT(algorithm, claims, clock);
}
}