1 13 14 package org.ejbca.ui.web.admin.approval; 15 16 import java.io.Serializable ; 17 import java.io.UnsupportedEncodingException ; 18 import java.security.cert.CertificateException ; 19 import java.text.DateFormat ; 20 import java.util.ArrayList ; 21 import java.util.Date ; 22 import java.util.List ; 23 24 import javax.ejb.EJBException ; 25 import javax.faces.application.Application; 26 import javax.faces.context.FacesContext; 27 import javax.faces.el.ValueBinding; 28 29 import org.apache.log4j.Logger; 30 import org.ejbca.core.model.approval.ApprovalDataText; 31 import org.ejbca.core.model.approval.ApprovalDataVO; 32 import org.ejbca.core.model.approval.ApprovalRequest; 33 import org.ejbca.core.model.approval.approvalrequests.DummyApprovalRequest; 34 import org.ejbca.core.model.log.Admin; 35 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper; 36 import org.ejbca.util.Base64; 37 import org.ejbca.util.CertTools; 38 39 40 47 public class ApprovalDataVOView implements Serializable { 48 49 private static final Logger log = Logger.getLogger(ApprovalDataVOView.class); 50 51 private ApprovalDataVO data; 52 53 private boolean initialized = false; 54 55 public ApprovalDataVOView( ApprovalDataVO data){ 56 this.data= data; 57 initialized = true; 58 } 59 60 63 public ApprovalDataVOView(){}{} 64 65 public String getRequestDate(){ 66 DateFormat dateformat = DateFormat.getDateTimeInstance(); 67 if(!initialized){ 68 return dateformat.format(new Date ()); 69 } 70 71 return dateformat.format(data.getRequestDate()); 72 } 73 74 public String getExpireDate(){ 75 DateFormat dateformat = DateFormat.getDateTimeInstance(); 76 if(!initialized){ 77 return dateformat.format(new Date ()); 78 } 79 80 return dateformat.format(data.getExpireDate()); 81 } 82 83 public String getCaName(){ 84 if(!initialized){ 85 return "TestCA"; 86 } 87 88 EjbcaJSFHelper helpBean = EjbcaJSFHelper.getBean(); 89 if(data.getCAId() == ApprovalDataVO.ANY_CA){ 90 return helpBean.getEjbcaWebBean().getText("ANYCA", true); 91 } 92 93 94 return helpBean.getCAAdminSession().getCAInfo(helpBean.getAdmin(), data.getCAId()).getName(); 95 } 96 97 public String getEndEntityProfileName(){ 98 if(!initialized){ 99 return "TestProfile"; 100 } 101 EjbcaJSFHelper helpBean = EjbcaJSFHelper.getBean(); 102 if(data.getEndEntityProfileiId() == ApprovalDataVO.ANY_ENDENTITYPROFILE){ 103 return helpBean.getEjbcaWebBean().getText("ANYENDENTITYPROFILE", true); 104 } 105 return helpBean.getRaAdminSession().getEndEntityProfileName(helpBean.getAdmin(), data.getEndEntityProfileiId()); 106 } 107 108 public String getRemainingApprovals(){ 109 if(!initialized){ 110 return "1"; 111 } 112 113 return "" +data.getRemainingApprovals(); 114 } 115 116 117 public String getApproveActionName(){ 118 if(!initialized){ 119 return "DummyAction"; 120 } 121 return EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(ApprovalDataVO.APPROVALTYPENAMES[data.getApprovalRequest().getApprovalType()], true); 122 } 123 124 public String getRequestAdminName(){ 125 String retval; 126 if(!initialized){ 127 return "DummyAdmin"; 128 } 129 130 if(data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER){ 131 String dn = data.getApprovalRequest().getRequestAdminCert().getSubjectDN().toString(); 132 String o = CertTools.getPartFromDN(dn, "O"); 133 if(o==null){ 134 o=""; 135 }else{ 136 o = ", " + o; 137 } 138 139 retval = CertTools.getPartFromDN(dn, "CN") + o; 140 }else{ 141 retval = EjbcaJSFHelper.getBean().getEjbcaWebBean().getText("CLITOOL", true); 142 } 143 144 log.debug("getRequestAdminName " + retval); 145 return retval; 146 } 147 148 public String getStatus(){ 149 if(!initialized){ 150 return "EXPIRED"; 151 } 152 153 FacesContext context = FacesContext.getCurrentInstance(); 154 Application app = context.getApplication(); 155 ValueBinding binding = app.createValueBinding("#{approvalActionSession}"); 156 Object value = binding.getValue(context); 157 ApproveActionSessionBean approvalActionSession = (ApproveActionSessionBean) value; 158 159 160 return (String ) approvalActionSession.getStatusText().get(new Integer (data.getStatus())); 161 } 162 163 164 165 168 public ApprovalDataVO getApproveActionDataVO() { 169 if(!initialized){ 170 try { 171 return new ApprovalDataVO(1,1, ApprovalDataVO.APPROVALTYPE_DUMMY, 0,0,"","",ApprovalDataVO.STATUS_WAITINGFORAPPROVAL,new ArrayList (),new DummyApprovalRequest(new Admin(CertTools.getCertfromByteArray(ApprovalDataVOView.dummycert)),null,ApprovalDataVO.ANY_ENDENTITYPROFILE,ApprovalDataVO.ANY_CA,false),new Date (),new Date (),2); 172 } catch (CertificateException e) { 173 log.error(e); 174 } 175 } 176 return data; 177 } 178 179 public int getApprovalId() { 180 if(!initialized){ 181 return 1; 182 } 183 return data.getApprovalId(); 184 } 185 186 187 191 public String getApproveActionWindowLink(){ 192 String link = EjbcaJSFHelper.getBean().getEjbcaWebBean().getBaseUrl() + EjbcaJSFHelper.getBean().getEjbcaWebBean().getGlobalConfiguration().getAdminWebPath() + "approval/approveaction.jsf?uniqueId=" + data.getId(); 193 194 return "window.open('"+link+"', 'ViewApproveAction', 'width=1000,height=800,scrollbars=yes,toolbar=no,resizable=yes').focus()"; 195 } 196 197 198 public boolean getShowViewRequestorCertLink(){ 199 return data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER; 200 } 201 202 public String getViewRequestorCertLink(){ 203 String retval = ""; 204 if(data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER){ 205 String link; 206 try { 207 link = EjbcaJSFHelper.getBean().getEjbcaWebBean().getBaseUrl() + EjbcaJSFHelper.getBean().getEjbcaWebBean().getGlobalConfiguration().getAdminWebPath() 208 + "viewcertificate.jsp?certsernoparameter=" + java.net.URLEncoder.encode(data.getReqadmincertsn() + "," + data.getReqadmincertissuerdn(),"UTF-8"); 209 } catch (UnsupportedEncodingException e) { 210 throw new EJBException (e); 211 } 212 213 retval = "viewcert('" + link + "')"; 214 } 215 216 return retval; 217 } 218 219 public List getTextComparisonList(){ 220 ArrayList textComparisonList = new ArrayList (); 221 if(!initialized){ 222 return textComparisonList; 223 } 224 225 if(data.getApprovalRequest().getApprovalRequestType() == ApprovalRequest.REQUESTTYPE_COMPARING){ 226 List newTextRows = data.getApprovalRequest().getNewRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin()); 227 List orgTextRows = data.getApprovalRequest().getOldRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin()); 228 int size = newTextRows.size(); 229 if(orgTextRows.size() > size){ 230 size = orgTextRows.size(); 231 } 232 233 for(int i=0;i<size;i++){ 234 String orgString =""; 235 try{ 236 orgString = translateApprovalDataText((ApprovalDataText) orgTextRows.get(i)); 237 }catch(ArrayIndexOutOfBoundsException e){ 238 } 240 String newString =""; 241 try{ 242 newString = translateApprovalDataText((ApprovalDataText) newTextRows.get(i)); 243 }catch(ArrayIndexOutOfBoundsException e){ 244 } 246 textComparisonList.add(new TextComparisonView(orgString, newString)); 247 } 248 249 }else{ 250 List newTextRows = data.getApprovalRequest().getNewRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin()); 251 int size = newTextRows.size(); 252 for(int i=0;i<size;i++){ 253 textComparisonList.add(new TextComparisonView(null, translateApprovalDataText((ApprovalDataText) newTextRows.get(i)))); 254 } 255 } 256 257 258 return textComparisonList; 259 } 260 261 private String translateApprovalDataText(ApprovalDataText data){ 262 String retval = ""; 263 if(data.isHeaderTranslateable()){ 264 retval = EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(data.getHeader(), true); 265 }else{ 266 retval = data.getHeader(); 267 } 268 269 if(data.isDataTranslatable()){ 270 retval += " : " + EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(data.getData(), true); 271 }else{ 272 retval += " : " + data.getData(); 273 } 274 275 return retval; 276 } 277 278 private static byte[] dummycert = Base64.decode(("MIIDATCCAmqgAwIBAgIIczEoghAwc3EwDQYJKoZIhvcNAQEFBQAwLzEPMA0GA1UE" 279 + "AxMGVGVzdENBMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNFMB4XDTAzMDky" 280 + "NDA2NDgwNFoXDTA1MDkyMzA2NTgwNFowMzEQMA4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