Example usage for java.security.interfaces RSAPublicKey equals

List of usage examples for java.security.interfaces RSAPublicKey equals

Introduction

In this page you can find the example usage for java.security.interfaces RSAPublicKey equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.vmware.identity.openidconnect.sample.RelyingPartyController.java

private static void validateToken(ServerIssuedToken token, TokenType expectedTokenType) {
    String error = null;//from w ww.  j av a2 s .  c  o m

    if (!token.getAudience().contains(clientId)) {
        error = "audience does not contain expected client_id";
    }

    if (error == null && !clientId.equals(token.getClientID().getValue())) {
        error = "incorrect client_id";
    }

    if (error == null && !tenantName.equals(token.getTenant())) {
        error = "incorrect tenant";
    }

    Date now = new Date();
    Date adjustedExpirationTime = new Date(
            token.getExpirationTime().getTime() + CLOCK_TOLERANCE_SECONDS * 1000L);
    if (error == null && now.after(adjustedExpirationTime)) {
        error = "expired jwt";
    }

    if (error == null && token.getTokenType() != expectedTokenType) {
        error = "incorrect token_type";
    }

    if (expectedTokenType == TokenType.HOK) {
        if (error == null && token.getHolderOfKey() == null) {
            error = "missing hotk claim";
        }

        if (error == null) {
            RSAPublicKey rsaPublicKey = token.getHolderOfKey();
            if (rsaPublicKey == null) {
                error = "could not extract an RSA 256 public key out of hotk";
            } else if (!rsaPublicKey.equals(clientCertificate.getPublicKey())) {
                error = "hotk is not equal to the public key we sent";
            }
        }

        if (error == null && token.getActAs() == null) {
            error = "missing act_as claim";
        }
    }

    if (error != null) {
        throw new IllegalStateException(
                String.format("%s validation error: %s", token.getTokenClass().getValue(), error));
    }
}