All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fun.mike.azure.auth.TokenValidator Maven / Gradle / Ivy

The newest version!
package fun.mike.azure.auth;

import java.text.ParseException;

import com.nimbusds.jose.JOSEException;
import com.nimbusds.jose.RemoteKeySourceException;
import com.nimbusds.jose.proc.BadJOSEException;
import com.nimbusds.jose.proc.SecurityContext;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.proc.ConfigurableJWTProcessor;

public class TokenValidator {
    private final ConfigurableJWTProcessor processor;

    public TokenValidator(ConfigurableJWTProcessor processor) {
        this.processor = processor;
    }

    public AuthenticationResult validate(String token) {
        try {
            JWTClaimsSet claimsSet = processor.process(token, null);
            return AuthenticationResult.valid(claimsSet.getClaims());
        }
        catch(RemoteKeySourceException ex) {
            return AuthenticationResult.failed(ex.getMessage());
        }
        catch (ParseException | JOSEException | BadJOSEException ex) {
            return AuthenticationResult.invalid(ex.getMessage());
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy