提交 9300c08f 编写于 作者: C coffeys

8147772: Update KerberosTicket to describe behavior if it has been destroyed...

8147772: Update KerberosTicket to describe behavior if it has been destroyed and fix NullPointerExceptions
8163104: Unexpected NPE still possible on some Kerberos ticket calls
Reviewed-by: weijun
上级 3167b53c
...@@ -377,7 +377,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -377,7 +377,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return true if this ticket is forwardable, false if not. * @return true if this ticket is forwardable, false if not.
*/ */
public final boolean isForwardable() { public final boolean isForwardable() {
return flags[FORWARDABLE_TICKET_FLAG]; return flags == null? false: flags[FORWARDABLE_TICKET_FLAG];
} }
/** /**
...@@ -389,7 +389,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -389,7 +389,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* false otherwise. * false otherwise.
*/ */
public final boolean isForwarded() { public final boolean isForwarded() {
return flags[FORWARDED_TICKET_FLAG]; return flags == null? false: flags[FORWARDED_TICKET_FLAG];
} }
/** /**
...@@ -398,7 +398,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -398,7 +398,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return true if this ticket is proxiable, false if not. * @return true if this ticket is proxiable, false if not.
*/ */
public final boolean isProxiable() { public final boolean isProxiable() {
return flags[PROXIABLE_TICKET_FLAG]; return flags == null? false: flags[PROXIABLE_TICKET_FLAG];
} }
/** /**
...@@ -407,7 +407,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -407,7 +407,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return true if this ticket is a proxy-ticket, false if not. * @return true if this ticket is a proxy-ticket, false if not.
*/ */
public final boolean isProxy() { public final boolean isProxy() {
return flags[PROXY_TICKET_FLAG]; return flags == null? false: flags[PROXY_TICKET_FLAG];
} }
...@@ -417,7 +417,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -417,7 +417,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return true if this ticket is post-dated, false if not. * @return true if this ticket is post-dated, false if not.
*/ */
public final boolean isPostdated() { public final boolean isPostdated() {
return flags[POSTDATED_TICKET_FLAG]; return flags == null? false: flags[POSTDATED_TICKET_FLAG];
} }
/** /**
...@@ -428,7 +428,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -428,7 +428,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return true if this ticket is renewable, false if not. * @return true if this ticket is renewable, false if not.
*/ */
public final boolean isRenewable() { public final boolean isRenewable() {
return flags[RENEWABLE_TICKET_FLAG]; return flags == null? false: flags[RENEWABLE_TICKET_FLAG];
} }
/** /**
...@@ -439,7 +439,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -439,7 +439,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* protocol, false if not. * protocol, false if not.
*/ */
public final boolean isInitial() { public final boolean isInitial() {
return flags[INITIAL_TICKET_FLAG]; return flags == null? false: flags[INITIAL_TICKET_FLAG];
} }
/** /**
...@@ -479,7 +479,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -479,7 +479,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
* @return the expiration time for this ticket's validity period. * @return the expiration time for this ticket's validity period.
*/ */
public final java.util.Date getEndTime() { public final java.util.Date getEndTime() {
return (Date) endTime.clone(); return (endTime == null) ? null : (Date) endTime.clone();
} }
/** /**
...@@ -515,7 +515,7 @@ public class KerberosTicket implements Destroyable, Refreshable, ...@@ -515,7 +515,7 @@ public class KerberosTicket implements Destroyable, Refreshable,
/** Determines if this ticket is still current. */ /** Determines if this ticket is still current. */
public boolean isCurrent() { public boolean isCurrent() {
return (System.currentTimeMillis() <= getEndTime().getTime()); return endTime == null? false: (System.currentTimeMillis() <= endTime.getTime());
} }
/** /**
......
...@@ -235,8 +235,11 @@ public class Krb5InitCredential ...@@ -235,8 +235,11 @@ public class Krb5InitCredential
*/ */
public int getInitLifetime() throws GSSException { public int getInitLifetime() throws GSSException {
int retVal = 0; int retVal = 0;
retVal = (int)(getEndTime().getTime() Date d = getEndTime();
- (new Date().getTime())); if (d == null) {
return 0;
}
retVal = (int)(d.getTime() - (new Date().getTime()));
return retVal/1000; return retVal/1000;
} }
......
...@@ -23,15 +23,18 @@ ...@@ -23,15 +23,18 @@
/* /*
* @test * @test
* @bug 6659990 * @bug 6659990 8147772
* @summary test the immutability of the Date fields in KerberosTicket class. * @summary test the immutability of the Date fields in KerberosTicket class,
* serialization, and behavior after being destroyed.
* @ignore Must set up KDC and setup Kerberos configuration file * @ignore Must set up KDC and setup Kerberos configuration file
*/ */
import java.net.InetAddress; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Date; import java.util.Date;
import java.io.*; import java.io.*;
import javax.security.auth.kerberos.KerberosKey; import javax.security.auth.RefreshFailedException;
import javax.security.auth.kerberos.KerberosPrincipal; import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KerberosTicket; import javax.security.auth.kerberos.KerberosTicket;
import java.util.Base64; import java.util.Base64;
...@@ -75,6 +78,7 @@ public class KerberosTixDateTest { ...@@ -75,6 +78,7 @@ public class KerberosTixDateTest {
testDateImmutability(t, originalTime); testDateImmutability(t, originalTime);
testS11nCompatibility(t); // S11n: Serialization testS11nCompatibility(t); // S11n: Serialization
testDestroy(t);
} }
private static void checkTime(KerberosTicket kt, long timeValue) { private static void checkTime(KerberosTicket kt, long timeValue) {
...@@ -137,4 +141,30 @@ public class KerberosTixDateTest { ...@@ -137,4 +141,30 @@ public class KerberosTixDateTest {
System.out.println("S11nCompatibility Test Passed"); System.out.println("S11nCompatibility Test Passed");
} }
private static void testDestroy(KerberosTicket t) throws Exception {
t.destroy();
if (!t.isDestroyed()) {
throw new RuntimeException("ticket should have been destroyed");
}
// Although these methods are meaningless, they can be called
for (Method m: KerberosTicket.class.getDeclaredMethods()) {
if (Modifier.isPublic(m.getModifiers())
&& m.getParameterCount() == 0) {
System.out.println("Testing " + m.getName() + "...");
try {
m.invoke(t);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof RefreshFailedException ||
cause instanceof IllegalStateException) {
// this is OK
} else {
throw e;
}
}
}
}
System.out.println("Destroy Test Passed");
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册