public void testDecodeIdentifier() throws IOException { TestDelegationTokenSecretManager secretManager = new TestDelegationTokenSecretManager(0, 0, 0, 0); secretManager.startThreads(); TestDelegationTokenIdentifier id = new TestDelegationTokenIdentifier( new Text("owner"), new Text("renewer"), new Text("realUser")); Token<TestDelegationTokenIdentifier> token = new Token<TestDelegationTokenIdentifier>(id, secretManager); TokenIdentifier idCopy = token.decodeIdentifier(); assertNotSame(id, idCopy); assertEquals(id, idCopy); }
@Override // MiniProtocol public Token<TestDelegationTokenIdentifier> getDelegationToken(Text renewer) throws IOException { String owner = UserGroupInformation.getCurrentUser().getUserName(); String realUser = UserGroupInformation.getCurrentUser().getRealUser() == null ? "": UserGroupInformation.getCurrentUser().getRealUser().getUserName(); TestDelegationTokenIdentifier tokenId = new TestDelegationTokenIdentifier( new Text(owner), renewer, new Text(realUser)); return new Token<TestDelegationTokenIdentifier>(tokenId, secretManager); }
void connectToServerAndGetDelegationToken( final Configuration conf, final InetSocketAddress addr) throws IOException { MiniProtocol client = null; try { UserGroupInformation current = UserGroupInformation.getCurrentUser(); UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting( MINI_USER, current, GROUP_NAMES); try { client = proxyUserUgi.doAs(new PrivilegedExceptionAction<MiniProtocol>() { @Override public MiniProtocol run() throws IOException { MiniProtocol p = RPC.getProxy(MiniProtocol.class, MiniProtocol.versionID, addr, conf); Token<TestDelegationTokenIdentifier> token; token = p.getDelegationToken(new Text(RENEWER)); currentUgi = UserGroupInformation.createUserForTesting(MINI_USER, GROUP_NAMES); SecurityUtil.setTokenService(token, addr); currentUgi.addToken(token); return p; } }); } catch (InterruptedException e) { Assert.fail(Arrays.toString(e.getStackTrace())); } } finally { RPC.stopProxy(client); } }
void connectToServerAndGetDelegationToken( final Configuration conf, final InetSocketAddress addr) throws IOException { MiniProtocol client = null; try { UserGroupInformation current = UserGroupInformation.getCurrentUser(); UserGroupInformation proxyUserUgi = UserGroupInformation.createProxyUserForTesting( MINI_USER, current, GROUP_NAMES); try { client = proxyUserUgi.doAs(new PrivilegedExceptionAction<MiniProtocol>() { public MiniProtocol run() throws IOException { MiniProtocol p = (MiniProtocol) RPC.getProxy(MiniProtocol.class, MiniProtocol.versionID, addr, conf); Token<TestDelegationTokenIdentifier> token; token = p.getDelegationToken(new Text(RENEWER)); currentUgi = UserGroupInformation.createUserForTesting(MINI_USER, GROUP_NAMES); SecurityUtil.setTokenService(token, addr); currentUgi.addToken(token); return p; } }); } catch (InterruptedException e) { Assert.fail(Arrays.toString(e.getStackTrace())); } } finally { RPC.stopProxy(client); } }
/** * Get a Delegation Token. */ public Token<TestDelegationTokenIdentifier> getDelegationToken(Text renewer) throws IOException;