KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
17 import java.util.Collections JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.io.Serializable JavaDoc;
21
22 /**
23  * A class that represents a group of users and their access rules.
24  *
25  * @version $Id: AdminGroup.java,v 1.1 2006/01/17 20:30:56 anatom Exp $
26  */

27 public class AdminGroup implements Serializable JavaDoc, Comparable JavaDoc {
28                                
29     
30     /** Creates a new instance of AdminGroup */
31     public AdminGroup(String JavaDoc admingroupname, int caid) {
32       this.admingroupname=admingroupname;
33       this.caid=caid;
34       accessrules = new ArrayList JavaDoc();
35       adminentities = new ArrayList JavaDoc();
36     }
37
38     public AdminGroup(int admingroupid, String JavaDoc admingroupname, int caid, ArrayList JavaDoc accessrules, ArrayList JavaDoc adminentities){
39       this.admingroupid=admingroupid;
40       this.admingroupname=admingroupname;
41       this.caid=caid;
42       this.accessrules=accessrules;
43       this.adminentities=adminentities;
44     }
45
46     // Public methods
47
/** Returns the number of accessrules applied to this admingroup */
48     public int getNumberOfAccessRules() {
49       return accessrules.size();
50     }
51
52     /** Returns a ArrayList of AccessRule containing all the admingroup's accessrules.*/
53     public Collection JavaDoc getAccessRules() {
54       return accessrules;
55     }
56
57     /** Returns the number of admin entities in this admingroup */
58     public int getNumberAdminEntities() {
59       return adminentities.size();
60     }
61
62     /** Returns an ArrayList of AdminEntity containing all the admingroup's admin entities.*/
63     public Collection JavaDoc getAdminEntities() {
64       return adminentities;
65     }
66     
67     public int getCAId(){
68       return this.caid;
69     }
70     
71     public int getAdminGroupId(){
72       return this.admingroupid;
73     }
74     
75     public String JavaDoc getAdminGroupName(){
76       return this.admingroupname;
77     }
78     
79     /** Method that given an array of available access rules returns which isn't already
80      * in use by the rule set. */

81     public Collection JavaDoc nonUsedAccessRules(Collection JavaDoc availableaccessrules){
82       ArrayList JavaDoc nonusedaccessrules = new ArrayList JavaDoc();
83       int result;
84       Collections.sort(accessrules);
85       if(availableaccessrules != null){
86         Iterator JavaDoc iter = availableaccessrules.iterator();
87         while(iter.hasNext()){
88           String JavaDoc availableaccessrule = (String JavaDoc) iter.next();
89           result=java.util.Collections.binarySearch(accessrules,new AccessRule(availableaccessrule, 0, false));
90           if(result < 0){
91             // Access rule isn't in use.
92
nonusedaccessrules.add(availableaccessrule);
93           }
94         }
95       }
96       return nonusedaccessrules;
97     }
98     
99  
100     public int compareTo(Object JavaDoc o) {
101         if(caid != ((AdminGroup) o).getCAId())
102             return caid - ((AdminGroup) o).getCAId();
103         return admingroupname.compareTo(((AdminGroup)o).getAdminGroupName());
104     }
105     
106     // Private methods
107

108     // Private fields
109
private int admingroupid;
110     private String JavaDoc admingroupname;
111     private int caid;
112     private ArrayList JavaDoc accessrules;
113     private ArrayList JavaDoc adminentities;
114  }
115
Popular Tags