KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > hardtokeninterface > HardTokenAuthorization


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.hardtokeninterface;
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.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.TreeMap JavaDoc;
23
24 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal;
25 import org.ejbca.core.ejb.hardtoken.IHardTokenSessionLocal;
26 import org.ejbca.core.model.authorization.AdminGroup;
27 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
28 import org.ejbca.core.model.hardtoken.HardTokenIssuerData;
29 import org.ejbca.core.model.log.Admin;
30
31 /**
32  * A class that looks up the which Hard Token Issuers the administrator is authorized to view and edit
33  *
34  * @version $Id: HardTokenAuthorization.java,v 1.1 2006/01/17 20:26:30 anatom Exp $
35  */

36 public class HardTokenAuthorization implements Serializable JavaDoc {
37     
38   
39     
40     /** Creates a new instance of CAAuthorization. */
41     public HardTokenAuthorization(Admin admin,
42                            IHardTokenSessionLocal hardtokensession,
43                            IAuthorizationSessionLocal authorizationsession) {
44       this.admin=admin;
45       this.hardtokensession=hardtokensession;
46       this.authorizationsession=authorizationsession;
47     }
48
49     /**
50      * Method returning a TreeMap containing Hard Token Alias -> Hard Token Issuer Data
51      * the administrator is authorized to view and edit
52      * @return A TreeMap Hard Token Alias (String) -> HardTokenIssuerData
53      */

54     public TreeMap JavaDoc getHardTokenIssuers(){
55       if(hardtokenissuers==null){
56         hardtokenissuers = new TreeMap JavaDoc();
57         Iterator JavaDoc iter = authorizationsession.getAuthorizedAdminGroupNames(admin).iterator();
58         HashSet JavaDoc authadmingroupids = new HashSet JavaDoc();
59         while(iter.hasNext()){
60           AdminGroup next = (AdminGroup) iter.next();
61           authadmingroupids.add(new Integer JavaDoc(next.getAdminGroupId()));
62         }
63         TreeMap JavaDoc allhardtokenissuers = this.hardtokensession.getHardTokenIssuers(admin);
64         iter = allhardtokenissuers.keySet().iterator();
65         while(iter.hasNext()){
66           String JavaDoc alias = (String JavaDoc) iter.next();
67           if(authadmingroupids.contains(new Integer JavaDoc(((HardTokenIssuerData) allhardtokenissuers.get(alias)).getAdminGroupId()))){
68             hardtokenissuers.put(alias,allhardtokenissuers.get(alias));
69           }
70         }
71       }
72       
73       return hardtokenissuers;
74     }
75     
76     /**
77      * Method returning a TreeMap containing Hard Token Profile Name -> Hard Token Profile Id
78      * the administrator is authorized to view and edit
79      * @return A TreeMap Hard Token Profile Name (String) -> Hard Token Profile Id
80      */

81     public TreeMap JavaDoc getHardTokenProfiles(){
82       if(hardtokenprofiles==null){
83         hardtokenprofiles = new TreeMap JavaDoc();
84         Collection JavaDoc authorizedhardtokenprofiles = hardtokensession.getAuthorizedHardTokenProfileIds(admin);
85         
86         Iterator JavaDoc iter = authorizedhardtokenprofiles.iterator();
87         while(iter.hasNext()){
88           Integer JavaDoc id = ((Integer JavaDoc) iter.next());
89           String JavaDoc name = hardtokensession.getHardTokenProfileName(admin,id.intValue());
90           hardtokenprofiles.put(name, id);
91         }
92       }
93       return hardtokenprofiles;
94     }
95     
96     
97     /**
98      * Checks if administrator is authorized to edit the specified hard token issuer.
99      *
100      * @param alias of hard token issuer
101      * @return true if administrator is authorized to edit ahrd token issuer.
102      */

103     
104     public boolean authorizedToHardTokenIssuer(String JavaDoc alias){
105         boolean returnval = false;
106         try{
107           returnval = this.authorizationsession.isAuthorizedNoLog(admin,"/hardtoken_functionality/edit_hardtoken_issuers");
108         }catch(AuthorizationDeniedException ade){}
109         
110         return returnval && this.getHardTokenIssuers().keySet().contains(alias);
111     }
112
113     /**
114      * Checks if administrator is authorized to edit the specified hard token profile.
115      *
116      * @param alias of hard token profile
117      * @return true if administrator is authorized to edit hard token profile.
118      */

119     
120     public boolean authorizedToHardTokenProfile(String JavaDoc name){
121         boolean returnval = false;
122         try{
123           returnval = this.authorizationsession.isAuthorizedNoLog(admin,"/hardtoken_functionality/edit_hardtoken_profiles");
124         }catch(AuthorizationDeniedException ade){}
125         
126         return returnval && this.getHardTokenProfiles().keySet().contains(name);
127     }
128
129     
130     /**
131      * Returns a Map of hard token profile id (Integer) -> hard token profile name (String).
132      */

133     public HashMap JavaDoc getHardTokenProfileIdToNameMap(){
134       if(hardtokenprofilesnamemap == null){
135         hardtokenprofilesnamemap = this.hardtokensession.getHardTokenProfileIdToNameMap(admin);
136       }
137       
138       return hardtokenprofilesnamemap;
139     }
140     
141     /**
142      * Returns a Collection of AdminGroup names authorized to issue hard tokens,
143      * it also only returns the admin groups the administrator is authorized to edit.
144      */

145     public Collection JavaDoc getHardTokenIssuingAdminGroups(){
146       if(authissueingadmgrps == null){
147         authissueingadmgrps = new ArrayList JavaDoc();
148         Iterator JavaDoc iter = authorizationsession.getAuthorizedAdminGroupNames(admin).iterator();
149         while(iter.hasNext()){
150           AdminGroup next = (AdminGroup) iter.next();
151           try {
152             if(authorizationsession.isGroupAuthorizedNoLog(admin, next.getAdminGroupId() ,"/hardtoken_functionality/issue_hardtokens"))
153               authissueingadmgrps.add(next);
154           } catch (AuthorizationDeniedException e) {}
155         }
156       }
157         
158       return authissueingadmgrps;
159     }
160     
161     public void clear(){
162       hardtokenissuers=null;
163       hardtokenprofiles=null;
164       hardtokenprofilesnamemap=null;
165       authissueingadmgrps=null;
166     }
167     
168     // Private fields.
169
private TreeMap JavaDoc hardtokenissuers = null;
170     private TreeMap JavaDoc hardtokenprofiles = null;
171     private HashMap JavaDoc hardtokenprofilesnamemap=null;
172     private ArrayList JavaDoc authissueingadmgrps = null;
173     
174     private Admin admin;
175     private IHardTokenSessionLocal hardtokensession;
176     private IAuthorizationSessionLocal authorizationsession;
177
178 }
179
180
181
Popular Tags