001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.model.authorization;
013:
014: import java.util.ArrayList;
015: import java.util.Collections;
016: import java.util.Collection;
017: import java.util.Iterator;
018: import java.io.Serializable;
019:
020: /**
021: * A class that represents a group of users and their access rules.
022: *
023: * @version $Id: AdminGroup.java,v 1.1 2006/01/17 20:30:56 anatom Exp $
024: */
025: public class AdminGroup implements Serializable, Comparable {
026:
027: /** Creates a new instance of AdminGroup */
028: public AdminGroup(String admingroupname, int caid) {
029: this .admingroupname = admingroupname;
030: this .caid = caid;
031: accessrules = new ArrayList();
032: adminentities = new ArrayList();
033: }
034:
035: public AdminGroup(int admingroupid, String admingroupname,
036: int caid, ArrayList accessrules, ArrayList adminentities) {
037: this .admingroupid = admingroupid;
038: this .admingroupname = admingroupname;
039: this .caid = caid;
040: this .accessrules = accessrules;
041: this .adminentities = adminentities;
042: }
043:
044: // Public methods
045: /** Returns the number of accessrules applied to this admingroup */
046: public int getNumberOfAccessRules() {
047: return accessrules.size();
048: }
049:
050: /** Returns a ArrayList of AccessRule containing all the admingroup's accessrules.*/
051: public Collection getAccessRules() {
052: return accessrules;
053: }
054:
055: /** Returns the number of admin entities in this admingroup */
056: public int getNumberAdminEntities() {
057: return adminentities.size();
058: }
059:
060: /** Returns an ArrayList of AdminEntity containing all the admingroup's admin entities.*/
061: public Collection getAdminEntities() {
062: return adminentities;
063: }
064:
065: public int getCAId() {
066: return this .caid;
067: }
068:
069: public int getAdminGroupId() {
070: return this .admingroupid;
071: }
072:
073: public String getAdminGroupName() {
074: return this .admingroupname;
075: }
076:
077: /** Method that given an array of available access rules returns which isn't already
078: * in use by the rule set. */
079: public Collection nonUsedAccessRules(Collection availableaccessrules) {
080: ArrayList nonusedaccessrules = new ArrayList();
081: int result;
082: Collections.sort(accessrules);
083: if (availableaccessrules != null) {
084: Iterator iter = availableaccessrules.iterator();
085: while (iter.hasNext()) {
086: String availableaccessrule = (String) iter.next();
087: result = java.util.Collections.binarySearch(
088: accessrules, new AccessRule(
089: availableaccessrule, 0, false));
090: if (result < 0) {
091: // Access rule isn't in use.
092: nonusedaccessrules.add(availableaccessrule);
093: }
094: }
095: }
096: return nonusedaccessrules;
097: }
098:
099: public int compareTo(Object o) {
100: if (caid != ((AdminGroup) o).getCAId())
101: return caid - ((AdminGroup) o).getCAId();
102: return admingroupname.compareTo(((AdminGroup) o)
103: .getAdminGroupName());
104: }
105:
106: // Private methods
107:
108: // Private fields
109: private int admingroupid;
110: private String admingroupname;
111: private int caid;
112: private ArrayList accessrules;
113: private ArrayList adminentities;
114: }
|