001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.mail.util;
018:
019: public class AuthenticationManager {
020:
021: // Default
022: public static final int MOST_SECURE = 0;
023:
024: // Protocol defined Mechanisms
025: public static final int USER = 1;
026: public static final int LOGIN = 2;
027: public static final int APOP = 3;
028:
029: //SMTP
030: public static final int POP_BEFORE_SMTP = 4;
031: public static final int NONE = 5;
032:
033: // SASL Mechanisms
034: public static final int SASL = 10;
035: public static final int SASL_PLAIN = 10;
036: public static final int SASL_LOGIN = 11;
037: public static final int SASL_DIGEST_MD5 = 12;
038:
039: public static final String[] SaslMechanism = { "PLAIN", "LOGIN",
040: "DIGEST-MD5" };
041:
042: public static int getSaslCode(String mechanism) {
043: for (int i = 0; i < SaslMechanism.length; i++) {
044: if (SaslMechanism[i].equalsIgnoreCase(mechanism)) {
045: return SASL + i;
046: }
047: }
048:
049: return -1;
050: }
051:
052: public static String getSaslName(int code) {
053: return SaslMechanism[code - SASL];
054: }
055:
056: public static int compare(int code1, int code2) {
057: // We compare three classes: plain, md5 and popbeforesmtp
058: int a = 1;
059:
060: if (code1 == SASL_DIGEST_MD5 || code1 == APOP) {
061: a = 2;
062: }
063:
064: if (code1 == POP_BEFORE_SMTP) {
065: a = 0;
066: }
067:
068: int b = 1;
069:
070: if (code2 == SASL_DIGEST_MD5 || code2 == APOP) {
071: b = 2;
072: }
073:
074: if (code2 == POP_BEFORE_SMTP) {
075: b = 0;
076: }
077:
078: if (a == b)
079: return 0;
080: if (a < b)
081: return -1;
082: else
083: return 1;
084: }
085:
086: public static String getLocalizedString(int code) {
087: switch (code) {
088: case MOST_SECURE: {
089: return MailResourceLoader.getString("dialog", "account",
090: "authentication_securest");
091: }
092:
093: case USER: {
094: return MailResourceLoader.getString("dialog", "account",
095: "authentication_user");
096: }
097:
098: case APOP: {
099: return MailResourceLoader.getString("dialog", "account",
100: "authentication_apop");
101: }
102:
103: case LOGIN: {
104: return MailResourceLoader.getString("dialog", "account",
105: "authentication_login");
106: }
107:
108: case SASL_PLAIN: {
109: return MailResourceLoader.getString("dialog", "account",
110: "authentication_sasl_plain");
111: }
112:
113: case SASL_LOGIN: {
114: return MailResourceLoader.getString("dialog", "account",
115: "authentication_sasl_login");
116: }
117:
118: case SASL_DIGEST_MD5: {
119: return MailResourceLoader.getString("dialog", "account",
120: "authentication_sasl_digest_md5");
121: }
122:
123: case POP_BEFORE_SMTP: {
124: return MailResourceLoader.getString("dialog", "account",
125: "authentication_pop_before_smtp");
126: }
127:
128: default: {
129: return "Invalid Code";
130: }
131: }
132: }
133:
134: }
|