KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > configuration > AccessRulesView


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.ui.web.admin.configuration;
15
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Collections JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 import org.ejbca.core.model.authorization.AccessRule;
22 import org.ejbca.core.model.authorization.AvailableAccessRules;
23
24
25 /**
26  * A class used as a help class for displaying access rules
27  *
28  * @author TomSelleck
29  */

30 public class AccessRulesView implements java.io.Serializable JavaDoc {
31
32     
33     /**
34      * Creates an AccessRulesView and sorts the accessrules into their approriate
35      * sets.
36      */

37     public AccessRulesView(Collection JavaDoc accessrules){
38       this.rolebasedaccessrules = new ArrayList JavaDoc();
39       this.regularaccessrules = new ArrayList JavaDoc();
40       this.endentityprofileaccessrules = new ArrayList JavaDoc();
41       this.caaccessrules = new ArrayList JavaDoc();
42         
43         
44       Iterator JavaDoc iter = accessrules.iterator();
45       while(iter.hasNext()){
46         Object JavaDoc obj = iter.next();
47         String JavaDoc accessrulestring = "";
48         AccessRule accessrule = null;
49         if( obj instanceof AccessRule ){
50           accessrulestring = ((AccessRule) obj).getAccessRule();
51           accessrule = (AccessRule) obj;
52         }else{
53           accessrulestring = (String JavaDoc) obj;
54           accessrule = new AccessRule(accessrulestring, 0, false);
55         }
56         boolean regular = true;
57         
58         // Check if rule is a role based one
59
for(int i=0; i< AvailableAccessRules.ROLEACCESSRULES.length; i++){
60            if(accessrulestring.equals(AvailableAccessRules.ROLEACCESSRULES[i])){
61              this.rolebasedaccessrules.add(accessrule);
62              regular=false;
63            }
64         }
65         
66         // Check if rule is end entity profile access rule
67
if(accessrulestring.startsWith("/endentityprofilesrules")){
68           this.endentityprofileaccessrules.add(accessrule);
69           regular=false;
70         }
71         
72         // Check if rule is CA access rule
73
if(accessrulestring.startsWith(AvailableAccessRules.CAPREFIX) || accessrulestring.equals(AvailableAccessRules.CABASE)){
74           this.caaccessrules.add(accessrule);
75           regular=false;
76         }
77         
78         // Otherwise it's a regular accessrule.
79
if(regular)
80           this.regularaccessrules.add(accessrule);
81         
82       }
83       
84       Collections.sort(this.rolebasedaccessrules);
85       Collections.sort(this.regularaccessrules);
86       Collections.sort(this.endentityprofileaccessrules);
87       Collections.sort(this.caaccessrules);
88       
89     }
90     
91    
92     /**
93      * Method that returns all role based access rules, sorted.
94      */

95     public Collection JavaDoc getRoleBasedAccessRules(){
96       return this.rolebasedaccessrules;
97     }
98
99     /**
100      * Method that returns all regular access rules, sorted.
101      */

102     public Collection JavaDoc getRegularAccessRules(){
103       return this.regularaccessrules;
104     }
105     
106     /**
107      * Method that returns all end entity profile access rules, sorted.
108      */

109     public Collection JavaDoc getEndEntityProfileAccessRules(){
110       return this.endentityprofileaccessrules;
111     }
112
113     /**
114      * Method that returns all CA access rules, sorted.
115      */

116     public Collection JavaDoc getCAAccessRules(){
117       return this.caaccessrules;
118     }
119     
120     // Private constants.
121

122     // Private methods.
123
private ArrayList JavaDoc rolebasedaccessrules;
124     private ArrayList JavaDoc regularaccessrules;
125     private ArrayList JavaDoc endentityprofileaccessrules;
126     private ArrayList JavaDoc caaccessrules;
127 }
128
Popular Tags