KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > authorization > AccessTree


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.core.model.authorization;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Iterator JavaDoc;
19 /**
20  * A class that builds and maintains an accesstree. It should be used to check if a
21  * client certificate has access rights to a resource or not. isAthorized metod is the one to use.
22  *
23  * @author Philip Vendil
24  * @version $Id: AccessTree.java,v 1.1 2006/01/17 20:30:56 anatom Exp $
25  */

26 public class AccessTree implements Serializable JavaDoc {
27     /** Creates a new instance of AccessTree */
28     public AccessTree() {}
29
30     // Public methods
31
/** Builds an accesstree out of the given admingroup data. */
32     public void buildTree(Collection JavaDoc admingroups) {
33         rootnode = new AccessTreeNode("/");
34                   
35         Iterator JavaDoc iter = admingroups.iterator();
36         // Add all admingroups accessrules.
37
while(iter.hasNext()){
38           AdminGroup admingroup = (AdminGroup) iter.next();
39           Iterator JavaDoc iter2 = admingroup.getAccessRules().iterator();
40           while(iter2.hasNext()){
41             AccessRule accessrule = (AccessRule) iter2.next();
42             rootnode.addAccessRule(accessrule.getAccessRule(),accessrule,admingroup); // Without heading '/'
43
}
44         }
45     }
46
47     /** A method to check if someone is athorized to view the given resource */
48     public boolean isAuthorized(AdminInformation admininformation, String JavaDoc resource){
49           String JavaDoc checkresource = resource;
50         // Must begin with '/'.
51
if((checkresource.toCharArray())[0] != '/')
52           checkresource = "/" + checkresource;
53
54         // Check if user is athorized in the tree.
55
boolean retval = rootnode.isAuthorized(admininformation, checkresource);
56         return retval;
57     }
58
59
60
61     // Private fields
62
private AccessTreeNode rootnode = null;
63
64 }
65
Popular Tags