KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > httpPresentation > PageUnauthorizedException


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: PageUnauthorizedException.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.appserver.server.httpPresentation;
30
31
32 /**
33  * Throwing this class will cause a 401 Unauthorized response.
34  *
35  * @see com.lutris.http.BasicAuth
36  * @author Andy John
37  */

38 public class PageUnauthorizedException extends RuntimeException JavaDoc {
39     /**
40      * The relm to ask for. This string is used by the browser in the
41      * prompt for username and password. It should identify to the
42      * user which system they are logging in to, i.e. which username
43      * and password to use.
44      */

45     private String JavaDoc relm;
46
47     /**
48      * Default title.
49      */

50     private static final String JavaDoc defaultHtmlTitle =
51         "Unauthorized access";
52
53     /**
54      * Default text message to display.
55      */

56     private static final String JavaDoc defaultHtmlText =
57         "<B>Client is not authorized to access this page</B>";
58
59     /**
60      * HTML title to display. (not yet configurable).
61      */

62     private String JavaDoc htmlTitle = defaultHtmlTitle;
63
64     /**
65      * HTML Text message to display.
66      */

67     private String JavaDoc htmlText = defaultHtmlText;
68
69     /**
70      * Create a new unauthorized exception.
71      *
72      * @param relm The relm to ask for. This string is used by the browser
73      * in the prompt for username and password. It should identify to the
74      * user which system they are logging in to, i.e. which username
75      * and password to use. For example, if relm is XXX, then Netscape
76      * Navigator will prompt the user with "Enter the username for
77      * XXX at <host>:<port>".
78      */

79     public PageUnauthorizedException(String JavaDoc requestedRelm) {
80         super(defaultHtmlTitle);
81         relm = requestedRelm;
82     }
83  
84  
85     /**
86      * Create a new unauthorized exception.
87      *
88      * @param relm The relm to ask for. This string is used by the browser
89      * in the prompt for username and password. It should identify to the
90      * user which system they are logging in to, i.e. which username
91      * and password to use. For example, if relm is XXX, then Netscape
92      * Navigator will prompt the user with "Enter the username for
93      * XXX at <host>:<port>".
94      * @param htmlDisplayText Text to display on the page. If null,
95      * a default will be used.
96      */

97     public PageUnauthorizedException(String JavaDoc requestedRelm,
98                                      String JavaDoc htmlDisplayText) {
99         super(defaultHtmlTitle);
100         relm = requestedRelm;
101         if (htmlDisplayText != null) {
102             htmlText = htmlDisplayText;
103         }
104     }
105     
106  
107  
108    /**
109      * Get the relm that was passed in to the constructor.
110      * This is used as part of the prompt to the user by the browser.
111      *
112      * @return The relm string.
113      */

114     public String JavaDoc getRelm() {
115         return relm;
116     }
117
118    /**
119      * Get the title to use for the HTML page.
120      *
121      * @return The title string.
122      */

123     public String JavaDoc getHtmlTitle() {
124         return htmlTitle;
125     }
126
127    /**
128      * Get the text to display in the client.
129      *
130      * @return The HTML text.
131      */

132     public String JavaDoc getHtmlText() {
133         return htmlText;
134     }
135
136 }
137
Popular Tags