1 13 14 package org.ejbca.ui.web.admin.hardtokeninterface; 15 16 import java.io.Serializable ; 17 import java.util.ArrayList ; 18 import java.util.Collection ; 19 import java.util.HashMap ; 20 import java.util.HashSet ; 21 import java.util.Iterator ; 22 import java.util.TreeMap ; 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 36 public class HardTokenAuthorization implements Serializable { 37 38 39 40 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 54 public TreeMap getHardTokenIssuers(){ 55 if(hardtokenissuers==null){ 56 hardtokenissuers = new TreeMap (); 57 Iterator iter = authorizationsession.getAuthorizedAdminGroupNames(admin).iterator(); 58 HashSet authadmingroupids = new HashSet (); 59 while(iter.hasNext()){ 60 AdminGroup next = (AdminGroup) iter.next(); 61 authadmingroupids.add(new Integer (next.getAdminGroupId())); 62 } 63 TreeMap allhardtokenissuers = this.hardtokensession.getHardTokenIssuers(admin); 64 iter = allhardtokenissuers.keySet().iterator(); 65 while(iter.hasNext()){ 66 String alias = (String ) iter.next(); 67 if(authadmingroupids.contains(new Integer (((HardTokenIssuerData) allhardtokenissuers.get(alias)).getAdminGroupId()))){ 68 hardtokenissuers.put(alias,allhardtokenissuers.get(alias)); 69 } 70 } 71 } 72 73 return hardtokenissuers; 74 } 75 76 81 public TreeMap getHardTokenProfiles(){ 82 if(hardtokenprofiles==null){ 83 hardtokenprofiles = new TreeMap (); 84 Collection authorizedhardtokenprofiles = hardtokensession.getAuthorizedHardTokenProfileIds(admin); 85 86 Iterator iter = authorizedhardtokenprofiles.iterator(); 87 while(iter.hasNext()){ 88 Integer id = ((Integer ) iter.next()); 89 String name = hardtokensession.getHardTokenProfileName(admin,id.intValue()); 90 hardtokenprofiles.put(name, id); 91 } 92 } 93 return hardtokenprofiles; 94 } 95 96 97 103 104 public boolean authorizedToHardTokenIssuer(String 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 119 120 public boolean authorizedToHardTokenProfile(String 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 133 public HashMap getHardTokenProfileIdToNameMap(){ 134 if(hardtokenprofilesnamemap == null){ 135 hardtokenprofilesnamemap = this.hardtokensession.getHardTokenProfileIdToNameMap(admin); 136 } 137 138 return hardtokenprofilesnamemap; 139 } 140 141 145 public Collection getHardTokenIssuingAdminGroups(){ 146 if(authissueingadmgrps == null){ 147 authissueingadmgrps = new ArrayList (); 148 Iterator 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 TreeMap hardtokenissuers = null; 170 private TreeMap hardtokenprofiles = null; 171 private HashMap hardtokenprofilesnamemap=null; 172 private ArrayList authissueingadmgrps = null; 173 174 private Admin admin; 175 private IHardTokenSessionLocal hardtokensession; 176 private IAuthorizationSessionLocal authorizationsession; 177 178 } 179 180 181 | Popular Tags |