1 13 package org.ejbca.core.model.approval.approvalrequests; 14 15 import java.io.IOException ; 16 import java.io.ObjectInput ; 17 import java.io.ObjectOutput ; 18 import java.util.ArrayList ; 19 import java.util.List ; 20 21 import org.apache.log4j.Logger; 22 import org.ejbca.core.model.approval.ApprovalDataText; 23 import org.ejbca.core.model.approval.ApprovalDataVO; 24 import org.ejbca.core.model.approval.ApprovalRequest; 25 import org.ejbca.core.model.approval.ApprovalRequestExecutionException; 26 import org.ejbca.core.model.log.Admin; 27 import org.ejbca.util.CertTools; 28 29 37 38 public class DummyApprovalRequest extends ApprovalRequest { 39 40 private static final long serialVersionUID = -1L; 41 42 private static final Logger log = Logger.getLogger(DummyApprovalRequest.class); 43 44 private static final int LATEST_VERSION = 1; 45 46 private static final int NUM_OF_REQUIRED_APPROVALS = 2; 47 48 49 50 private boolean executable = false; 51 52 61 62 public DummyApprovalRequest(Admin requestAdmin, String requestSignature, int cAId, int endEntityProfileId, boolean executable) { 63 super(requestAdmin, requestSignature, ApprovalRequest.REQUESTTYPE_SIMPLE, 64 NUM_OF_REQUIRED_APPROVALS, cAId, endEntityProfileId); 65 this.executable = executable; 66 67 } 68 69 72 public DummyApprovalRequest(){ 73 } 74 75 81 public boolean isExecutable(){ 82 return executable; 83 } 84 85 92 public void execute() throws ApprovalRequestExecutionException{ 93 if(executable){ 94 log.info("Dummy Is Executable, this should be shown in the log"); 95 }else{ 96 log.error("Error: This shouldn't be logged, DummyApprovalRequest isn't executable"); 97 } 98 99 } 100 101 106 public int generateApprovalId(){ 107 return (CertTools.getFingerprintAsString(getRequestAdminCert()) + getApprovalType() + getCAId() + getEndEntityProfileId()).hashCode(); 108 } 109 110 111 public List getNewRequestDataAsText(Admin admin){ 112 ArrayList newText = new ArrayList (); 113 newText.add(new ApprovalDataText("DUMMYDATAROW1: ", "YES" , false, false)); 114 newText.add(new ApprovalDataText("DUMMYDATAROW2: ", "YES" , false, false)); 115 return newText; 116 117 } 118 119 120 public List getOldRequestDataAsText(Admin admin){ 121 return null; 122 } 123 124 125 131 public long getRequestValidity(){ 132 return 4 * 1000; 133 } 134 135 141 public long getApprovalValidity(){ 142 return 4 * 1000; 143 } 144 145 146 149 public int getApprovalType(){ 150 return ApprovalDataVO.APPROVALTYPE_DUMMY; 151 } 152 153 154 public void writeExternal(ObjectOutput out) throws IOException { 155 super.writeExternal(out); 156 out.writeInt(LATEST_VERSION); 157 out.writeBoolean(executable); 158 } 159 160 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 161 super.readExternal(in); 162 int version = in.readInt(); 163 if(version == 1){ 164 this.executable = in.readBoolean(); 165 } 166 167 } 168 169 170 } 171 | Popular Tags |