提交 57a8a863 编写于 作者: W weijun

8048030: Expectations should be consistent

Reviewed-by: valeriep, mullan, ahgross
上级 0a1ffd04
...@@ -112,18 +112,7 @@ public final class KerberosPrincipal ...@@ -112,18 +112,7 @@ public final class KerberosPrincipal
* java.security.krb5.realm system property. * java.security.krb5.realm system property.
*/ */
public KerberosPrincipal(String name) { public KerberosPrincipal(String name) {
this(name, KRB_NT_PRINCIPAL);
PrincipalName krb5Principal = null;
try {
// Appends the default realm if it is missing
krb5Principal = new PrincipalName(name, KRB_NT_PRINCIPAL);
} catch (KrbException e) {
throw new IllegalArgumentException(e.getMessage());
}
nameType = KRB_NT_PRINCIPAL; // default name type
fullName = krb5Principal.toString();
realm = krb5Principal.getRealmString();
} }
/** /**
...@@ -165,6 +154,20 @@ public final class KerberosPrincipal ...@@ -165,6 +154,20 @@ public final class KerberosPrincipal
throw new IllegalArgumentException(e.getMessage()); throw new IllegalArgumentException(e.getMessage());
} }
// A ServicePermission with a principal in the deduced realm and
// any action must be granted if no realm is provided by caller.
if (krb5Principal.isRealmDeduced() && !Realm.AUTODEDUCEREALM) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new ServicePermission(
"@" + krb5Principal.getRealmAsString(), "-"));
} catch (SecurityException se) {
// Swallow the actual exception to hide info
throw new SecurityException("Cannot read realm info");
}
}
}
this.nameType = nameType; this.nameType = nameType;
fullName = krb5Principal.toString(); fullName = krb5Principal.toString();
realm = krb5Principal.getRealmString(); realm = krb5Principal.getRealmString();
......
...@@ -50,7 +50,7 @@ import java.io.IOException; ...@@ -50,7 +50,7 @@ import java.io.IOException;
* used within. * used within.
* <p> * <p>
* The service principal name is the canonical name of the * The service principal name is the canonical name of the
* {@code KereberosPrincipal} supplying the service, that is * {@code KerberosPrincipal} supplying the service, that is
* the KerberosPrincipal represents a Kerberos service * the KerberosPrincipal represents a Kerberos service
* principal. This name is treated in a case sensitive manner. * principal. This name is treated in a case sensitive manner.
* An asterisk may appear by itself, to signify any service principal. * An asterisk may appear by itself, to signify any service principal.
...@@ -145,6 +145,9 @@ public final class ServicePermission extends Permission ...@@ -145,6 +145,9 @@ public final class ServicePermission extends Permission
* @param action the action string * @param action the action string
*/ */
public ServicePermission(String servicePrincipal, String action) { public ServicePermission(String servicePrincipal, String action) {
// Note: servicePrincipal can be "@REALM" which means any principal in
// this realm implies it. action can be "-" which means any
// action implies it.
super(servicePrincipal); super(servicePrincipal);
init(servicePrincipal, getMask(action)); init(servicePrincipal, getMask(action));
} }
...@@ -188,7 +191,9 @@ public final class ServicePermission extends Permission ...@@ -188,7 +191,9 @@ public final class ServicePermission extends Permission
boolean impliesIgnoreMask(ServicePermission p) { boolean impliesIgnoreMask(ServicePermission p) {
return ((this.getName().equals("*")) || return ((this.getName().equals("*")) ||
this.getName().equals(p.getName())); this.getName().equals(p.getName()) ||
(p.getName().startsWith("@") &&
this.getName().endsWith(p.getName())));
} }
/** /**
...@@ -295,7 +300,10 @@ public final class ServicePermission extends Permission ...@@ -295,7 +300,10 @@ public final class ServicePermission extends Permission
/** /**
* Convert an action string to an integer actions mask. * Convert an action string to an integer actions mask.
* *
* @param action the action string * Note: if action is "-", action will be NONE, which means any
* action implies it.
*
* @param action the action string.
* @return the action mask * @return the action mask
*/ */
private static int getMask(String action) { private static int getMask(String action) {
...@@ -312,9 +320,11 @@ public final class ServicePermission extends Permission ...@@ -312,9 +320,11 @@ public final class ServicePermission extends Permission
char[] a = action.toCharArray(); char[] a = action.toCharArray();
int i = a.length - 1; if (a.length == 1 && a[0] == '-') {
if (i < 0)
return mask; return mask;
}
int i = a.length - 1;
while (i != -1) { while (i != -1) {
char c; char c;
...@@ -475,6 +485,17 @@ final class KrbServicePermissionCollection extends PermissionCollection ...@@ -475,6 +485,17 @@ final class KrbServicePermissionCollection extends PermissionCollection
ServicePermission np = (ServicePermission) permission; ServicePermission np = (ServicePermission) permission;
int desired = np.getMask(); int desired = np.getMask();
if (desired == 0) {
for (Permission p: perms) {
ServicePermission sp = (ServicePermission)p;
if (sp.impliesIgnoreMask(np)) {
return true;
}
}
return false;
}
int effective = 0; int effective = 0;
int needed = desired; int needed = desired;
......
...@@ -28,7 +28,10 @@ package sun.security.jgss.krb5; ...@@ -28,7 +28,10 @@ package sun.security.jgss.krb5;
import org.ietf.jgss.*; import org.ietf.jgss.*;
import sun.security.jgss.spi.*; import sun.security.jgss.spi.*;
import sun.security.krb5.PrincipalName; import sun.security.krb5.PrincipalName;
import sun.security.krb5.Realm;
import sun.security.krb5.KrbException; import sun.security.krb5.KrbException;
import javax.security.auth.kerberos.ServicePermission;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
...@@ -126,6 +129,18 @@ public class Krb5NameElement ...@@ -126,6 +129,18 @@ public class Krb5NameElement
throw new GSSException(GSSException.BAD_NAME, -1, e.getMessage()); throw new GSSException(GSSException.BAD_NAME, -1, e.getMessage());
} }
if (principalName.isRealmDeduced() && !Realm.AUTODEDUCEREALM) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
sm.checkPermission(new ServicePermission(
"@" + principalName.getRealmAsString(), "-"));
} catch (SecurityException se) {
// Do not chain the actual exception to hide info
throw new GSSException(GSSException.FAILURE);
}
}
}
return new Krb5NameElement(principalName, gssNameStr, gssNameType); return new Krb5NameElement(principalName, gssNameStr, gssNameType);
} }
...@@ -198,7 +213,7 @@ public class Krb5NameElement ...@@ -198,7 +213,7 @@ public class Krb5NameElement
* If either name denotes an anonymous principal, the call should * If either name denotes an anonymous principal, the call should
* return false. * return false.
* *
* @param name to be compared with * @param other to be compared with
* @returns true if they both refer to the same entity, else false * @returns true if they both refer to the same entity, else false
* @exception GSSException with major codes of BAD_NAMETYPE, * @exception GSSException with major codes of BAD_NAMETYPE,
* BAD_NAME, FAILURE * BAD_NAME, FAILURE
......
...@@ -30,6 +30,7 @@ import java.security.Provider; ...@@ -30,6 +30,7 @@ import java.security.Provider;
import java.security.Security; import java.security.Security;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import sun.security.krb5.Realm;
import sun.security.jgss.GSSUtil; import sun.security.jgss.GSSUtil;
import sun.security.util.ObjectIdentifier; import sun.security.util.ObjectIdentifier;
import sun.security.util.DerInputStream; import sun.security.util.DerInputStream;
...@@ -38,6 +39,8 @@ import sun.security.jgss.GSSUtil; ...@@ -38,6 +39,8 @@ import sun.security.jgss.GSSUtil;
import sun.security.jgss.GSSExceptionImpl; import sun.security.jgss.GSSExceptionImpl;
import sun.security.jgss.spi.GSSNameSpi; import sun.security.jgss.spi.GSSNameSpi;
import javax.security.auth.kerberos.ServicePermission;
/** /**
* This class is essentially a wrapper class for the gss_name_t * This class is essentially a wrapper class for the gss_name_t
* structure of the native GSS library. * structure of the native GSS library.
...@@ -150,6 +153,26 @@ public class GSSNameElement implements GSSNameSpi { ...@@ -150,6 +153,26 @@ public class GSSNameElement implements GSSNameSpi {
pName = cStub.importName(name, nameType); pName = cStub.importName(name, nameType);
setPrintables(); setPrintables();
SecurityManager sm = System.getSecurityManager();
if (sm != null && !Realm.AUTODEDUCEREALM) {
String krbName = getKrbName();
int atPos = krbName.lastIndexOf('@');
if (atPos != -1) {
String atRealm = krbName.substring(atPos);
if (nameType.equals(GSSUtil.NT_GSS_KRB5_PRINCIPAL)
&& new String(nameBytes).endsWith(atRealm)) {
// Created from Kerberos name with realm, no need to check
} else {
try {
sm.checkPermission(new ServicePermission(atRealm, "-"));
} catch (SecurityException se) {
// Do not chain the actual exception to hide info
throw new GSSException(GSSException.FAILURE);
}
}
}
}
SunNativeProvider.debug("Imported " + printableName + " w/ type " + SunNativeProvider.debug("Imported " + printableName + " w/ type " +
printableType); printableType);
} }
......
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
package sun.security.krb5; package sun.security.krb5;
import sun.security.krb5.internal.Krb5;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays; import java.util.Arrays;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Random; import java.util.Random;
...@@ -52,6 +57,8 @@ class KrbServiceLocator { ...@@ -52,6 +57,8 @@ class KrbServiceLocator {
private static final Random random = new Random(); private static final Random random = new Random();
private static final boolean DEBUG = Krb5.DEBUG;
private KrbServiceLocator() { private KrbServiceLocator() {
} }
...@@ -62,8 +69,7 @@ class KrbServiceLocator { ...@@ -62,8 +69,7 @@ class KrbServiceLocator {
* Information on the mapping of DNS hostnames and domain names * Information on the mapping of DNS hostnames and domain names
* to Kerberos realms is stored using DNS TXT records * to Kerberos realms is stored using DNS TXT records
* *
* @param domainName A string domain name. * @param realmName A string realm name.
* @param environment The possibly null environment of the context.
* @return An ordered list of hostports for the Kerberos service or null if * @return An ordered list of hostports for the Kerberos service or null if
* the service has not been located. * the service has not been located.
*/ */
...@@ -81,8 +87,18 @@ class KrbServiceLocator { ...@@ -81,8 +87,18 @@ class KrbServiceLocator {
if (!(ctx instanceof DirContext)) { if (!(ctx instanceof DirContext)) {
return null; // cannot create a DNS context return null; // cannot create a DNS context
} }
Attributes attrs = Attributes attrs = null;
((DirContext)ctx).getAttributes(dnsUrl, SRV_TXT_ATTR); try {
// both connect and accept are needed since DNS is thru UDP
attrs = AccessController.doPrivileged(
(PrivilegedExceptionAction<Attributes>)
() -> ((DirContext)ctx).getAttributes(
dnsUrl, SRV_TXT_ATTR),
null,
new java.net.SocketPermission("*", "connect,accept"));
} catch (PrivilegedActionException e) {
throw (NamingException)e.getCause();
}
Attribute attr; Attribute attr;
if (attrs != null && ((attr = attrs.get(SRV_TXT)) != null)) { if (attrs != null && ((attr = attrs.get(SRV_TXT)) != null)) {
...@@ -124,7 +140,8 @@ class KrbServiceLocator { ...@@ -124,7 +140,8 @@ class KrbServiceLocator {
* Queries DNS for a list of KERBEROS Service Location Records (SRV) for a * Queries DNS for a list of KERBEROS Service Location Records (SRV) for a
* given domain name. * given domain name.
* *
* @param domainName A string domain name. * @param realmName A string realm name.
* @param protocol the protocol string, can be "_udp" or "_tcp"
* @return An ordered list of hostports for the Kerberos service or null if * @return An ordered list of hostports for the Kerberos service or null if
* the service has not been located. * the service has not been located.
*/ */
...@@ -142,8 +159,20 @@ class KrbServiceLocator { ...@@ -142,8 +159,20 @@ class KrbServiceLocator {
if (!(ctx instanceof DirContext)) { if (!(ctx instanceof DirContext)) {
return null; // cannot create a DNS context return null; // cannot create a DNS context
} }
Attributes attrs =
((DirContext)ctx).getAttributes(dnsUrl, SRV_RR_ATTR); Attributes attrs = null;
try {
// both connect and accept are needed since DNS is thru UDP
attrs = AccessController.doPrivileged(
(PrivilegedExceptionAction<Attributes>)
() -> ((DirContext)ctx).getAttributes(
dnsUrl, SRV_RR_ATTR),
null,
new java.net.SocketPermission("*", "connect,accept"));
} catch (PrivilegedActionException e) {
throw (NamingException)e.getCause();
}
Attribute attr; Attribute attr;
if (attrs != null && ((attr = attrs.get(SRV_RR)) != null)) { if (attrs != null && ((attr = attrs.get(SRV_RR)) != null)) {
......
...@@ -123,6 +123,13 @@ public class PrincipalName implements Cloneable { ...@@ -123,6 +123,13 @@ public class PrincipalName implements Cloneable {
*/ */
private final Realm nameRealm; // not null private final Realm nameRealm; // not null
/**
* When constructing a PrincipalName, whether the realm is included in
* the input, or deduced from default realm or domain-realm mapping.
*/
private final boolean realmDeduced;
// cached default salt, not used in clone // cached default salt, not used in clone
private transient String salt = null; private transient String salt = null;
...@@ -143,6 +150,7 @@ public class PrincipalName implements Cloneable { ...@@ -143,6 +150,7 @@ public class PrincipalName implements Cloneable {
this.nameType = nameType; this.nameType = nameType;
this.nameStrings = nameStrings.clone(); this.nameStrings = nameStrings.clone();
this.nameRealm = nameRealm; this.nameRealm = nameRealm;
this.realmDeduced = false;
} }
// This method is called by Windows NativeCred.c // This method is called by Windows NativeCred.c
...@@ -150,11 +158,6 @@ public class PrincipalName implements Cloneable { ...@@ -150,11 +158,6 @@ public class PrincipalName implements Cloneable {
this(KRB_NT_UNKNOWN, nameParts, new Realm(realm)); this(KRB_NT_UNKNOWN, nameParts, new Realm(realm));
} }
public PrincipalName(String[] nameParts, int type)
throws IllegalArgumentException, RealmException {
this(type, nameParts, Realm.getDefault());
}
// Validate a nameStrings argument // Validate a nameStrings argument
private static void validateNameStrings(String[] ns) { private static void validateNameStrings(String[] ns) {
if (ns == null) { if (ns == null) {
...@@ -226,7 +229,7 @@ public class PrincipalName implements Cloneable { ...@@ -226,7 +229,7 @@ public class PrincipalName implements Cloneable {
* <a href="http://www.ietf.org/rfc/rfc4120.txt"> * <a href="http://www.ietf.org/rfc/rfc4120.txt">
* http://www.ietf.org/rfc/rfc4120.txt</a>. * http://www.ietf.org/rfc/rfc4120.txt</a>.
* *
* @param encoding a Der-encoded data. * @param encoding DER-encoded PrincipalName (without Realm)
* @param realm the realm for this name * @param realm the realm for this name
* @exception Asn1Exception if an error occurs while decoding * @exception Asn1Exception if an error occurs while decoding
* an ASN1 encoded data. * an ASN1 encoded data.
...@@ -240,6 +243,7 @@ public class PrincipalName implements Cloneable { ...@@ -240,6 +243,7 @@ public class PrincipalName implements Cloneable {
if (realm == null) { if (realm == null) {
throw new IllegalArgumentException("Null realm not allowed"); throw new IllegalArgumentException("Null realm not allowed");
} }
realmDeduced = false;
nameRealm = realm; nameRealm = realm;
DerValue der; DerValue der;
if (encoding == null) { if (encoding == null) {
...@@ -394,6 +398,10 @@ public class PrincipalName implements Cloneable { ...@@ -394,6 +398,10 @@ public class PrincipalName implements Cloneable {
if (realm == null) { if (realm == null) {
realm = Realm.parseRealmAtSeparator(name); realm = Realm.parseRealmAtSeparator(name);
} }
// No realm info from parameter and string, must deduce later
realmDeduced = realm == null;
switch (type) { switch (type) {
case KRB_NT_SRV_HST: case KRB_NT_SRV_HST:
if (nameParts.length >= 2) { if (nameParts.length >= 2) {
...@@ -413,8 +421,8 @@ public class PrincipalName implements Cloneable { ...@@ -413,8 +421,8 @@ public class PrincipalName implements Cloneable {
hostName.toLowerCase(Locale.ENGLISH)+".")) { hostName.toLowerCase(Locale.ENGLISH)+".")) {
hostName = canonicalized; hostName = canonicalized;
} }
} catch (UnknownHostException e) { } catch (UnknownHostException | SecurityException e) {
// no canonicalization, use old // not canonicalized or no permission to do so, use old
} }
nameParts[1] = hostName.toLowerCase(Locale.ENGLISH); nameParts[1] = hostName.toLowerCase(Locale.ENGLISH);
} }
...@@ -680,4 +688,7 @@ public class PrincipalName implements Cloneable { ...@@ -680,4 +688,7 @@ public class PrincipalName implements Cloneable {
return result; return result;
} }
public boolean isRealmDeduced() {
return realmDeduced;
}
} }
...@@ -47,6 +47,12 @@ import sun.security.krb5.internal.util.KerberosString; ...@@ -47,6 +47,12 @@ import sun.security.krb5.internal.util.KerberosString;
* This class is immutable. * This class is immutable.
*/ */
public class Realm implements Cloneable { public class Realm implements Cloneable {
public static final boolean AUTODEDUCEREALM =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"sun.security.krb5.autodeducerealm"));
private final String realm; // not null nor empty private final String realm; // not null nor empty
public Realm(String name) throws RealmException { public Realm(String name) throws RealmException {
......
...@@ -146,8 +146,9 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC ...@@ -146,8 +146,9 @@ public class CCacheInputStream extends KrbDataInputStream implements FileCCacheC
} }
try { try {
return new PrincipalName( return new PrincipalName(
type,
result.toArray(new String[result.size()]), result.toArray(new String[result.size()]),
type); Realm.getDefault());
} catch (RealmException re) { } catch (RealmException re) {
return null; return null;
} }
......
...@@ -858,8 +858,9 @@ public class KDC { ...@@ -858,8 +858,9 @@ public class KDC {
PrincipalName service = asReq.reqBody.sname; PrincipalName service = asReq.reqBody.sname;
if (options.containsKey(KDC.Option.RESP_NT)) { if (options.containsKey(KDC.Option.RESP_NT)) {
service = new PrincipalName(service.getNameStrings(), service = new PrincipalName((int)options.get(KDC.Option.RESP_NT),
(int)options.get(KDC.Option.RESP_NT)); service.getNameStrings(),
Realm.getDefault());
} }
try { try {
System.out.println(realm + "> " + asReq.reqBody.cname + System.out.println(realm + "> " + asReq.reqBody.cname +
......
...@@ -78,8 +78,11 @@ public class SSL extends SecurityManager { ...@@ -78,8 +78,11 @@ public class SSL extends SecurityManager {
return; return;
} }
ServicePermission p = (ServicePermission)perm; ServicePermission p = (ServicePermission)perm;
// ServicePermissions required to create GSSName are ignored
if (!p.getActions().isEmpty()) {
permChecks = permChecks + p.getActions().toUpperCase().charAt(0); permChecks = permChecks + p.getActions().toUpperCase().charAt(0);
} }
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
......
...@@ -40,22 +40,22 @@ public class Constructors { ...@@ -40,22 +40,22 @@ public class Constructors {
// Good ones // Good ones
type = PrincipalName.KRB_NT_UNKNOWN; type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R", "R", "a"); checkName("a", type, "R", "R", false, "a");
checkName("a@R2", type, "R", "R", "a"); checkName("a@R2", type, "R", "R", false, "a");
checkName("a/b", type, "R", "R", "a", "b"); checkName("a/b", type, "R", "R", false, "a", "b");
checkName("a/b@R2", type, "R", "R", "a", "b"); checkName("a/b@R2", type, "R", "R", false, "a", "b");
checkName("a/b/c", type, "R", "R", "a", "b", "c"); checkName("a/b/c", type, "R", "R", false, "a", "b", "c");
checkName("a/b/c@R2", type, "R", "R", "a", "b", "c"); checkName("a/b/c@R2", type, "R", "R", false, "a", "b", "c");
// Weird ones // Weird ones
checkName("a\\/b", type, "R", "R", "a/b"); checkName("a\\/b", type, "R", "R", false, "a/b");
checkName("a\\/b\\/c", type, "R", "R", "a/b/c"); checkName("a\\/b\\/c", type, "R", "R", false, "a/b/c");
checkName("a\\/b\\@R2", type, "R", "R", "a/b@R2"); checkName("a\\/b\\@R2", type, "R", "R", false, "a/b@R2");
// Bad ones // Bad ones
checkName("a", type, "", null); checkName("a", type, "", null, false);
checkName("a/", type, "R", null); checkName("a/", type, "R", null, false);
checkName("/a", type, "R", null); checkName("/a", type, "R", null, false);
checkName("a//b", type, "R", null); checkName("a//b", type, "R", null, false);
checkName("a@", type, null, null); checkName("a@", type, null, null, false);
type = PrincipalName.KRB_NT_SRV_HST; type = PrincipalName.KRB_NT_SRV_HST;
// Part 2: on realm choices // Part 2: on realm choices
...@@ -77,17 +77,17 @@ public class Constructors { ...@@ -77,17 +77,17 @@ public class Constructors {
if (testNoDefaultDomain) { if (testNoDefaultDomain) {
type = PrincipalName.KRB_NT_UNKNOWN; type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R1", "R1", "a"); // arg checkName("a", type, "R1", "R1", false, "a"); // arg
checkName("a@R1", type, null, "R1", "a"); // or r in name checkName("a@R1", type, null, "R1", false, "a"); // or r in name
checkName("a@R2", type, "R1", "R1", "a"); // arg over r checkName("a@R2", type, "R1", "R1", false, "a"); // arg over r
checkName("a", type, null, null); // fail if none checkName("a", type, null, null, false); // fail if none
checkName("a/b@R1", type, null, "R1", "a", "b"); checkName("a/b@R1", type, null, "R1", false, "a", "b");
type = PrincipalName.KRB_NT_SRV_HST; type = PrincipalName.KRB_NT_SRV_HST;
// Let's pray "b.h" won't be canonicalized // Let's pray "b.h" won't be canonicalized
checkName("a/b.h", type, "R1", "R1", "a", "b.h"); // arg checkName("a/b.h", type, "R1", "R1", false, "a", "b.h"); // arg
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name checkName("a/b.h@R1", type, null, "R1", false, "a", "b.h"); // or r in name
checkName("a/b.h@R1", type, "R2", "R2", "a", "b.h"); // arg over r checkName("a/b.h@R1", type, "R2", "R2", false, "a", "b.h"); // arg over r
checkName("a/b.h", type, null, null); // fail if none checkName("a/b.h", type, null, null, false); // fail if none
} }
// When there is default realm // When there is default realm
...@@ -96,25 +96,25 @@ public class Constructors { ...@@ -96,25 +96,25 @@ public class Constructors {
Config.refresh(); Config.refresh();
type = PrincipalName.KRB_NT_UNKNOWN; type = PrincipalName.KRB_NT_UNKNOWN;
checkName("a", type, "R1", "R1", "a"); // arg checkName("a", type, "R1", "R1", false, "a"); // arg
checkName("a@R1", type, null, "R1", "a"); // or r in name checkName("a@R1", type, null, "R1", false, "a"); // or r in name
checkName("a@R2", type, "R1", "R1", "a"); // arg over r checkName("a@R2", type, "R1", "R1", false, "a"); // arg over r
checkName("a", type, null, "R", "a"); // default checkName("a", type, null, "R", true, "a"); // default
checkName("a/b", type, null, "R", "a", "b"); checkName("a/b", type, null, "R", true, "a", "b");
type = PrincipalName.KRB_NT_SRV_HST; type = PrincipalName.KRB_NT_SRV_HST;
checkName("a/b.h3", type, "R1", "R1", "a", "b.h3"); // arg checkName("a/b.h3", type, "R1", "R1", false, "a", "b.h3"); // arg
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name checkName("a/b.h@R1", type, null, "R1", false, "a", "b.h"); // or r in name
checkName("a/b.h3@R2", type, "R1", "R1", "a", "b.h3"); // arg over r checkName("a/b.h3@R2", type, "R1", "R1", false, "a", "b.h3"); // arg over r
checkName("a/b.h2", type, "R1", "R1", "a", "b.h2"); // arg over map checkName("a/b.h2", type, "R1", "R1", false, "a", "b.h2"); // arg over map
checkName("a/b.h2@R1", type, null, "R1", "a", "b.h2"); // r over map checkName("a/b.h2@R1", type, null, "R1", false, "a", "b.h2"); // r over map
checkName("a/b.h2", type, null, "R2", "a", "b.h2"); // map checkName("a/b.h2", type, null, "R2", true, "a", "b.h2"); // map
checkName("a/b.h", type, null, "R", "a", "b.h"); // default checkName("a/b.h", type, null, "R", true, "a", "b.h"); // default
} }
// Check if the creation matches the expected output. // Check if the creation matches the expected output.
// Note: realm == null means creation failure // Note: realm == null means creation failure
static void checkName(String n, int t, String s, static void checkName(String n, int t, String s,
String realm, String... parts) String realm, boolean deduced, String... parts)
throws Exception { throws Exception {
PrincipalName pn = null; PrincipalName pn = null;
try { try {
...@@ -131,5 +131,8 @@ public class Constructors { ...@@ -131,5 +131,8 @@ public class Constructors {
throw new Exception(pn.toString() + " vs " throw new Exception(pn.toString() + " vs "
+ Arrays.toString(parts) + "@" + realm); + Arrays.toString(parts) + "@" + realm);
} }
if (deduced != pn.isRealmDeduced()) {
throw new Exception("pn.realmDeduced is " + pn.isRealmDeduced());
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册