001: /*
002: * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.jndi.ldap;
027:
028: import java.util.Arrays; // JDK 1.2
029: import java.util.Hashtable;
030:
031: import java.io.OutputStream;
032: import javax.naming.ldap.Control;
033:
034: /**
035: * Extends SimpleClientId to add property values specific for Digest-MD5.
036: * This includes:
037: * realm, authzid, qop, strength, maxbuffer, mutual-auth, reuse,
038: * all policy-related selection properties.
039: * Two DigestClientIds are identical iff they pass the SimpleClientId
040: * equals() test and that all of these property values are the same.
041: *
042: * @author Rosanna Lee
043: */
044: class DigestClientId extends SimpleClientId {
045: private static final String[] SASL_PROPS = {
046: "java.naming.security.sasl.authorizationId",
047: "java.naming.security.sasl.realm",
048: "javax.security.sasl.qop", "javax.security.sasl.strength",
049: "javax.security.sasl.reuse",
050: "javax.security.sasl.server.authentication",
051: "javax.security.sasl.maxbuffer",
052: "javax.security.sasl.policy.noplaintext",
053: "javax.security.sasl.policy.noactive",
054: "javax.security.sasl.policy.nodictionary",
055: "javax.security.sasl.policy.noanonymous",
056: "javax.security.sasl.policy.forward",
057: "javax.security.sasl.policy.credentials", };
058:
059: final private String[] propvals;
060: final private int myHash;
061: private int pHash = 0;
062:
063: DigestClientId(int version, String hostname, int port,
064: String protocol, Control[] bindCtls, OutputStream trace,
065: String socketFactory, String username, Object passwd,
066: Hashtable env) {
067:
068: super (version, hostname, port, protocol, bindCtls, trace,
069: socketFactory, username, passwd);
070:
071: if (env == null) {
072: propvals = null;
073: } else {
074: // Could be smarter and apply default values for props
075: // but for now, we just record and check exact matches
076: propvals = new String[SASL_PROPS.length];
077: for (int i = 0; i < SASL_PROPS.length; i++) {
078: propvals[i] = (String) env.get(SASL_PROPS[i]);
079: if (propvals[i] != null) {
080: pHash = pHash * 31 + propvals[i].hashCode();
081: }
082: }
083: }
084: myHash = super .hashCode() + pHash;
085: }
086:
087: public boolean equals(Object obj) {
088: if (!(obj instanceof DigestClientId)) {
089: return false;
090: }
091: DigestClientId other = (DigestClientId) obj;
092: return myHash == other.myHash && pHash == other.pHash
093: && super .equals(obj)
094: && Arrays.equals(propvals, other.propvals);
095: }
096:
097: public int hashCode() {
098: return myHash;
099: }
100:
101: public String toString() {
102: if (propvals != null) {
103: StringBuffer buf = new StringBuffer();
104: for (int i = 0; i < propvals.length; i++) {
105: buf.append(':');
106: if (propvals[i] != null) {
107: buf.append(propvals[i]);
108: }
109: }
110: return super.toString() + buf.toString();
111: } else {
112: return super.toString();
113: }
114: }
115: }
|