BrokerTokenIdentifier extends DelegationTokenIdentifier { public String getSessionToken(){ return sessionToken; } BrokerTokenIdentifier();  BrokerTokenIdentifier(Configuration config, Text owner, Text renewer, Text realUser, Text service); @Override void write(DataOutput out); @Override void readFields(DataInput in); void setSessionToken(String sessionToken); String getSessionToken(); static final Text KIND; }
@Test public void testGetSessionTokenProviderRefreshWhileNotLoggedIn() throws Exception { try { Configuration conf = TestingTools.getBrokerConfig(); getSessionToken(conf); fail(); } catch (Exception e) { assertEquals(RuntimeException.class, e.getClass()); Assert.assertEquals( "Failed creating a SPNEGO token. Make sure that you have run kinit and that your Kerberos configuration is correct. See the full Kerberos error message: " + SpnegoUtilsTest.TGT_ERROR, e.getMessage() ); } }
@Test public void testGetSessionToken() throws IOException { TestingTools.startServer(new FakeServer(fakeKDC), grpcCleanup); Configuration conf = TestingTools.getBrokerConfig(); Subject alice = fakeKDC.login(ALICE); UserGroupInformation.loginUserFromSubject(alice); String token = getSessionToken(conf); assertEquals("FakeSessionToken/AuthenticatedUser=" + ALICE + ";Owner=" + ALICE + ";Target=" + MOCK_BUCKET, token); UserGroupInformation.setLoginUser(null); }
@Test public void testGetSessionTokenWithoutAccessBoundary() throws IOException { TestingTools.startServer(new FakeServer(fakeKDC), grpcCleanup); Configuration conf = TestingTools.getBrokerConfig(); conf.set("gcp.token.broker.access.boundary.enabled", "false"); Subject alice = fakeKDC.login(ALICE); UserGroupInformation.loginUserFromSubject(alice); String token = getSessionToken(conf); assertEquals("FakeSessionToken/AuthenticatedUser=" + ALICE + ";Owner=" + ALICE + ";Target=", token); UserGroupInformation.setLoginUser(null); }