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.authentication;
04:
05: import fitnesse.FitNesseContext;
06: import fitnesse.wiki.*;
07: import fitnesse.http.Request;
08: import java.util.*;
09:
10: public abstract class SecurePageOperation implements SecureOperation {
11: protected abstract String getSecurityMode();
12:
13: public boolean shouldAuthenticate(FitNesseContext context,
14: Request request) throws Exception {
15: WikiPagePath path = PathParser.parse(request.getResource());
16: PageCrawler crawler = context.root.getPageCrawler();
17: crawler.setDeadEndStrategy(new VirtualMockingPageCrawler());
18: WikiPage page = crawler.getPage(context.root, path);
19: if (page == null)
20: return false;
21:
22: List ancestors = WikiPageUtil.getAncestorsStartingWith(page);
23: for (Iterator iterator = ancestors.iterator(); iterator
24: .hasNext();) {
25: WikiPage ancestor = (WikiPage) iterator.next();
26: if (hasSecurityModeAttribute(ancestor))
27: return true;
28: }
29: return false;
30: }
31:
32: private boolean hasSecurityModeAttribute(WikiPage ancestor)
33: throws Exception {
34: PageData data = ancestor.getData();
35: boolean hasSecurityMode = data.hasAttribute(getSecurityMode());
36: return hasSecurityMode;
37: }
38: }
|