JwtValidatorImpl.java
1.37 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* org.apache.oltu.oauth2.jwt.ClaimsSet
* org.apache.oltu.oauth2.jwt.JWT
* org.apache.oltu.oauth2.jwt.io.JWTReader
*/
package com.adobe.granite.oauth.jwt.impl;
import com.adobe.granite.oauth.jwt.JwtValidator;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.oltu.oauth2.jwt.ClaimsSet;
import org.apache.oltu.oauth2.jwt.JWT;
import org.apache.oltu.oauth2.jwt.io.JWTReader;
@Service
@Component(metatype=0)
public class JwtValidatorImpl
implements JwtValidator {
public boolean validate(String jwt, long time) {
JWT ojwt = (JWT)new JWTReader().read(jwt);
return this.validateExpiration(ojwt, time) && this.validateNotBefore(ojwt, time);
}
private boolean validateNotBefore(JWT jwt, long time) {
String nbf = jwt.getClaimsSet().getNotBefore();
return nbf == null || this.getUtcTimeInMillis(Long.parseLong(nbf)) <= time;
}
private boolean validateExpiration(JWT jwt, long time) {
long exp = jwt.getClaimsSet().getExpirationTime();
return exp == 0 || this.getUtcTimeInMillis(exp) > time;
}
private long getUtcTimeInMillis(long intDate) {
return intDate * 1000;
}
}