KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > cainterface > CAAuthorization


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.cainterface;
15
16 import java.io.Serializable JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Collection JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.TreeMap JavaDoc;
22
23 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal;
24 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal;
25 import org.ejbca.core.ejb.ca.store.CertificateDataBean;
26 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal;
27 import org.ejbca.core.model.SecConst;
28 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
29 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfile;
30 import org.ejbca.core.model.log.Admin;
31
32 /**
33  * A class that looks up the which CA:s and certificate profiles the administrator is authorized to view.
34  *
35  * @version $Id: CAAuthorization.java,v 1.1 2006/01/17 20:28:08 anatom Exp $
36  */

37 public class CAAuthorization implements Serializable JavaDoc {
38     
39   
40     
41     /** Creates a new instance of CAAuthorization. */
42     public CAAuthorization(Admin admin,
43                            ICAAdminSessionLocal caadminsession,
44                            ICertificateStoreSessionLocal certificatestoresession,
45                            IAuthorizationSessionLocal authorizationsession) {
46       this.admin=admin;
47       this.caadminsession=caadminsession;
48       this.certificatestoresession=certificatestoresession;
49       this.authorizationsession=authorizationsession;
50     }
51
52     
53     
54     /**
55      * Methos returning a Collection of authorizaed CA ids (Integer).
56      *
57      */

58     public Collection JavaDoc getAuthorizedCAIds() {
59       if(authcas ==null || authcas.size() == 0){
60         authcas = this.authorizationsession.getAuthorizedCAIds(admin);
61       }
62       
63       return authcas;
64     }
65     
66     
67     
68     public TreeMap JavaDoc getAuthorizedEndEntityCertificateProfileNames(boolean usehardtokenprofiles){
69       if(profilenamesendentity==null){
70         profilenamesendentity = new TreeMap JavaDoc();
71         Iterator JavaDoc iter = null;
72         if(usehardtokenprofiles)
73           iter = certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_HARDTOKEN).iterator();
74         else
75           iter = certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_ENDENTITY).iterator();
76         HashMap JavaDoc idtonamemap = certificatestoresession.getCertificateProfileIdToNameMap(admin);
77         while(iter.hasNext()){
78           Integer JavaDoc id = (Integer JavaDoc) iter.next();
79           profilenamesendentity.put(idtonamemap.get(id),id);
80         }
81       }
82       return profilenamesendentity;
83     }
84             
85     public TreeMap JavaDoc getAuthorizedSubCACertificateProfileNames(){
86       if(profilenamessubca==null){
87         profilenamessubca = new TreeMap JavaDoc();
88         Iterator JavaDoc iter = certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_SUBCA).iterator();
89         HashMap JavaDoc idtonamemap = certificatestoresession.getCertificateProfileIdToNameMap(admin);
90         while(iter.hasNext()){
91           Integer JavaDoc id = (Integer JavaDoc) iter.next();
92           profilenamessubca.put(idtonamemap.get(id),id);
93         }
94       }
95       return profilenamessubca;
96     }
97     
98     
99     public TreeMap JavaDoc getAuthorizedRootCACertificateProfileNames(){
100       if(profilenamesrootca==null){
101         profilenamesrootca = new TreeMap JavaDoc();
102         Iterator JavaDoc iter = certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_ROOTCA).iterator();
103         HashMap JavaDoc idtonamemap = certificatestoresession.getCertificateProfileIdToNameMap(admin);
104         while(iter.hasNext()){
105           Integer JavaDoc id = (Integer JavaDoc) iter.next();
106           profilenamesrootca.put(idtonamemap.get(id),id);
107         }
108       }
109       return profilenamesrootca;
110     }
111     
112     public TreeMap JavaDoc getEditCertificateProfileNames(boolean includefixedhardtokenprofiles){
113       if(allprofilenames==null){
114         // check if administrator
115
boolean superadministrator = false;
116         try{
117           superadministrator = authorizationsession.isAuthorizedNoLog(admin, "/super_administrator");
118         }catch(AuthorizationDeniedException ade){}
119         
120         allprofilenames = new TreeMap JavaDoc();
121         Iterator JavaDoc iter= null;
122         if(includefixedhardtokenprofiles){
123           iter = certificatestoresession.getAuthorizedCertificateProfileIds(admin, 0).iterator();
124         }else{
125           ArrayList JavaDoc certprofiles = new ArrayList JavaDoc();
126           certprofiles.addAll(certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_ENDENTITY));
127           certprofiles.addAll(certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_ROOTCA));
128           certprofiles.addAll(certificatestoresession.getAuthorizedCertificateProfileIds(admin, CertificateDataBean.CERTTYPE_SUBCA));
129           iter = certprofiles.iterator();
130         }
131         HashMap JavaDoc idtonamemap = certificatestoresession.getCertificateProfileIdToNameMap(admin);
132         while(iter.hasNext()){
133         
134           Integer JavaDoc id = (Integer JavaDoc) iter.next();
135           CertificateProfile certprofile = certificatestoresession.getCertificateProfile(admin,id.intValue());
136  
137           // If not superadministrator, then should only end entity profiles be added.
138
if(superadministrator || certprofile.getType() == CertificateProfile.TYPE_ENDENTITY){
139             // if default profiles, add fixed to name.
140
if(id.intValue() <= SecConst.FIXED_CERTIFICATEPROFILE_BOUNDRY ||
141                (!superadministrator && certprofile.isApplicableToAnyCA()))
142               allprofilenames.put(idtonamemap.get(id) + " (FIXED)",id);
143             else
144               allprofilenames.put(idtonamemap.get(id),id);
145           }
146         }
147       }
148       return allprofilenames;
149     }
150         
151     
152     
153     public TreeMap JavaDoc getCANames(){
154       if(canames==null){
155         canames = new TreeMap JavaDoc();
156         HashMap JavaDoc idtonamemap = this.caadminsession.getCAIdToNameMap(admin);
157         Iterator JavaDoc iter = getAuthorizedCAIds().iterator();
158         while(iter.hasNext()){
159           Integer JavaDoc id = (Integer JavaDoc) iter.next();
160           canames.put(idtonamemap.get(id),id);
161         }
162       }
163       return canames;
164     }
165     
166     public TreeMap JavaDoc getAllCANames(){
167         allcanames = new TreeMap JavaDoc();
168         HashMap JavaDoc idtonamemap = this.caadminsession.getCAIdToNameMap(admin);
169         Iterator JavaDoc iter = idtonamemap.keySet().iterator();
170         while(iter.hasNext()){
171           Integer JavaDoc id = (Integer JavaDoc) iter.next();
172           allcanames.put(idtonamemap.get(id),id);
173         }
174        
175       return allcanames;
176     }
177     public void clear(){
178       authcas=null;
179       profilenamesendentity = null;
180       profilenamessubca = null;
181       profilenamesrootca = null;
182       allprofilenames = null;
183       canames=null;
184       allcanames=null;
185     }
186     
187     // Private fields.
188
private Collection JavaDoc authcas = null;
189     private TreeMap JavaDoc profilenamesendentity = null;
190     private TreeMap JavaDoc profilenamessubca = null;
191     private TreeMap JavaDoc profilenamesrootca = null;
192     private TreeMap JavaDoc canames = null;
193     private TreeMap JavaDoc allcanames = null;
194     private TreeMap JavaDoc allprofilenames = null;
195     private Admin admin;
196     private ICAAdminSessionLocal caadminsession;
197     private IAuthorizationSessionLocal authorizationsession;
198     private ICertificateStoreSessionLocal certificatestoresession;
199
200 }
201
202
203
Popular Tags