protected void performKdcTest() throws Exception { TgtTicket tgt; SgtTicket tkt; try { tgt = getKrbClient().requestTgt(getClientPrincipal(), getClientPassword()); assertThat(tgt).isNotNull(); tkt = getKrbClient().requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); } catch (Exception e) { Assert.fail("Exception occurred with good password. " + e.toString()); } } }
@Test public void testStoringSGT() throws Exception { TgtTicket tgt = getKrbClient().requestTgt(getClientPrincipal(), getClientPassword()); assertThat(tgt).isNotNull(); SgtTicket tkt = getKrbClient().requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); File ccFile = new File("target/cache.cc"); if (ccFile.exists()) { ccFile.delete(); } try { // Test storing the SGT and not the TGT getKrbClient().storeTicket(tkt, ccFile); } catch (Throwable t) { t.printStackTrace(); } } }
sgtTicket = krbClient.requestSgt(ccFile, null); } catch (KrbException e) { System.err.println("kinit: " + e.getKrbErrorCode().getMessage()); SgtTicket sgtTicket = null; try { sgtTicket = krbClient.requestSgt(ccFile, servicePrincipal); } catch (KrbException e) { System.err.println("Kinit: get service ticket failed: " + e.getMessage()); SgtTicket sgtTicket; try { sgtTicket = krbClient.requestSgt(tgt, servicePrincipal); } catch (KrbException e) { System.err.println("kinit: " + e.getKrbErrorCode().getMessage());
sgtTicket = krbClient.requestSgt(ccFile, null); } catch (KrbException e) { System.err.println("kinit: " + e.getKrbErrorCode().getMessage()); SgtTicket sgtTicket = null; try { sgtTicket = krbClient.requestSgt(ccFile, servicePrincipal); } catch (KrbException e) { System.err.println("Kinit: get service ticket failed: " + e.getMessage()); SgtTicket sgtTicket; try { sgtTicket = krbClient.requestSgt(tgt, servicePrincipal); } catch (KrbException e) { System.err.println("kinit: " + e.getKrbErrorCode().getMessage());
tkt = getKrbClient().requestSgt(tgt, serverPrincipal); assertThat(tkt).isNotNull(); } catch (Exception e) { assertThat(tgt).isNotNull(); tkt = getKrbClient().requestSgt(tgt, serverPrincipal); assertThat(tkt).isNotNull(); } catch (Exception e) {
@Test public void testLoginARCFOURHMAC() throws Exception { KrbClient client = super.getKrbClient(); client.getKrbConfig().setString(KrbConfigKey.PERMITTED_ENCTYPES, "arcfour-hmac"); KOptions requestOptions = new KOptions(); requestOptions.add(KrbOption.CLIENT_PRINCIPAL, getClientPrincipal()); requestOptions.add(KrbOption.USE_KEYTAB, true); File keytab = new File(getTestDir(), "test-client.keytab"); requestOptions.add(KrbOption.KEYTAB_FILE, keytab); getKdcServer().exportPrincipal(getClientPrincipal(), keytab); TgtTicket tgt = client.requestTgt(requestOptions); assertThat(tgt).isNotNull(); SgtTicket tkt = client.requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); keytab.delete(); }
@Test public void testPreAuthTrue() throws Exception { KrbClient client = super.getKrbClient(); client.getKrbConfig().setString(KrbConfigKey.PREAUTH_REQUIRED, "true"); KOptions requestOptions = new KOptions(); requestOptions.add(KrbOption.CLIENT_PRINCIPAL, getClientPrincipal()); requestOptions.add(KrbOption.USE_KEYTAB, true); File keytab = new File(getTestDir(), "test-client.keytab"); requestOptions.add(KrbOption.KEYTAB_FILE, keytab); getKdcServer().exportPrincipal(getClientPrincipal(), keytab); TgtTicket tgt = client.requestTgt(requestOptions); assertThat(tgt).isNotNull(); SgtTicket tkt = client.requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); keytab.delete(); }
@Test public void testPreAuthFalse() throws Exception { KrbClient client = super.getKrbClient(); client.getKrbConfig().setString(KrbConfigKey.PREAUTH_REQUIRED, "false"); KOptions requestOptions = new KOptions(); requestOptions.add(KrbOption.CLIENT_PRINCIPAL, getClientPrincipal()); requestOptions.add(KrbOption.USE_KEYTAB, true); File keytab = new File(getTestDir(), "test-client.keytab"); requestOptions.add(KrbOption.KEYTAB_FILE, keytab); getKdcServer().exportPrincipal(getClientPrincipal(), keytab); TgtTicket tgt = client.requestTgt(requestOptions); assertThat(tgt).isNotNull(); SgtTicket tkt = client.requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); keytab.delete(); }
@Test public void testLoginRC4HMAC() throws Exception { KrbClient client = super.getKrbClient(); client.getKrbConfig().setString(KrbConfigKey.PERMITTED_ENCTYPES, "rc4-hmac"); KOptions requestOptions = new KOptions(); requestOptions.add(KrbOption.CLIENT_PRINCIPAL, getClientPrincipal()); requestOptions.add(KrbOption.USE_KEYTAB, true); File keytab = new File(getTestDir(), "test-client.keytab"); requestOptions.add(KrbOption.KEYTAB_FILE, keytab); getKdcServer().exportPrincipal(getClientPrincipal(), keytab); TgtTicket tgt = client.requestTgt(requestOptions); assertThat(tgt).isNotNull(); SgtTicket tkt = client.requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); keytab.delete(); } }
public static SgtTicket getSgt( KrbClient krbClient, String keytab, String ccache, String password, TgtTicket tgt, String serverPrincipal ) throws KrbException { KOptions requestOptions = new KOptions(); if ( keytab != null ) { requestOptions.add( KrbOption.USE_KEYTAB, true ); requestOptions.add( KrbOption.KEYTAB_FILE, keytab ); } else { requestOptions.add( KrbOption.USE_PASSWD, true ); requestOptions.add( KrbOption.USER_PASSWD, password ); } requestOptions.add( KrbOption.CLIENT_PRINCIPAL, tgt.getClientPrincipal().getName() ); requestOptions.add( KrbOption.SERVER_PRINCIPAL, serverPrincipal ); requestOptions.add( KrbOption.USE_TGT, tgt ); SgtTicket sgt = krbClient.requestSgt( requestOptions ); return sgt; }
assertThat(tgt).isNotNull(); tkt = getKrbClient().requestSgt(tgt, getServerPrincipal()); assertThat(tkt).isNotNull(); } catch (Exception e) {
@Test public void testUnknownServicePrincipal() { try { TgtTicket tgtTicket = getKrbClient().requestTgt(getClientPrincipal(), getClientPassword()); String serverPrincipal = "unknown/" + getHostname() + "@" + TestKdcServer.KDC_REALM; getKrbClient().requestSgt(tgtTicket, serverPrincipal); } catch (KrbException ex) { Assert.assertEquals(KrbErrorCode.KDC_ERR_S_PRINCIPAL_UNKNOWN, ex.getKrbErrorCode()); } }