in geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/authentication/AuthenticatorFactory.java [55:119]
static public ClientAuthenticator getAuthenticator(ProtocolProperties props, List mechanisms, String host, String username, String password, String authId, String realm)
{
// if the authorization id isn't given, then this is the same as the logged in user name.
if (authId == null) {
authId = username;
}
// if SASL is enabled, try getting a SASL authenticator first
if (props.getBooleanProperty("sasl.enable", false)) {
// we need to convert the mechanisms map into an array of strings for SASL.
String [] mechs = (String [])mechanisms.toArray(new String[mechanisms.size()]);
try {
// need to try to load this using reflection since it has references to
// the SASL API. That's only available with 1.5 or later.
Class authenticatorClass = null;
//We obtain only the SASL mechanisms provided by the client properties
final List saslMechanisms = getSaslMechanisms(props);
if (saslMechanisms != null && saslMechanisms.contains(AUTHENTICATION_XOAUTH2)) {
authenticatorClass = Class.forName(
"org.apache.geronimo.mail.authentication.XOAUTH2Authenticator");
} else {
authenticatorClass = Class.forName(
"org.apache.geronimo.mail.authentication.SASLAuthenticator");
}
Constructor c = authenticatorClass.getConstructor(new Class[] {
(new String[0]).getClass(),
Properties.class,
String.class,
String.class,
String.class,
String.class,
String.class,
String.class
});
Object[] args = { mechs, props.getProperties(), props.getProtocol(), host, realm, authId, username, password };
return (ClientAuthenticator)c.newInstance(args);
} catch (Throwable e) {
// Any exception is likely because we're running on 1.4 and can't use the Sasl API.
// just ignore and use our fallback implementations.
}
}
// now go through the progression of mechanisms we support, from the
// most secure to the least secure.
if (mechanisms.contains(AUTHENTICATION_DIGESTMD5)) {
return new DigestMD5Authenticator(host, username, password, realm);
} else if (mechanisms.contains(AUTHENTICATION_CRAMMD5)) {
return new CramMD5Authenticator(username, password);
} else if (mechanisms.contains(AUTHENTICATION_LOGIN)) {
return new LoginAuthenticator(username, password);
} else if (mechanisms.contains(AUTHENTICATION_PLAIN)) {
return new PlainAuthenticator(authId, username, password);
} else {
// can't find a mechanism we support in common
return null;
}
}