Authenticate using one of the non-SASL mechanisms. @param p the IMAPProtocol object @param authzid the authorization ID @param user the user name @param password the password @exception ProtocolException on failures
(IMAPProtocol p, String authzid, String user, String password)
| 867 | * @exception ProtocolException on failures |
| 868 | */ |
| 869 | private void authenticate(IMAPProtocol p, String authzid, |
| 870 | String user, String password) |
| 871 | throws ProtocolException { |
| 872 | // this list must match the "if" statements below |
| 873 | String defaultAuthenticationMechanisms = "PLAIN LOGIN NTLM XOAUTH2"; |
| 874 | |
| 875 | // setting mail.imap.auth.mechanisms controls which mechanisms will |
| 876 | // be used, and in what order they'll be considered. only the first |
| 877 | // match is used. |
| 878 | String mechs = session.getProperty("mail." + name + ".auth.mechanisms"); |
| 879 | |
| 880 | if (mechs == null) |
| 881 | mechs = defaultAuthenticationMechanisms; |
| 882 | |
| 883 | /* |
| 884 | * Loop through the list of mechanisms supplied by the user |
| 885 | * (or defaulted) and try each in turn. If the server supports |
| 886 | * the mechanism and we have an authenticator for the mechanism, |
| 887 | * and it hasn't been disabled, use it. |
| 888 | */ |
| 889 | boolean xoauth2 = false; |
| 890 | ProtocolException pex = null; |
| 891 | StringTokenizer st = new StringTokenizer(mechs); |
| 892 | while (st.hasMoreTokens()) { |
| 893 | String m = st.nextToken(); |
| 894 | m = m.toUpperCase(Locale.ENGLISH); |
| 895 | |
| 896 | /* |
| 897 | * If using the default mechanisms, check if this one is disabled. |
| 898 | */ |
| 899 | if (mechs == defaultAuthenticationMechanisms) { |
| 900 | String dprop = "mail." + name + ".auth." + |
| 901 | m.toLowerCase(Locale.ENGLISH) + ".disable"; |
| 902 | boolean disabled = PropUtil.getBooleanProperty( |
| 903 | session.getProperties(), |
| 904 | dprop, m.equals("XOAUTH2")); |
| 905 | if (disabled) { |
| 906 | if (logger.isLoggable(Level.FINE)) |
| 907 | logger.fine("mechanism " + m + |
| 908 | " disabled by property: " + dprop); |
| 909 | continue; |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | if (!(p.hasCapability("AUTH=" + m) || |
| 914 | (m.equals("LOGIN") && p.hasCapability("AUTH-LOGIN")))) { |
| 915 | logger.log(Level.FINE, "mechanism {0} not supported by server", |
| 916 | m); |
| 917 | continue; |
| 918 | } |
| 919 | |
| 920 | try { |
| 921 | if (m.equals("PLAIN")) { |
| 922 | p.authplain(authzid, user, password); |
| 923 | return; |
| 924 | } |
| 925 | else if (m.equals("LOGIN")) { |
| 926 | p.authlogin(user, password); |
no test coverage detected