public synchronized String getDelegationToken(final String ownerStr, final String renewer) throws IOException {
    if (ownerStr == null) {
      throw new RuntimeException("Delegation token owner is null");
    }
    Text owner = new Text(ownerStr);
    Text realUser = null;
    UserGroupInformation currentUgi = UserGroupInformation.getCurrentUser();
    if (currentUgi.getUserName() != null) {
      realUser = new Text(currentUgi.getUserName());
    }
    DelegationTokenIdentifier ident =
      new DelegationTokenIdentifier(owner, new Text(renewer), realUser);
    Token<DelegationTokenIdentifier> t = new Token<>(
        ident, this);
    return t.encodeToUrlString();
  }
Verify token string
@param tokenStrForm
@return user name
@throws IOException
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/security/DelegationTokenSecretManager.java