Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
36   186   25   2.25
16   88   0.69   16
16     1.56  
1    
 
 
  AuthenticatorException       Line # 37 36 25 0% 0.0
 
No Tests
 
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 org.itracker.services.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 RuntimeException {
38    /**
39    *
40    */
41    private static final long serialVersionUID = -7799413588815903874L;
42    public static final int INVALID_DATA = -1;
43    public static final int UNKNOWN_USER = -2;
44    public static final int INVALID_PASSWORD = -3;
45    public static final int INACTIVE_ACCOUNT = -4;
46    public static final int SYSTEM_ERROR = -5;
47    public static final int INVALID_AUTHENTICATION_TYPE = -6;
48    public static final int CUSTOM_ERROR = -7;
49   
50    public static final int ERRORPAGE_TYPE_UNDEFINED = -1;
51    public static final int ERRORPAGE_TYPE_FORWARD = 1;
52    public static final int ERRORPAGE_TYPE_URL = 2;
53   
54    private int type = 0;
55    private String messageKey = "itracker.web.error.login.system";
56    private int errorPageType = ERRORPAGE_TYPE_UNDEFINED;
57    private String errorPageValue = null;
58   
 
59  0 toggle public AuthenticatorException() {
60    }
61   
 
62  0 toggle public AuthenticatorException(int type) {
63  0 this.type = type;
64    }
65   
 
66  0 toggle public AuthenticatorException(int type, String messageKey) {
67  0 this(type);
68  0 this.messageKey = messageKey;
69    }
70   
 
71  0 toggle public AuthenticatorException(String message, int type) {
72  0 super(message);
73  0 this.type = type;
74    }
75   
 
76  0 toggle public AuthenticatorException(String message, int type, Throwable cause) {
77  0 super(message, cause);
78  0 this.type = type;
79    }
80   
 
81  0 toggle public AuthenticatorException(String message, int type, String messageKey) {
82  0 this(message, type);
83  0 this.messageKey = messageKey;
84    }
85   
 
86  0 toggle public int getType() {
87  0 return type;
88    }
89   
 
90  0 toggle public void setType(int type) {
91  0 this.type = type;
92    }
93   
 
94  0 toggle public String getMessage() {
95  0 String message = super.getMessage();
96  0 if(message == null || message.equals("")) {
97  0 message = "Empty message, type: " + getTypeString();
98    }
99   
100  0 return message;
101    }
102   
103    /**
104    * Returns a key that contains a custom error message to display to the user.
105    * @return a resource key that can be used to look up the custom error
106    * message for this exception.
107    */
 
108  0 toggle public String getMessageKey() {
109  0 return messageKey;
110    }
111   
112    /**
113    * Sets a key that contains a custom error message to display to the user.
114    * @param messageKey a resource key that can be used to look up the custom error
115    * message for this exception.
116    */
 
117  0 toggle public void setMessageKey(String messageKey) {
118  0 this.messageKey = messageKey;
119    }
120   
121    /**
122    * Returns the type of error page that is has been set.
123    * Supported values are urls and Struts forward action mappings.
124    * @returns the type of error page that has been set
125    * @see AuthenticatorException#ERRORPAGE_TYPE_FORWARD
126    * @see AuthenticatorException#ERRORPAGE_TYPE_URL
127    */
 
128  0 toggle public int getErrorPageType() {
129  0 return errorPageType;
130    }
131   
132    /**
133    * Sets the type of error page that should be used to display this exception.
134    * Supported values are urls and Struts forward action mappings.
135    * @param value the type of error page that has been set
136    * @see AuthenticatorException#ERRORPAGE_TYPE_FORWARD
137    * @see AuthenticatorException#ERRORPAGE_TYPE_URL
138    */
 
139  0 toggle public void setErrorPageType(int value) {
140  0 errorPageType = value;
141    }
142   
143    /**
144    * Returns the error page that should be used to display this exception
145    * Supported values are urls and Struts forward action mappings. The type that
146    * has been set must be identified using the setErrorPageType method.
147    * @returns the error page that has been set
148    * @see AuthenticatorException#setErrorPageType
149    */
 
150  0 toggle public String getErrorPageValue() {
151  0 return errorPageValue;
152    }
153   
154    /**
155    * Returns the error page that should be used to display this exception
156    * Supported values are urls and Struts forward action mappings. The type that
157    * has been set must be identified using the setErrorPageType method.
158    * @param value the error page that should be used to display this message
159    * @see AuthenticatorException#setErrorPageType
160    */
 
161  0 toggle public void setErrorPageValue(String value) {
162  0 errorPageValue = value;
163    }
164   
 
165  0 toggle private String getTypeString() {
166  0 if(type == INVALID_DATA) {
167  0 return "Invalid Data";
168  0 } else if(type == UNKNOWN_USER) {
169  0 return "Unknown User";
170  0 } else if(type == INVALID_PASSWORD) {
171  0 return "Invalid Password";
172  0 } else if(type == INACTIVE_ACCOUNT) {
173  0 return "Inactive Account";
174  0 } else if(type == SYSTEM_ERROR) {
175  0 return "System Error";
176  0 } else if(type == INVALID_AUTHENTICATION_TYPE) {
177  0 return "Invalid Authentication Type";
178  0 } else if(type == CUSTOM_ERROR ) {
179  0 return "Custom Error. Check message key.";
180    }
181   
182  0 return "Unknown Type";
183    }
184    }
185   
186