diff options
| author | Keith Wall <kwall@apache.org> | 2012-06-30 17:17:26 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2012-06-30 17:17:26 +0000 |
| commit | c7dfca2b82359126057a3533822fad2f92a9b257 (patch) | |
| tree | 8772bbf461fcb53ae57531916682cc6b8d4e5eb7 /java/client | |
| parent | 88a10ffdbbf072c845c999ba6196c2342239b7d2 (diff) | |
| download | qpid-python-c7dfca2b82359126057a3533822fad2f92a9b257.tar.gz | |
QPID-4090: Bug fix: allow Java client to make connections to Java Broker using CRAM-MD5-HASHED mechanism.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1355775 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client')
2 files changed, 93 insertions, 3 deletions
diff --git a/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClient.java b/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClient.java new file mode 100644 index 0000000000..9965176772 --- /dev/null +++ b/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClient.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.client.security.crammd5hashed; + +import java.util.Map; + +import javax.security.auth.callback.CallbackHandler; +import javax.security.sasl.Sasl; +import javax.security.sasl.SaslClient; +import javax.security.sasl.SaslException; + +import org.apache.qpid.client.security.UsernameHashedPasswordCallbackHandler; + +/** + * A {@link CRAMMD5HashedSaslClient} merely wraps an instance of a CRAM-MD5 SASL client delegating + * all method calls to it, except {@link #getMechanismName()} which returns "CRAM-MD5-HASHED". + * + * This mechanism must be used with {@link UsernameHashedPasswordCallbackHandler} which is responsible + * for the additional hash of the password. + */ +public class CRAMMD5HashedSaslClient implements SaslClient +{ + private final SaslClient _cramMd5SaslClient; + + public CRAMMD5HashedSaslClient(String authorizationId, String protocol, String serverName, Map<String, ?> props, CallbackHandler cbh) throws SaslException + { + super(); + String[] mechanisms = {"CRAM-MD5"}; + _cramMd5SaslClient = Sasl.createSaslClient(mechanisms, authorizationId, protocol, serverName, props, cbh); + } + + public void dispose() throws SaslException + { + _cramMd5SaslClient.dispose(); + } + + public String getMechanismName() + { + return CRAMMD5HashedSaslClientFactory.MECHANISM; + } + + public byte[] evaluateChallenge(byte[] challenge) throws SaslException + { + return _cramMd5SaslClient.evaluateChallenge(challenge); + } + + + public Object getNegotiatedProperty(String propName) + { + return _cramMd5SaslClient.getNegotiatedProperty(propName); + } + + public boolean hasInitialResponse() + { + return _cramMd5SaslClient.hasInitialResponse(); + } + + public boolean isComplete() + { + return _cramMd5SaslClient.isComplete(); + } + + public byte[] unwrap(byte[] incoming, int offset, int len) + throws SaslException + { + return _cramMd5SaslClient.unwrap(incoming, offset, len); + } + + public byte[] wrap(byte[] outgoing, int offset, int len) + throws SaslException + { + return _cramMd5SaslClient.wrap(outgoing, offset, len); + } +} diff --git a/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClientFactory.java b/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClientFactory.java index cb989f7919..b3ce1a0d23 100644 --- a/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClientFactory.java +++ b/java/client/src/main/java/org/apache/qpid/client/security/crammd5hashed/CRAMMD5HashedSaslClientFactory.java @@ -44,14 +44,13 @@ public class CRAMMD5HashedSaslClientFactory implements SaslClientFactory throw new SaslException("CallbackHandler must not be null"); } - String[] mechs = {"CRAM-MD5"}; - return Sasl.createSaslClient(mechs, authorizationId, protocol, serverName, props, cbh); + return new CRAMMD5HashedSaslClient(authorizationId, protocol, serverName, props, cbh); } } return null; } - public String[] getMechanismNames(Map props) + public String[] getMechanismNames(Map<String,?> props) { if (props != null) { |
