KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > approval > approvalrequests > DummyApprovalRequest


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.core.model.approval.approvalrequests;
14
15 import java.io.IOException JavaDoc;
16 import java.io.ObjectInput JavaDoc;
17 import java.io.ObjectOutput JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.List JavaDoc;
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 /**
30  * Dummy Approval Request used for testing and demonstration purposes.
31  *
32  *
33  *
34  * @author Philip Vendil
35  * @version $Id: DummyApprovalRequest.java,v 1.3 2006/08/11 02:57:49 herrvendil Exp $
36  */

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     /**
53      * Main constructor of an approval request
54      * @param requestAdminCert the certificate of the requesting admin
55      * @param requestSignature signature of the requestor (OPTIONAL, for future use)
56      * @param approvalRequestType one of TYPE_ constants
57      * @param numOfRequiredApprovals
58      * @param cAId the related cAId of the request that the approver must be authorized to or ApprovalDataVO.ANY_CA in applicable to any ca
59      * @param endEntityProfileId the related profile id that the approver must be authorized to or ApprovalDataVO.ANY_ENDENTITYPROFILE if applicable to any end entity profile
60      */

61
62     public DummyApprovalRequest(Admin requestAdmin, String JavaDoc 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     /**
70      * Constuctor used in externaliziation only
71      */

72     public DummyApprovalRequest(){
73     }
74     
75     /**
76      * Should return true if the request if of the type that should be executed
77      * by the last approver.
78      *
79      * False if the request admin should do a polling action to try again.
80      */

81     public boolean isExecutable(){
82         return executable;
83     }
84     
85     /**
86      * A main function of the ApprovalRequest, the execute() method
87      * is run when all required approvals have been made.
88      *
89      * execute should perform the action or nothing if the requesting admin
90      * is supposed to try his action again.
91      */

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     /**
102      * Method that should generate an approval id for this type of
103      * approval, the same request i.e the same admin want's to do the
104      * same thing twice should result in the same approvalId.
105      */

106     public int generateApprovalId(){
107         return (CertTools.getFingerprintAsString(getRequestAdminCert()) + getApprovalType() + getCAId() + getEndEntityProfileId()).hashCode();
108     }
109     
110
111     public List JavaDoc getNewRequestDataAsText(Admin admin){
112         ArrayList JavaDoc newText = new ArrayList JavaDoc();
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 JavaDoc getOldRequestDataAsText(Admin admin){
121         return null;
122     }
123
124
125     /**
126      * Should return the time in millisecond that the request should be valid
127      * or Long.MAX_VALUE if it should never expire
128      *
129      * Returns 4 s (For testscripts only. usually 30 minutes or something)
130      */

131     public long getRequestValidity(){
132         return 4 * 1000;
133     }
134     
135     /**
136      * Should return the time in second that the approval should be valid
137      * or Long.MAX_VALUE if it should never expire
138      *
139      * Returns 4 s (For testscripts only. usually 30 minutes or something)
140      */

141     public long getApprovalValidity(){
142         return 4 * 1000;
143     }
144     
145     
146     /**
147      * Should return one of the ApprovalDataVO.APPROVALTYPE_ constants
148      */

149     public int getApprovalType(){
150         return ApprovalDataVO.APPROVALTYPE_DUMMY;
151     }
152
153
154     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
155         super.writeExternal(out);
156         out.writeInt(LATEST_VERSION);
157         out.writeBoolean(executable);
158     }
159
160     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
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