Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/DigestClientId.java
41161 views
/*1* Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import java.util.Arrays; // JDK 1.228import java.util.Hashtable;2930import java.io.OutputStream;31import javax.naming.ldap.Control;3233/**34* Extends SimpleClientId to add property values specific for Digest-MD5.35* This includes:36* realm, authzid, qop, strength, maxbuffer, mutual-auth, reuse,37* all policy-related selection properties.38* Two DigestClientIds are identical iff they pass the SimpleClientId39* equals() test and that all of these property values are the same.40*41* @author Rosanna Lee42*/43class DigestClientId extends SimpleClientId {44private static final String[] SASL_PROPS = {45"java.naming.security.sasl.authorizationId",46"java.naming.security.sasl.realm",47"javax.security.sasl.qop",48"javax.security.sasl.strength",49"javax.security.sasl.reuse",50"javax.security.sasl.server.authentication",51"javax.security.sasl.maxbuffer",52"javax.security.sasl.policy.noplaintext",53"javax.security.sasl.policy.noactive",54"javax.security.sasl.policy.nodictionary",55"javax.security.sasl.policy.noanonymous",56"javax.security.sasl.policy.forward",57"javax.security.sasl.policy.credentials",58};5960private final String[] propvals;61private final int myHash;6263DigestClientId(int version, String hostname, int port,64String protocol, Control[] bindCtls, OutputStream trace,65String socketFactory, String username,66Object passwd, Hashtable<?,?> env) {6768super(version, hostname, port, protocol, bindCtls, trace,69socketFactory, username, passwd);7071if (env == null) {72propvals = null;73} else {74// Could be smarter and apply default values for props75// but for now, we just record and check exact matches76propvals = new String[SASL_PROPS.length];77for (int i = 0; i < SASL_PROPS.length; i++) {78propvals[i] = (String) env.get(SASL_PROPS[i]);79}80}81myHash = super.hashCode() ^ Arrays.hashCode(propvals);82}8384public boolean equals(Object obj) {85if (!(obj instanceof DigestClientId)) {86return false;87}88DigestClientId other = (DigestClientId)obj;89return myHash == other.myHash90&& super.equals(obj)91&& Arrays.equals(propvals, other.propvals);92}9394public int hashCode() {95return myHash;96}9798public String toString() {99if (propvals != null) {100StringBuilder sb = new StringBuilder();101for (int i = 0; i < propvals.length; i++) {102sb.append(':');103if (propvals[i] != null) {104sb.append(propvals[i]);105}106}107return super.toString() + sb.toString();108} else {109return super.toString();110}111}112}113114115