KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > security > implementation > cloudcontext > builders > PeopleContexts


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.security.implementation.cloudcontext.builders;
11
12 import org.mmbase.security.implementation.cloudcontext.*;
13 import org.mmbase.module.core.*;
14 import org.mmbase.core.CoreField;
15
16 /**
17  * Simple extension of Contexts. It overrides the concept of an 'own' node wich is on default only
18  * the mmbaseusers object. This adds also the people nodes where the 'account; field is the current
19  * account (either as a String field containing the user's identifier), or as a NODE field refering
20  * to the mmbaseusers node.
21  *
22  * @author Michiel Meeuwissen
23  * @version $Id: PeopleContexts.java,v 1.6 2005/07/14 11:48:01 michiel Exp $
24  */

25 public class PeopleContexts extends Contexts {
26
27
28
29     protected String JavaDoc peopleBuilder = "people";
30     public boolean init() {
31         String JavaDoc s = (String JavaDoc) getInitParameters().get("peoplebuilder");
32         if (s != null) {
33             peopleBuilder = s;
34         }
35         return super.init();
36     }
37
38     // javadoc inherited
39
protected boolean isOwnNode(User user, MMObjectNode node) {
40         if (super.isOwnNode(user, node)) return true;
41         if (node.getBuilder().getTableName().equals(peopleBuilder)) {
42             CoreField field = node.getBuilder().getField("account");
43             if (field != null) {
44                 switch (field.getType()) {
45                 case CoreField.TYPE_STRING:
46                     if (node.getStringValue("account").equals(user.getIdentifier())) {
47                         return true;
48                     }
49                     break;
50                 case CoreField.TYPE_NODE:
51                     if (node.getIntValue("account") == user.getNode().getNumber()) {
52                         return true;
53                     }
54                     break;
55                 default:
56                     break;
57                 }
58             }
59         }
60         return false;
61     }
62
63
64 }
65
Popular Tags