1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.geronimo.javamail.authentication;
19
20 import java.lang.reflect.Constructor;
21 import java.util.List;
22 import java.util.Properties;
23
24 import org.apache.geronimo.javamail.util.ProtocolProperties;
25
26 public class AuthenticatorFactory {
27
28
29
30 public static final String AUTHENTICATION_PLAIN = "PLAIN";
31 public static final String AUTHENTICATION_LOGIN = "LOGIN";
32 public static final String AUTHENTICATION_CRAMMD5 = "CRAM-MD5";
33 public static final String AUTHENTICATION_DIGESTMD5 = "DIGEST-MD5";
34
35 static public ClientAuthenticator getAuthenticator(ProtocolProperties props, List mechanisms, String host, String username, String password, String authId, String realm)
36 {
37
38 if (authId == null) {
39 authId = username;
40 }
41
42
43 if (props.getBooleanProperty("sasl.enable", false)) {
44
45 String [] mechs = (String [])mechanisms.toArray(new String[mechanisms.size()]);
46
47 try {
48
49
50 Class authenticatorClass = Class.forName("org.apache.geronimo.javamal.authentication.SASLAuthenticator");
51 Constructor c = authenticatorClass.getConstructor(new Class[] {
52 (new String[0]).getClass(),
53 Properties.class,
54 String.class,
55 String.class,
56 String.class,
57 String.class,
58 String.class,
59 String.class
60 });
61
62 Object[] args = { mechs, props.getProperties(), props.getProtocol(), host, realm, authId, username, password };
63
64 return (ClientAuthenticator)c.newInstance(args);
65 } catch (Throwable e) {
66
67
68 }
69 }
70
71
72
73
74 if (mechanisms.contains(AUTHENTICATION_DIGESTMD5)) {
75 return new DigestMD5Authenticator(host, username, password, realm);
76 } else if (mechanisms.contains(AUTHENTICATION_CRAMMD5)) {
77 return new CramMD5Authenticator(username, password);
78 } else if (mechanisms.contains(AUTHENTICATION_LOGIN)) {
79 return new LoginAuthenticator(username, password);
80 } else if (mechanisms.contains(AUTHENTICATION_PLAIN)) {
81 return new PlainAuthenticator(username, password);
82 } else {
83
84 return null;
85 }
86 }
87 }
88