Skip to content

Commit d6a5f1b

Browse files
committed
8344768: Consider removing "sun.security.krb5.autodeducerealm" system property
Reviewed-by: mullan
1 parent 7c944ee commit d6a5f1b

File tree

3 files changed

+39
-63
lines changed

3 files changed

+39
-63
lines changed

src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java

+2-19
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ public class PrincipalName implements Cloneable {
9999
* TGS Name
100100
*/
101101
public static final String TGS_DEFAULT_SRV_NAME = "krbtgt";
102-
public static final int TGS_DEFAULT_NT = KRB_NT_SRV_INST;
103102

104103
public static final char NAME_COMPONENT_SEPARATOR = '/';
105104
public static final char NAME_REALM_SEPARATOR = '@';
106105
public static final char REALM_COMPONENT_SEPARATOR = '.';
107106

108107
public static final String NAME_COMPONENT_SEPARATOR_STR = "/";
109108
public static final String NAME_REALM_SEPARATOR_STR = "@";
110-
public static final String REALM_COMPONENT_SEPARATOR_STR = ".";
111109

112110
private static final boolean NAME_CASE_SENSITIVE_IN_MATCH
113111
= "true".equalsIgnoreCase(
@@ -135,12 +133,6 @@ public class PrincipalName implements Cloneable {
135133
private final Realm nameRealm; // not null
136134

137135

138-
/**
139-
* When constructing a PrincipalName, whether the realm is included in
140-
* the input, or deduced from default realm or domain-realm mapping.
141-
*/
142-
private final boolean realmDeduced;
143-
144136
// cached default salt, not used in clone
145137
private transient String salt = null;
146138

@@ -161,7 +153,6 @@ public PrincipalName(int nameType, String[] nameStrings, Realm nameRealm) {
161153
this.nameType = nameType;
162154
this.nameStrings = nameStrings.clone();
163155
this.nameRealm = nameRealm;
164-
this.realmDeduced = false;
165156
}
166157

167158
// Warning: called by NativeCreds.c
@@ -251,7 +242,6 @@ public PrincipalName(DerValue encoding, Realm realm)
251242
if (realm == null) {
252243
throw new IllegalArgumentException("Null realm not allowed");
253244
}
254-
realmDeduced = false;
255245
nameRealm = realm;
256246
DerValue der;
257247
if (encoding == null) {
@@ -405,9 +395,6 @@ public PrincipalName(String name, int type, String realm)
405395
realm = Realm.parseRealmAtSeparator(name);
406396
}
407397

408-
// No realm info from parameter and string, must deduce later
409-
realmDeduced = realm == null;
410-
411398
switch (type) {
412399
case KRB_NT_SRV_HST:
413400
if (nameParts.length >= 2) {
@@ -437,8 +424,8 @@ public PrincipalName(String name, int type, String realm)
437424
hostName.toLowerCase(Locale.ENGLISH) + ".")) {
438425
hostName = canonicalized;
439426
}
440-
} catch (UnknownHostException | SecurityException e) {
441-
// not canonicalized or no permission to do so, use old
427+
} catch (UnknownHostException e) {
428+
// not canonicalized, use old
442429
}
443430
if (hostName.endsWith(".")) {
444431
hostName = hostName.substring(0, hostName.length() - 1);
@@ -726,8 +713,4 @@ static String mapHostToRealm(String name) {
726713
}
727714
return result;
728715
}
729-
730-
public boolean isRealmDeduced() {
731-
return realmDeduced;
732-
}
733716
}

src/java.security.jgss/share/classes/sun/security/krb5/Realm.java

-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
*/
4848
public class Realm implements Cloneable {
4949

50-
public static final boolean AUTODEDUCEREALM =
51-
Boolean.getBoolean("sun.security.krb5.autodeducerealm");
52-
5350
private final String realm; // not null nor empty
5451

5552
public Realm(String name) throws RealmException {

test/jdk/sun/security/krb5/name/Constructors.java

+37-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,23 +41,22 @@ public static void main(String[] args) throws Exception {
4141

4242
// Good ones
4343
type = PrincipalName.KRB_NT_UNKNOWN;
44-
checkName("a", type, "R", "R", false, "a");
45-
checkName("a@R2", type, "R", "R", false, "a");
46-
checkName("a/b", type, "R", "R", false, "a", "b");
47-
checkName("a/b@R2", type, "R", "R", false, "a", "b");
48-
checkName("a/b/c", type, "R", "R", false, "a", "b", "c");
49-
checkName("a/b/c@R2", type, "R", "R", false, "a", "b", "c");
44+
checkName("a", type, "R", "R", "a");
45+
checkName("a@R2", type, "R", "R", "a");
46+
checkName("a/b", type, "R", "R", "a", "b");
47+
checkName("a/b@R2", type, "R", "R", "a", "b");
48+
checkName("a/b/c", type, "R", "R", "a", "b", "c");
49+
checkName("a/b/c@R2", type, "R", "R", "a", "b", "c");
5050
// Weird ones
51-
checkName("a\\/b", type, "R", "R", false, "a/b");
52-
checkName("a\\/b\\/c", type, "R", "R", false, "a/b/c");
53-
checkName("a\\/b\\@R2", type, "R", "R", false, "a/b@R2");
51+
checkName("a\\/b", type, "R", "R", "a/b");
52+
checkName("a\\/b\\/c", type, "R", "R", "a/b/c");
53+
checkName("a\\/b\\@R2", type, "R", "R", "a/b@R2");
5454
// Bad ones
55-
checkName("a", type, "", null, false);
56-
checkName("a/", type, "R", null, false);
57-
checkName("/a", type, "R", null, false);
58-
checkName("a//b", type, "R", null, false);
59-
checkName("a@", type, null, null, false);
60-
type = PrincipalName.KRB_NT_SRV_HST;
55+
checkName("a", type, "", null);
56+
checkName("a/", type, "R", null);
57+
checkName("/a", type, "R", null);
58+
checkName("a//b", type, "R", null);
59+
checkName("a@", type, null, null);
6160

6261
// Part 2: on realm choices
6362

@@ -78,17 +77,17 @@ public static void main(String[] args) throws Exception {
7877

7978
if (testNoDefaultDomain) {
8079
type = PrincipalName.KRB_NT_UNKNOWN;
81-
checkName("a", type, "R1", "R1", false, "a"); // arg
82-
checkName("a@R1", type, null, "R1", false, "a"); // or r in name
83-
checkName("a@R2", type, "R1", "R1", false, "a"); // arg over r
84-
checkName("a", type, null, null, false); // fail if none
85-
checkName("a/b@R1", type, null, "R1", false, "a", "b");
80+
checkName("a", type, "R1", "R1", "a"); // arg
81+
checkName("a@R1", type, null, "R1", "a"); // or r in name
82+
checkName("a@R2", type, "R1", "R1", "a"); // arg over r
83+
checkName("a", type, null, null); // fail if none
84+
checkName("a/b@R1", type, null, "R1", "a", "b");
8685
type = PrincipalName.KRB_NT_SRV_HST;
8786
// Let's pray "b.h" won't be canonicalized
88-
checkName("a/b.h", type, "R1", "R1", false, "a", "b.h"); // arg
89-
checkName("a/b.h@R1", type, null, "R1", false, "a", "b.h"); // or r in name
90-
checkName("a/b.h@R1", type, "R2", "R2", false, "a", "b.h"); // arg over r
91-
checkName("a/b.h", type, null, null, false); // fail if none
87+
checkName("a/b.h", type, "R1", "R1", "a", "b.h"); // arg
88+
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name
89+
checkName("a/b.h@R1", type, "R2", "R2", "a", "b.h"); // arg over r
90+
checkName("a/b.h", type, null, null); // fail if none
9291
}
9392

9493
// When there is default realm
@@ -97,25 +96,25 @@ public static void main(String[] args) throws Exception {
9796
Config.refresh();
9897

9998
type = PrincipalName.KRB_NT_UNKNOWN;
100-
checkName("a", type, "R1", "R1", false, "a"); // arg
101-
checkName("a@R1", type, null, "R1", false, "a"); // or r in name
102-
checkName("a@R2", type, "R1", "R1", false, "a"); // arg over r
103-
checkName("a", type, null, "R", true, "a"); // default
104-
checkName("a/b", type, null, "R", true, "a", "b");
99+
checkName("a", type, "R1", "R1", "a"); // arg
100+
checkName("a@R1", type, null, "R1", "a"); // or r in name
101+
checkName("a@R2", type, "R1", "R1", "a"); // arg over r
102+
checkName("a", type, null, "R", "a"); // default
103+
checkName("a/b", type, null, "R", "a", "b");
105104
type = PrincipalName.KRB_NT_SRV_HST;
106-
checkName("a/b.h3", type, "R1", "R1", false, "a", "b.h3"); // arg
107-
checkName("a/b.h@R1", type, null, "R1", false, "a", "b.h"); // or r in name
108-
checkName("a/b.h3@R2", type, "R1", "R1", false, "a", "b.h3"); // arg over r
109-
checkName("a/b.h2", type, "R1", "R1", false, "a", "b.h2"); // arg over map
110-
checkName("a/b.h2@R1", type, null, "R1", false, "a", "b.h2"); // r over map
111-
checkName("a/b.h2", type, null, "R2", true, "a", "b.h2"); // map
112-
checkName("a/b.h", type, null, "R", true, "a", "b.h"); // default
105+
checkName("a/b.h3", type, "R1", "R1", "a", "b.h3"); // arg
106+
checkName("a/b.h@R1", type, null, "R1", "a", "b.h"); // or r in name
107+
checkName("a/b.h3@R2", type, "R1", "R1", "a", "b.h3"); // arg over r
108+
checkName("a/b.h2", type, "R1", "R1", "a", "b.h2"); // arg over map
109+
checkName("a/b.h2@R1", type, null, "R1", "a", "b.h2"); // r over map
110+
checkName("a/b.h2", type, null, "R2", "a", "b.h2"); // map
111+
checkName("a/b.h", type, null, "R", "a", "b.h"); // default
113112
}
114113

115114
// Check if the creation matches the expected output.
116115
// Note: realm == null means creation failure
117116
static void checkName(String n, int t, String s,
118-
String realm, boolean deduced, String... parts)
117+
String realm, String... parts)
119118
throws Exception {
120119
PrincipalName pn = null;
121120
try {
@@ -132,8 +131,5 @@ static void checkName(String n, int t, String s,
132131
throw new Exception(pn.toString() + " vs "
133132
+ Arrays.toString(parts) + "@" + realm);
134133
}
135-
if (deduced != pn.isRealmDeduced()) {
136-
throw new Exception("pn.realmDeduced is " + pn.isRealmDeduced());
137-
}
138134
}
139135
}

0 commit comments

Comments
 (0)