LoadBalancingKMSClientProvider extends KeyProvider implements
    CryptoExtension,
    KeyProviderDelegationTokenExtension.DelegationTokenExtension { @VisibleForTesting public KMSClientProvider[] getProviders() { return providers; } LoadBalancingKMSClientProvider(URI providerUri,
      KMSClientProvider[] providers, Configuration conf); @VisibleForTesting  LoadBalancingKMSClientProvider(KMSClientProvider[] providers, long seed,
      Configuration conf); private  LoadBalancingKMSClientProvider(URI uri,
      KMSClientProvider[] providers, long seed, Configuration conf); @VisibleForTesting KMSClientProvider[] getProviders(); @Override org.apache.hadoop.security.token.Token<? extends TokenIdentifier> selectDelegationToken(Credentials creds); @Override String getCanonicalServiceName(); @Override Token<?> getDelegationToken(String renewer); @Override long renewDelegationToken(final Token<?> token); @Override Void cancelDelegationToken(final Token<?> token); @Override void warmUpEncryptedKeys(String... keyNames); @Override void drain(String keyName); @Override void invalidateCache(String keyName); @Override EncryptedKeyVersion generateEncryptedKey(final String encryptionKeyName); @Override KeyVersion decryptEncryptedKey(final EncryptedKeyVersion encryptedKeyVersion); @Override EncryptedKeyVersion reencryptEncryptedKey(
      final EncryptedKeyVersion ekv); @Override void reencryptEncryptedKeys(final List<EncryptedKeyVersion> ekvs); @Override KeyVersion getKeyVersion(final String versionName); @Override List<String> getKeys(); @Override Metadata[] getKeysMetadata(final String... names); @Override List<KeyVersion> getKeyVersions(final String name); @Override KeyVersion getCurrentKey(final String name); @Override Metadata getMetadata(final String name); @Override KeyVersion createKey(final String name, final byte[] material,
      final Options options); @Override KeyVersion createKey(final String name, final Options options); @Override void deleteKey(final String name); @Override KeyVersion rollNewVersion(final String name, final byte[] material); @Override KeyVersion rollNewVersion(final String name); @Override void close(); @Override void flush(); static Logger LOG; }
@Test public void testGetActualUGI() throws Exception { final Configuration conf = new Configuration(); conf.set("hadoop.security.authentication", "kerberos"); UserGroupInformation.setConfiguration(conf); UserGroupInformation ugi = UserGroupInformation.createUserForTesting( "foo", new String[] {"hadoop"}); String providerUriString = "kms: final URI kmsUri = URI.create(providerUriString); final Token token = new Token(); token.setKind(TOKEN_KIND); token.setService(new Text(providerUriString)); UserGroupInformation actualUgi = ugi.doAs(new PrivilegedExceptionAction<UserGroupInformation>(){ @Override public UserGroupInformation run() throws Exception { final KeyProvider kp = new KMSClientProvider.Factory().createProvider(kmsUri, conf); final LoadBalancingKMSClientProvider lbkp = (LoadBalancingKMSClientProvider) kp; final Credentials creds = new Credentials(); creds.addToken(token.getService(), token); UserGroupInformation.getCurrentUser().addCredentials(creds); KMSClientProvider[] providers = lbkp.getProviders(); return providers[0].getActualUgi(); } }); assertEquals( "getActualUgi() should return the current user, not login user", ugi, actualUgi); }