public void addJWTAuthentication(UserEntity userEntity, String key, boolean persist) throws AmbariException {
    addAuthentication(userEntity,
        UserAuthenticationType.JWT,
        key,
            (user, authKey) -> {
              List<UserAuthenticationEntity> authenticationEntities = user.getAuthenticationEntities();

              // Ensure only one UserAuthenticationEntity exists for JWT for the user...
              for (UserAuthenticationEntity entity : authenticationEntities) {
                if ((entity.getAuthenticationType() == UserAuthenticationType.JWT) &&
                    ((authKey == null) ? (entity.getAuthenticationKey() == null) : authKey.equals(entity.getAuthenticationKey()))) {
                  throw new AmbariException("The authentication type already exists for this user");
                }
              }
            },
        persist);
  }
Adds the ability for a user to authenticate using a JWT token.
<p>
The key for this authentication mechanism is the username expected to be in the JWT token.

@param userEntity the user
@param key        the relevant key
@param persist    true, to persist the created entity; false, to not persist the created entity
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/security/authorization/Users.java