KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > util > AuthenticationManager


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.mail.util;
18
19
20 public class AuthenticationManager {
21     
22     // Default
23
public static final int MOST_SECURE = 0;
24     
25     // Protocol defined Mechanisms
26
public static final int USER = 1;
27     public static final int LOGIN = 2;
28     public static final int APOP = 3;
29     
30     //SMTP
31
public static final int POP_BEFORE_SMTP = 4;
32     public static final int NONE = 5;
33     
34     
35     // SASL Mechanisms
36
public static final int SASL = 10;
37     public static final int SASL_PLAIN = 10;
38     public static final int SASL_LOGIN= 11;
39     public static final int SASL_DIGEST_MD5 = 12;
40
41     public static final String JavaDoc[] SaslMechanism = { "PLAIN", "LOGIN", "DIGEST-MD5" };
42     
43     public static int getSaslCode(String JavaDoc mechanism) {
44         for( int i=0; i<SaslMechanism.length; i++) {
45             if( SaslMechanism[i].equalsIgnoreCase(mechanism)) {
46                 return SASL+i;
47             }
48         }
49         
50         return -1;
51     }
52     
53     public static String JavaDoc getSaslName(int code) {
54         return SaslMechanism[code-SASL];
55     }
56     
57     public static int compare(int code1, int code2) {
58         // We compare three classes: plain, md5 and popbeforesmtp
59
int a = 1;
60         
61         if( code1 == SASL_DIGEST_MD5 || code1 == APOP) {
62             a = 2;
63         }
64         
65         if( code1 == POP_BEFORE_SMTP) {
66             a = 0;
67         }
68         
69         
70         int b = 1;
71         
72         if( code2 == SASL_DIGEST_MD5 || code2 == APOP) {
73             b = 2;
74         }
75         
76         if( code2 == POP_BEFORE_SMTP) {
77             b = 0;
78         }
79
80         
81         
82         if( a==b ) return 0;
83         if( a < b ) return -1;
84         else return 1;
85     }
86     
87     public static String JavaDoc getLocalizedString(int code) {
88         switch( code ) {
89             case MOST_SECURE : {
90                 return MailResourceLoader.getString("dialog",
91                         "account", "authentication_securest");
92             }
93             
94             case USER : {
95                 return MailResourceLoader.getString("dialog",
96                         "account", "authentication_user");
97             }
98
99             case APOP : {
100                 return MailResourceLoader.getString("dialog",
101                         "account", "authentication_apop");
102             }
103
104             case LOGIN : {
105                 return MailResourceLoader.getString("dialog",
106                         "account", "authentication_login");
107             }
108
109             case SASL_PLAIN : {
110                 return MailResourceLoader.getString("dialog",
111                         "account", "authentication_sasl_plain");
112             }
113
114             case SASL_LOGIN : {
115                 return MailResourceLoader.getString("dialog",
116                         "account", "authentication_sasl_login");
117             }
118
119             case SASL_DIGEST_MD5 : {
120                 return MailResourceLoader.getString("dialog",
121                         "account", "authentication_sasl_digest_md5");
122             }
123
124             case POP_BEFORE_SMTP : {
125                 return MailResourceLoader.getString("dialog",
126                         "account", "authentication_pop_before_smtp");
127             }
128
129             default : {
130                 return "Invalid Code";
131             }
132         }
133     }
134     
135 }
136
Popular Tags