1 package org.ejbca.ui.web.admin.configuration; 2 3 import java.security.cert.X509Certificate ; 4 import java.util.Map ; 5 6 import javax.ejb.CreateException ; 7 import javax.ejb.EJBException ; 8 import javax.faces.application.Application; 9 import javax.faces.context.FacesContext; 10 import javax.faces.el.ValueBinding; 11 import javax.servlet.http.HttpServletRequest ; 12 import javax.servlet.http.HttpSession ; 13 14 import org.apache.log4j.Logger; 15 import org.ejbca.core.ejb.ServiceLocator; 16 import org.ejbca.core.ejb.approval.IApprovalSessionLocal; 17 import org.ejbca.core.ejb.approval.IApprovalSessionLocalHome; 18 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal; 19 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocalHome; 20 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocal; 21 import org.ejbca.core.ejb.ra.raadmin.IRaAdminSessionLocalHome; 22 import org.ejbca.core.ejb.services.IServiceSessionLocal; 23 import org.ejbca.core.ejb.services.IServiceSessionLocalHome; 24 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 25 import org.ejbca.core.model.authorization.AvailableAccessRules; 26 import org.ejbca.core.model.log.Admin; 27 import org.ejbca.ui.web.RequestHelper; 28 29 30 31 32 39 40 public class EjbcaJSFHelper { 41 private static final Logger log = Logger.getLogger(EjbcaJSFHelper.class); 42 43 private EjbcaJSFLanguageResource text = null; 44 private EjbcaJSFImageResource image = null; 45 private EjbcaWebBean ejbcawebbean; 46 47 48 private IRaAdminSessionLocal raadminsession; 49 private ICAAdminSessionLocal caadminsession; 50 private IApprovalSessionLocal approvalsession; 51 private IServiceSessionLocal servicesession; 52 53 54 private FacesContext ctx = FacesContext.getCurrentInstance(); 55 56 private Admin admin = null; 57 58 59 public EjbcaJSFHelper(){} 60 61 public void setEjbcaWebBean(EjbcaWebBean ejbcawebbean){ 62 this.ejbcawebbean = ejbcawebbean; 63 text = new EjbcaJSFLanguageResource(ejbcawebbean); 64 image = new EjbcaJSFImageResource(ejbcawebbean); 65 admin = getAdmin(); 66 } 67 68 71 public String getEjbcaTitle(){ 72 return getEjbcaWebBean().getGlobalConfiguration().getEjbcaTitle(); 73 } 74 75 78 public String getTheme(){ 79 return getEjbcaWebBean().getCssFile(); 80 } 81 82 85 public String getEjbcaBaseURL(){ 86 return getEjbcaWebBean().getBaseUrl(); 87 } 88 89 92 public String getContent(){ 93 return "text/html; charset=" + RequestHelper.getDefaultContentEncoding(); 94 } 95 96 99 public Map getText(){ 100 return text; 101 } 102 103 106 public Map getImage(){ 107 return image; 108 } 109 110 115 public void authorizedToApprovalPages() throws AuthorizationDeniedException{ 116 boolean approveendentity = false; 118 boolean approvecaaction = false; 119 try{ 120 approveendentity = getEjbcaWebBean().isAuthorizedNoLog(AvailableAccessRules.REGULAR_APPROVEENDENTITY); 121 }catch(AuthorizationDeniedException e){} 122 try{ 123 approvecaaction = getEjbcaWebBean().isAuthorizedNoLog(AvailableAccessRules.REGULAR_APPROVECAACTION); 124 }catch(AuthorizationDeniedException e){} 125 if(!approveendentity && !approvecaaction){ 126 throw new AuthorizationDeniedException("Not authorized to view approval pages"); 127 } 128 } 129 130 135 public void authorizedToServicesPages() throws AuthorizationDeniedException{ 136 getEjbcaWebBean().isAuthorizedNoLog(AvailableAccessRules.ROLE_SUPERADMINISTRATOR); 137 } 138 139 public int getEntriesPerPage(){ 140 return getEjbcaWebBean().getEntriesPerPage(); 141 } 142 143 public EjbcaWebBean getEjbcaWebBean(){ 144 145 if(ejbcawebbean == null){ 146 FacesContext ctx = FacesContext.getCurrentInstance(); 147 148 HttpSession session = (HttpSession ) ctx.getExternalContext().getSession(true); 149 150 151 synchronized (session) { 152 ejbcawebbean = (org.ejbca.ui.web.admin.configuration.EjbcaWebBean) session.getAttribute("ejbcawebbean"); 153 if (ejbcawebbean == null){ 154 ejbcawebbean = new org.ejbca.ui.web.admin.configuration.EjbcaWebBean(); 155 session.setAttribute("ejbcawebbean", ejbcawebbean); 156 } 157 } 158 159 try { 160 ejbcawebbean.initialize((HttpServletRequest ) ctx.getExternalContext().getRequest(), "/administrator"); 161 } catch (Exception e) { 162 log.error(e); 163 } 164 } 165 166 return ejbcawebbean; 167 } 168 169 public Admin getAdmin() { 170 if(admin == null){ 171 X509Certificate [] certificates = (X509Certificate []) ((HttpServletRequest )ctx.getExternalContext().getRequest()).getAttribute( "javax.servlet.request.X509Certificate" ); 172 admin = new Admin(certificates[0]); 173 } 174 return admin; 175 } 176 177 public static EjbcaJSFHelper getBean(){ 178 FacesContext context = FacesContext.getCurrentInstance(); 179 Application app = context.getApplication(); 180 ValueBinding binding = app.createValueBinding("#{web}"); 181 Object value = binding.getValue(context); 182 return (EjbcaJSFHelper) value; 183 } 184 185 public IRaAdminSessionLocal getRaAdminSession(){ 186 if(raadminsession == null){ 187 ServiceLocator locator = ServiceLocator.getInstance(); 188 IRaAdminSessionLocalHome raadminsessionhome = (IRaAdminSessionLocalHome) locator.getLocalHome(IRaAdminSessionLocalHome.COMP_NAME); 189 try { 190 raadminsession = raadminsessionhome.create(); 191 } catch (CreateException e) { 192 throw new EJBException (e); 193 } 194 } 195 196 return raadminsession; 197 } 198 199 public ICAAdminSessionLocal getCAAdminSession(){ 200 if(caadminsession == null){ 201 ServiceLocator locator = ServiceLocator.getInstance(); 202 ICAAdminSessionLocalHome caadminsessionhome = (ICAAdminSessionLocalHome) locator.getLocalHome(ICAAdminSessionLocalHome.COMP_NAME); 203 try { 204 caadminsession = caadminsessionhome.create(); 205 } catch (CreateException e) { 206 throw new EJBException (e); 207 } 208 } 209 return caadminsession; 210 } 211 212 public IApprovalSessionLocal getApprovalSession(){ 213 if(approvalsession == null){ 214 ServiceLocator locator = ServiceLocator.getInstance(); 215 IApprovalSessionLocalHome approvalsessionhome = (IApprovalSessionLocalHome) locator.getLocalHome(IApprovalSessionLocalHome.COMP_NAME); 216 try { 217 approvalsession = approvalsessionhome.create(); 218 } catch (CreateException e) { 219 throw new EJBException (e); 220 } 221 } 222 return approvalsession; 223 } 224 225 226 public IServiceSessionLocal getServiceSession(){ 227 if(servicesession == null){ 228 ServiceLocator locator = ServiceLocator.getInstance(); 229 IServiceSessionLocalHome servicesessionhome = (IServiceSessionLocalHome) locator.getLocalHome(IServiceSessionLocalHome.COMP_NAME); 230 try { 231 servicesession = servicesessionhome.create(); 232 } catch (CreateException e) { 233 throw new EJBException (e); 234 } 235 } 236 return servicesession; 237 } 238 } 239 | Popular Tags |