001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: PageUnauthorizedException.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
022: */
023:
024: package com.lutris.appserver.server.httpPresentation;
025:
026: /**
027: * Throwing this class will cause a 401 Unauthorized response.
028: *
029: * @see com.lutris.http.BasicAuth
030: * @author Andy John
031: */
032: public class PageUnauthorizedException extends RuntimeException {
033: /**
034: * The relm to ask for. This string is used by the browser in the
035: * prompt for username and password. It should identify to the
036: * user which system they are logging in to, i.e. which username
037: * and password to use.
038: */
039: private String relm;
040:
041: /**
042: * Default title.
043: */
044: private static final String defaultHtmlTitle = "Unauthorized access";
045:
046: /**
047: * Default text message to display.
048: */
049: private static final String defaultHtmlText = "<B>Client is not authorized to access this page</B>";
050:
051: /**
052: * HTML title to display. (not yet configurable).
053: */
054: private String htmlTitle = defaultHtmlTitle;
055:
056: /**
057: * HTML Text message to display.
058: */
059: private String htmlText = defaultHtmlText;
060:
061: /**
062: * Create a new unauthorized exception.
063: *
064: * @param relm The relm to ask for. This string is used by the browser
065: * in the prompt for username and password. It should identify to the
066: * user which system they are logging in to, i.e. which username
067: * and password to use. For example, if relm is XXX, then Netscape
068: * Navigator will prompt the user with "Enter the username for
069: * XXX at <host>:<port>".
070: */
071: public PageUnauthorizedException(String requestedRelm) {
072: super (defaultHtmlTitle);
073: relm = requestedRelm;
074: }
075:
076: /**
077: * Create a new unauthorized exception.
078: *
079: * @param relm The relm to ask for. This string is used by the browser
080: * in the prompt for username and password. It should identify to the
081: * user which system they are logging in to, i.e. which username
082: * and password to use. For example, if relm is XXX, then Netscape
083: * Navigator will prompt the user with "Enter the username for
084: * XXX at <host>:<port>".
085: * @param htmlDisplayText Text to display on the page. If null,
086: * a default will be used.
087: */
088: public PageUnauthorizedException(String requestedRelm,
089: String htmlDisplayText) {
090: super (defaultHtmlTitle);
091: relm = requestedRelm;
092: if (htmlDisplayText != null) {
093: htmlText = htmlDisplayText;
094: }
095: }
096:
097: /**
098: * Get the relm that was passed in to the constructor.
099: * This is used as part of the prompt to the user by the browser.
100: *
101: * @return The relm string.
102: */
103: public String getRelm() {
104: return relm;
105: }
106:
107: /**
108: * Get the title to use for the HTML page.
109: *
110: * @return The title string.
111: */
112: public String getHtmlTitle() {
113: return htmlTitle;
114: }
115:
116: /**
117: * Get the text to display in the client.
118: *
119: * @return The HTML text.
120: */
121: public String getHtmlText() {
122: return htmlText;
123: }
124:
125: }
|