KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > exceptions > AuthenticatorException


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.client.exceptions;
20
21 /**
22   * This class encapsulates the errors that may occur during a login
23   * or other types of actions typically performed by a pluggable
24   * authentication module.<br><br>
25   * A pluggable authentication module should set the type of error generated
26   * using the setType method, or the appropriate constructor. If the type
27   * of error does not match one of the existing types and the error should
28   * be returned to the user, the module should use the CUSTOM_ERROR type,
29   * and then also populate the the messageKey attribute with a key that would
30   * be suitable for display to the user.<br><br>
31   * This class can also be used to send the user to a custom error page in the
32   * event of a failure. If this is required, the page type should be set using
33   * the setErrorPageType method, and the appropriate value for the type is set
34   * using setErrorPageValue. The currently supported types are either a URL
35   * or a Struts forward action mapping..
36   */

37 public class AuthenticatorException extends Exception JavaDoc {
38     public static final int INVALID_DATA = -1;
39     public static final int UNKNOWN_USER = -2;
40     public static final int INVALID_PASSWORD = -3;
41     public static final int INACTIVE_ACCOUNT = -4;
42     public static final int SYSTEM_ERROR = -5;
43     public static final int INVALID_AUTHENTICATION_TYPE = -6;
44     public static final int CUSTOM_ERROR = -7;
45
46     public static final int ERRORPAGE_TYPE_UNDEFINED = -1;
47     public static final int ERRORPAGE_TYPE_FORWARD = 1;
48     public static final int ERRORPAGE_TYPE_URL = 2;
49
50     private int type = 0;
51     private String JavaDoc messageKey = "itracker.web.error.login.system";
52     private int errorPageType = ERRORPAGE_TYPE_UNDEFINED;
53     private String JavaDoc errorPageValue = null;
54
55     public AuthenticatorException() {
56     }
57
58     public AuthenticatorException(int type) {
59         this.type = type;
60     }
61
62     public AuthenticatorException(int type, String JavaDoc messageKey) {
63         this(type);
64         this.messageKey = messageKey;
65     }
66
67     public AuthenticatorException(String JavaDoc message, int type) {
68         super(message);
69         this.type = type;
70     }
71
72     public AuthenticatorException(String JavaDoc message, int type, String JavaDoc messageKey) {
73         this(message, type);
74         this.messageKey = messageKey;
75     }
76
77     public int getType() {
78         return type;
79     }
80
81     public void setType(int type) {
82         this.type = type;
83     }
84
85     public String JavaDoc getMessage() {
86         String JavaDoc message = super.getMessage();
87         if(message == null || message.equals("")) {
88             message = "Empty message, type: " + getTypeString();
89         }
90
91         return message;
92     }
93
94     /**
95       * Returns a key that contains a custom error message to display to the user.
96       * @return a resource key that can be used to look up the custom error
97       * message for this exception.
98       */

99     public String JavaDoc getMessageKey() {
100         return messageKey;
101     }
102
103     /**
104       * Sets a key that contains a custom error message to display to the user.
105       * @param messageKey a resource key that can be used to look up the custom error
106       * message for this exception.
107       */

108     public void setMessageKey(String JavaDoc messageKey) {
109         this.messageKey = messageKey;
110     }
111
112     /**
113       * Returns the type of error page that is has been set.
114       * Supported values are urls and Struts forward action mappings.
115       * @returns the type of error page that has been set
116       * @see AuthenticatorException#ERRORPAGE_TYPE_FORWARD
117       * @see AuthenticatorException#ERRORPAGE_TYPE_URL
118       */

119     public int getErrorPageType() {
120         return errorPageType;
121     }
122
123     /**
124       * Sets the type of error page that should be used to display this exception.
125       * Supported values are urls and Struts forward action mappings.
126       * @param value the type of error page that has been set
127       * @see AuthenticatorException#ERRORPAGE_TYPE_FORWARD
128       * @see AuthenticatorException#ERRORPAGE_TYPE_URL
129       */

130     public void setErrorPageType(int value) {
131         errorPageType = value;
132     }
133
134     /**
135       * Returns the error page that should be used to display this exception
136       * Supported values are urls and Struts forward action mappings. The type that
137       * has been set must be identified using the setErrorPageType method.
138       * @returns the error page that has been set
139       * @see AuthenticatorException#setErrorPageType
140       */

141     public String JavaDoc getErrorPageValue() {
142         return errorPageValue;
143     }
144
145     /**
146       * Returns the error page that should be used to display this exception
147       * Supported values are urls and Struts forward action mappings. The type that
148       * has been set must be identified using the setErrorPageType method.
149       * @param value the error page that should be used to display this message
150       * @see AuthenticatorException#setErrorPageType
151       */

152     public void setErrorPageValue(String JavaDoc value) {
153         errorPageValue = value;
154     }
155
156     private String JavaDoc getTypeString() {
157         if(type == INVALID_DATA) {
158             return "Invalid Data";
159         } else if(type == UNKNOWN_USER) {
160             return "Unknown User";
161         } else if(type == INVALID_PASSWORD) {
162             return "Invalid Password";
163         } else if(type == INACTIVE_ACCOUNT) {
164             return "Inactive Account";
165         } else if(type == SYSTEM_ERROR) {
166             return "System Error";
167         } else if(type == INVALID_AUTHENTICATION_TYPE) {
168             return "Invalid Authentication Type";
169         } else if(type == CUSTOM_ERROR ) {
170             return "Custom Error. Check message key.";
171         }
172
173         return "Unknown Type";
174     }
175 }
176
177   
Popular Tags