/*
* Enhydra Java Application Server Project
*
* The contents of this file are subject to the Enhydra Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License on
* the Enhydra web site ( http://www.enhydra.org/ ).
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific terms governing rights and limitations
* under the License.
*
* The Initial Developer of the Enhydra Application Server is Lutris
* Technologies, Inc. The Enhydra Application Server and portions created
* by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
* All Rights Reserved.
*
* Contributor(s):
*
* $Id: PageUnauthorizedException.java,v 1.2 2006-06-15 13:40:47 sinisa Exp $
*/
package com.lutris.appserver.server.httpPresentation;
/**
* Throwing this class will cause a 401 Unauthorized response.
*
* @see com.lutris.http.BasicAuth
* @author Andy John
*/
public class PageUnauthorizedException extends RuntimeException {
/**
* The relm to ask for. This string is used by the browser in the
* prompt for username and password. It should identify to the
* user which system they are logging in to, i.e. which username
* and password to use.
*/
private String relm;
/**
* Default title.
*/
private static final String defaultHtmlTitle =
"Unauthorized access";
/**
* Default text message to display.
*/
private static final String defaultHtmlText =
"<B>Client is not authorized to access this page</B>";
/**
* HTML title to display. (not yet configurable).
*/
private String htmlTitle = defaultHtmlTitle;
/**
* HTML Text message to display.
*/
private String htmlText = defaultHtmlText;
/**
* Create a new unauthorized exception.
*
* @param relm The relm to ask for. This string is used by the browser
* in the prompt for username and password. It should identify to the
* user which system they are logging in to, i.e. which username
* and password to use. For example, if relm is XXX, then Netscape
* Navigator will prompt the user with "Enter the username for
* XXX at <host>:<port>".
*/
public PageUnauthorizedException(String requestedRelm) {
super(defaultHtmlTitle);
relm = requestedRelm;
}
/**
* Create a new unauthorized exception.
*
* @param relm The relm to ask for. This string is used by the browser
* in the prompt for username and password. It should identify to the
* user which system they are logging in to, i.e. which username
* and password to use. For example, if relm is XXX, then Netscape
* Navigator will prompt the user with "Enter the username for
* XXX at <host>:<port>".
* @param htmlDisplayText Text to display on the page. If null,
* a default will be used.
*/
public PageUnauthorizedException(String requestedRelm,
String htmlDisplayText) {
super(defaultHtmlTitle);
relm = requestedRelm;
if (htmlDisplayText != null) {
htmlText = htmlDisplayText;
}
}
/**
* Get the relm that was passed in to the constructor.
* This is used as part of the prompt to the user by the browser.
*
* @return The relm string.
*/
public String getRelm() {
return relm;
}
/**
* Get the title to use for the HTML page.
*
* @return The title string.
*/
public String getHtmlTitle() {
return htmlTitle;
}
/**
* Get the text to display in the client.
*
* @return The HTML text.
*/
public String getHtmlText() {
return htmlText;
}
}
|