01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.responders;
04:
05: import fitnesse.*;
06: import fitnesse.html.*;
07: import fitnesse.http.*;
08:
09: public class UnauthorizedResponder implements Responder {
10: public Response makeResponse(FitNesseContext context,
11: Request request) throws Exception {
12: SimpleResponse response = new SimpleResponse(401);
13: response.addHeader("WWW-Authenticate",
14: "Basic realm=\"FitNesse\"");
15:
16: HtmlPage page = context.htmlPageFactory.newPage();
17: HtmlUtil.addTitles(page, "401 Unauthorized");
18: page.main.use(makeContent(request));
19: response.setContent(page.html());
20:
21: return response;
22: }
23:
24: private HtmlTag makeContent(Request request) throws Exception {
25: TagGroup group = new TagGroup();
26: group.add(makeSimpleTag("h1", "Unauthorized"));
27: group.add("<p>The requested resource: ");
28: group.add(makeSimpleTag("b", request.getResource()));
29: group.add(" is restricted.");
30: group
31: .add("<p> Either your credientials were not supplied or they didn't match the criteria to access this resource.");
32: group.add(HtmlUtil.HR);
33: group.add(makeSimpleTag("address", "FitNesse"));
34: return group;
35: }
36:
37: private String makeSimpleTag(String tagName, String content)
38: throws Exception {
39: HtmlTag tag = new HtmlTag(tagName);
40: tag.add(content);
41: return tag.html();
42: }
43: }
|