01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.search;
19:
20: import org.apache.lucene.document.Document;
21:
22: import de.finix.contelligent.CallData;
23: import de.finix.contelligent.Component;
24: import de.finix.contelligent.ComponentCreationException;
25: import de.finix.contelligent.ComponentManager;
26: import de.finix.contelligent.ComponentNotFoundException;
27: import de.finix.contelligent.ComponentPath;
28: import de.finix.contelligent.core.security.ComponentPermission;
29: import de.finix.contelligent.core.security.User;
30: import de.finix.contelligent.util.ThreadedMem;
31:
32: public class AccessRightResultCollector implements
33: SearchResultCollector {
34:
35: private ComponentManager cm;
36:
37: private User currentUser;
38:
39: private CallData callData;
40:
41: public AccessRightResultCollector() {
42: callData = ThreadedMem.getCallData();
43: cm = callData.getActualManager();
44: currentUser = callData.getUser();
45: }
46:
47: /**
48: *
49: * @return true if the item should be included
50: */
51: public boolean collect(Document document, float score) {
52: try {
53: Component component = cm.getComponent(new ComponentPath(
54: document.get("path")), callData);
55: return cm.callerHasPermission(currentUser, callData,
56: component, ComponentPermission.READ);
57: } catch (ComponentNotFoundException e) {
58: return false;
59: } catch (ComponentCreationException e) {
60: return false;
61: }
62: }
63: }
|