Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/DigestClientId.java
41161 views
1
/*
2
* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package com.sun.jndi.ldap;
27
28
import java.util.Arrays; // JDK 1.2
29
import java.util.Hashtable;
30
31
import java.io.OutputStream;
32
import javax.naming.ldap.Control;
33
34
/**
35
* Extends SimpleClientId to add property values specific for Digest-MD5.
36
* This includes:
37
* realm, authzid, qop, strength, maxbuffer, mutual-auth, reuse,
38
* all policy-related selection properties.
39
* Two DigestClientIds are identical iff they pass the SimpleClientId
40
* equals() test and that all of these property values are the same.
41
*
42
* @author Rosanna Lee
43
*/
44
class DigestClientId extends SimpleClientId {
45
private static final String[] SASL_PROPS = {
46
"java.naming.security.sasl.authorizationId",
47
"java.naming.security.sasl.realm",
48
"javax.security.sasl.qop",
49
"javax.security.sasl.strength",
50
"javax.security.sasl.reuse",
51
"javax.security.sasl.server.authentication",
52
"javax.security.sasl.maxbuffer",
53
"javax.security.sasl.policy.noplaintext",
54
"javax.security.sasl.policy.noactive",
55
"javax.security.sasl.policy.nodictionary",
56
"javax.security.sasl.policy.noanonymous",
57
"javax.security.sasl.policy.forward",
58
"javax.security.sasl.policy.credentials",
59
};
60
61
private final String[] propvals;
62
private final int myHash;
63
64
DigestClientId(int version, String hostname, int port,
65
String protocol, Control[] bindCtls, OutputStream trace,
66
String socketFactory, String username,
67
Object passwd, Hashtable<?,?> env) {
68
69
super(version, hostname, port, protocol, bindCtls, trace,
70
socketFactory, username, passwd);
71
72
if (env == null) {
73
propvals = null;
74
} else {
75
// Could be smarter and apply default values for props
76
// but for now, we just record and check exact matches
77
propvals = new String[SASL_PROPS.length];
78
for (int i = 0; i < SASL_PROPS.length; i++) {
79
propvals[i] = (String) env.get(SASL_PROPS[i]);
80
}
81
}
82
myHash = super.hashCode() ^ Arrays.hashCode(propvals);
83
}
84
85
public boolean equals(Object obj) {
86
if (!(obj instanceof DigestClientId)) {
87
return false;
88
}
89
DigestClientId other = (DigestClientId)obj;
90
return myHash == other.myHash
91
&& super.equals(obj)
92
&& Arrays.equals(propvals, other.propvals);
93
}
94
95
public int hashCode() {
96
return myHash;
97
}
98
99
public String toString() {
100
if (propvals != null) {
101
StringBuilder sb = new StringBuilder();
102
for (int i = 0; i < propvals.length; i++) {
103
sb.append(':');
104
if (propvals[i] != null) {
105
sb.append(propvals[i]);
106
}
107
}
108
return super.toString() + sb.toString();
109
} else {
110
return super.toString();
111
}
112
}
113
}
114
115