1 13 14 package org.ejbca.ui.web.admin.cainterface; 15 16 import java.security.cert.X509Certificate ; 17 18 import javax.servlet.http.HttpServletRequest ; 19 20 import org.ejbca.core.model.SecConst; 21 import org.ejbca.core.model.authorization.AuthorizationDeniedException; 22 import org.ejbca.core.model.authorization.AvailableAccessRules; 23 import org.ejbca.core.model.ca.catoken.CATokenAuthenticationFailedException; 24 import org.ejbca.core.model.ca.catoken.CATokenOfflineException; 25 import org.ejbca.core.model.ca.catoken.HardCATokenInfo; 26 import org.ejbca.core.model.ca.catoken.IHardCAToken; 27 import org.ejbca.ui.web.RequestHelper; 28 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean; 29 30 31 37 public class ViewCAInfoJSPHelper implements java.io.Serializable { 38 39 public static final String CA_PARAMETER = "caid"; 40 41 public static final String CERTSERNO_PARAMETER = "certsernoparameter"; 42 43 public static final String PASSWORD_AUTHENTICATIONCODE = "passwordactivationcode"; 44 45 public static final String BUTTON_ACTIVATE = "buttonactivate"; 46 public static final String BUTTON_MAKEOFFLINE = "buttonmakeoffline"; 47 public static final String BUTTON_CLOSE = "buttonclose"; 48 49 50 51 public ViewCAInfoJSPHelper(){ 52 } 53 59 public void initialize(HttpServletRequest request, EjbcaWebBean ejbcawebbean, 60 CAInterfaceBean cabean) throws Exception { 61 62 if(!initialized){ 63 this.cabean = cabean; 64 initialized = true; 65 can_activate = false; 66 authorized = false; 67 try{ 68 authorized = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.REGULAR_CABASICFUNCTIONS); 69 can_activate = ejbcawebbean.isAuthorizedNoLog(AvailableAccessRules.REGULAR_ACTIVATECA); 70 }catch(AuthorizationDeniedException ade){} 71 } 72 } 73 74 79 public void parseRequest(HttpServletRequest request) throws Exception { 80 generalerrormessage = null; 81 activationerrormessage = null; 82 activationmessage = null; 83 ishardcatoken = false; 84 85 RequestHelper.setDefaultCharacterEncoding(request); 86 87 if( request.getParameter(CA_PARAMETER) != null ){ 88 caid = Integer.parseInt(request.getParameter(CA_PARAMETER)); 89 90 if(request.getParameter(BUTTON_ACTIVATE) != null || request.getParameter(BUTTON_MAKEOFFLINE) != null){ 91 status = SecConst.CA_OFFLINE; 93 try{ 94 cainfo = cabean.getCAInfo(caid); 95 status = cainfo.getCAInfo().getStatus(); 96 if( cainfo.getCAInfo().getCATokenInfo() instanceof HardCATokenInfo ){ 97 ishardcatoken = true; 98 } 99 } catch(AuthorizationDeniedException e){ 100 generalerrormessage = "NOTAUTHORIZEDTOVIEWCA"; 101 return; 102 } 103 104 if(request.getParameter(BUTTON_ACTIVATE) != null && 106 can_activate && 107 ishardcatoken && 108 ((status == SecConst.CA_OFFLINE) || 109 (status == SecConst.CA_ACTIVE && 110 ((HardCATokenInfo) cainfo.getCAInfo().getCATokenInfo()).getCATokenStatus() == IHardCAToken.STATUS_OFFLINE))){ 111 112 String authorizationcode = request.getParameter(PASSWORD_AUTHENTICATIONCODE); 113 try { 114 cabean.getCADataHandler().activateCAToken(caid,authorizationcode); 115 activationmessage = "CAACTIVATIONSUCCESSFUL"; 116 } catch (CATokenAuthenticationFailedException catafe) { 117 activationerrormessage = "AUTHENTICATIONERROR"; 118 activationerrorreason = catafe.getMessage(); 119 } catch (CATokenOfflineException catoe) { 120 activationerrormessage = "ERROR"; 121 activationerrorreason = catoe.getMessage(); 122 } 123 } 124 if(request.getParameter(BUTTON_MAKEOFFLINE) != null && 126 can_activate && 127 ishardcatoken && 128 status == SecConst.CA_ACTIVE){ 129 130 try{ 131 cabean.getCADataHandler().deactivateCAToken(caid); 132 activationmessage = "MAKEOFFLINESUCCESSFUL"; 133 }catch(Exception e){ 134 throw e; 135 } 136 } 137 } 138 139 140 try{ 141 cainfo = cabean.getCAInfo(caid); 142 status = cainfo.getCAInfo().getStatus(); 143 if( cainfo.getCAInfo().getCATokenInfo() instanceof HardCATokenInfo ){ 144 ishardcatoken = true; 145 hardtokenoffline = ((HardCATokenInfo) cainfo.getCAInfo().getCATokenInfo()).getCATokenStatus() == IHardCAToken.STATUS_OFFLINE; 146 } 147 ocspcert = cainfo.getOCSPSignerCertificate(); 148 } catch(AuthorizationDeniedException e){ 149 generalerrormessage = "NOTAUTHORIZEDTOVIEWCA"; 150 } 151 152 if(cainfo==null){ 153 generalerrormessage = "CADOESNTEXIST"; 154 } 155 }else{ 156 generalerrormessage = "YOUMUSTSPECIFYCAID"; 157 } 158 159 } 160 161 162 163 private CAInterfaceBean cabean; 165 private boolean initialized=false; 166 public String generalerrormessage = null; 167 public String activationerrormessage = null; 168 public String activationerrorreason = null; 169 public String activationmessage = null; 170 public boolean can_activate = false; 171 public boolean authorized = false; 172 public boolean ishardcatoken = false; 173 public CAInfoView cainfo = null; 174 public int status = 0; 175 public boolean hardtokenoffline = false; 176 public int caid = 0; 177 public X509Certificate ocspcert = null; 178 179 180 } 181 | Popular Tags |