blob: 2fa1ebd8f12181e90b1795580a1cfc408027703b [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/*
2 * Copyright 2009 Rene Treffer
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package de.measite.smack;
18
19import java.util.Map;
20
21import com.novell.sasl.client.DigestMD5SaslClient;
22
23import org.apache.harmony.javax.security.auth.callback.CallbackHandler;
24import org.apache.harmony.javax.security.sasl.SaslClient;
25import org.apache.harmony.javax.security.sasl.SaslException;
26import org.apache.qpid.management.common.sasl.PlainSaslClient;
27
28public class SaslClientFactory implements
29 org.apache.harmony.javax.security.sasl.SaslClientFactory {
30
31 @Override
32 public SaslClient createSaslClient(String[] mechanisms,
33 String authorizationId, String protocol, String serverName,
34 Map<String, ?> props, CallbackHandler cbh) throws SaslException {
35 for (String mech: mechanisms) {
36 if ("PLAIN".equals(mech)) {
37 return new PlainSaslClient(authorizationId, cbh);
38 } else
39 if ("DIGEST-MD5".equals(mech)) {
40 return DigestMD5SaslClient.getClient(
41 authorizationId,
42 protocol,
43 serverName,
44 props,
45 cbh
46 );
47 }
48 }
49 return null;
50 }
51
52 @Override
53 public String[] getMechanismNames(Map<String, ?> props) {
54 return new String[]{
55 "PLAIN",
56 "DIGEST-MD5"
57 };
58 }
59
60}