JwtValidatorImpl.java 1.37 KB
/*
 * 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;
    }
}