agave-common/common-core/src/main/java/org/iplantc/service/common/auth/JWTClient.java
/**
	 * Entry method to this class. Parses the JWT and optionally validates 
	 * the signature against the known public key of the tenant auth server
	 * if {@link Settings#VERIFY_JWT_SIGNATURE} is true.
	 * @param serializedToken
	 * @param tenantId
	 * @return
	 */
Entry method to this class. Parses the JWT and optionally validates
the signature against the known public key of the tenant auth server
if  Settings#VERIFY_JWT_SIGNATURE is true.
@param serializedToken
@param tenantId
@return
Entry method to this class . Parses the JWT and optionally validates the signature against the known public key of the tenant auth server if Settings#VERIFY_JWT_SIGNATURE is true . @param serializedToken @param tenantId @return
public static boolean parse(String serializedToken, String tenantId)
	{
		if (tenantId == null) return false;
		try 
		{
			SignedJWT signedJWT = SignedJWT.parse(serializedToken);
			if (signedJWT != null)
			{
				if (Settings.VERIFY_JWT_SIGNATURE) {
					RSASSAVerifier.SUPPORTED_ALGORITHMS.add(new JWSAlgorithm("SHA256withRSA", Requirement.OPTIONAL));
					JWSVerifier verifier = new SHA256withRSAVerifier(getTenantPublicKey(tenantId));
					if (!signedJWT.verify(verifier)) {
						log.error("Invalid JWT signature.");	
						return false; 
					}
				}
				ReadOnlyJWTClaimsSet claims = signedJWT.getJWTClaimsSet();
				Date expirationDate = claims.getExpirationTime();
				if (expirationDate == null)
					throw new AuthenticationException(
						"No expiration date in the JWT header. Authentication failed.");
				if (expirationDate.before(new Date()))
					throw new AuthenticationException(
						"JWT has expired. Authentication failed.");
				JSONObject json = claims.toJSONObject();
				json.put("rawTenantId", tenantId); 
				tenantId = StringUtils.lowerCase(tenantId);
				tenantId = StringUtils.replaceChars(tenantId, '_', '.');
				tenantId = StringUtils.replaceChars(tenantId, '-', '.');
				json.put("tenantId", tenantId);
				setCurrentJWSObject(json);
				setCurrentRawJWT(serializedToken);
				if (getCurrentEndUser() == null)
					throw new AuthenticationException(
							"No end user specified in the JWT header. Authentication failed.");
				if (getCurrentTenant() == null)
					throw new AuthenticationException(
							"No tenant specified in the JWT header. Authentication failed.");
				if (getCurrentSubscriber() == null)
					throw new AuthenticationException(
							"No subscriber specified in the JWT header. Authentication failed.");
				return true;
			}
		} 
		catch (TenantException e) {
			log.error("Failed to validate JWT object.", e);
		} 
		catch (ParseException e) {
			log.error("Failed to parse JWT object. Authentication failed.", e);
		} 
		catch (Throwable e) {
			log.error("Error processing JWT header. Authentication failed.", e);
		}
		return false;
	}
public static boolean parse ( String serializedToken , String tenantId ) { if ( tenantId == null ) return false ; try { SignedJWT signedJWT = SignedJWT . parse ( serializedToken ) ; if ( signedJWT != null ) { if ( Settings . VERIFY_JWT_SIGNATURE ) { RSASSAVerifier . SUPPORTED_ALGORITHMS . add ( new JWSAlgorithm ( "SHA256withRSA" , Requirement . OPTIONAL ) ) ; JWSVerifier verifier = new SHA256withRSAVerifier ( getTenantPublicKey ( tenantId ) ) ; if ( ! signedJWT . verify ( verifier ) ) { log . error ( "Invalid JWT signature." ) ; return false ; } } ReadOnlyJWTClaimsSet claims = signedJWT . getJWTClaimsSet ( ) ; Date expirationDate = claims . getExpirationTime ( ) ; if ( expirationDate == null ) throw new AuthenticationException ( "No expiration date in the JWT header. Authentication failed." ) ; if ( expirationDate . before ( new Date ( ) ) ) throw new AuthenticationException ( "JWT has expired. Authentication failed." ) ; JSONObject json = claims . toJSONObject ( ) ; json . put ( "rawTenantId" , tenantId ) ; tenantId = StringUtils . lowerCase ( tenantId ) ; tenantId = StringUtils . replaceChars ( tenantId , '_' , '.' ) ; tenantId = StringUtils . replaceChars ( tenantId , '-' , '.' ) ; json . put ( "tenantId" , tenantId ) ; setCurrentJWSObject ( json ) ; setCurrentRawJWT ( serializedToken ) ; if ( getCurrentEndUser ( ) == null ) throw new AuthenticationException ( "No end user specified in the JWT header. Authentication failed." ) ; if ( getCurrentTenant ( ) == null ) throw new AuthenticationException ( "No tenant specified in the JWT header. Authentication failed." ) ; if ( getCurrentSubscriber ( ) == null ) throw new AuthenticationException ( "No subscriber specified in the JWT header. Authentication failed." ) ; return true ; } } catch ( TenantException e ) { log . error ( "Failed to validate JWT object." , e ) ; } catch ( ParseException e ) { log . error ( "Failed to parse JWT object. Authentication failed." , e ) ; } catch ( Throwable e ) { log . error ( "Error processing JWT header. Authentication failed." , e ) ; } return false ; }
Entry method to this class.
Entry method to this class .
// Create HMAC signer // unmodified tenant id //				log.debug(json.toJSONString());