1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.vc;
20
21 import nl.toolforge.karma.core.ErrorCode;
22
23 /***
24 * @author D.A. Smedes
25 * @version $Id: AuthenticationException.java,v 1.7 2004/11/02 22:26:44 asmedes Exp $
26 */
27 public class AuthenticationException extends Exception {
28
29 private ErrorCode errorCode = null;
30 private Object[] messageArguments = null;
31
32 /***
33 * This is the prefix that is shown when displaying the error.
34 */
35 public static final String EXCEPTION_PREFIX = "AUT-";
36 /***
37 * When the authenticator configuration is invalid. This is due to functional errors in the content of the
38 * <code><&authenticator></code>-element. Some locations require certain data to be available (username and
39 * password for a <code>pserver</code> location for instance).
40 */
41 public static final ErrorCode INVALID_AUTHENTICATOR_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00001");
42 /***
43 * When the location-type requires authentication configuration to be present.
44 */
45 public static final ErrorCode MISSING_AUTHENTICATOR_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00002");
46 /***
47 * No authenticator entry is configured that matches the location alias (the <code>id</code>-attribute).
48 */
49 public static final ErrorCode DUPLICATE_AUTHENTICATOR_KEY = new ErrorCode(EXCEPTION_PREFIX + "00003");
50 /***
51 * When the <code>authenticators.xml</code> file could not be read properly.
52 */
53 public static final ErrorCode AUTHENTICATOR_LOAD_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00004");
54 /***
55 * No authenticator entry is configured that matches the location alias (the <code>id</code>-attribute).
56 */
57 public static final ErrorCode AUTHENTICATOR_NOT_FOUND = new ErrorCode(EXCEPTION_PREFIX + "00005");
58 /*** Could not write <code>authenticators.xml</code> */
59 public static final ErrorCode AUTHENTICATOR_WRITE_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00006");
60 /*** Username is missing while configuring a new authenticator. */
61 public static final ErrorCode MISSING_USERNAME = new ErrorCode(EXCEPTION_PREFIX + "00007");
62
63 public AuthenticationException(ErrorCode errorCode) {
64 this(errorCode, null);
65 }
66
67 public AuthenticationException(Throwable t, ErrorCode errorCode) {
68 this(t, errorCode, null);
69 }
70
71 public AuthenticationException(ErrorCode errorCode, Object[] messageArguments) {
72 super();
73 this.errorCode = errorCode;
74 this.messageArguments = messageArguments;
75 }
76
77 public AuthenticationException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
78 super(t);
79 this.errorCode = errorCode;
80 this.messageArguments = messageArguments;
81 }
82
83 public String getMessage() {
84 if (messageArguments != null && messageArguments.length > 0) {
85 errorCode.setMessageArguments(messageArguments);
86 }
87 return errorCode.getErrorMessage();
88 }
89
90 /***
91 * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
92 */
93 public final ErrorCode getErrorCode() {
94 return errorCode;
95 }
96
97 /***
98 * Retrieves the message arguments for this exception.
99 */
100 public final Object[] getMessageArguments() {
101 return messageArguments;
102 }
103 }