KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.ejb.CreateException JavaDoc;
22 import javax.ejb.DuplicateKeyException JavaDoc;
23 import javax.ejb.EJBException JavaDoc;
24
25 import org.apache.log4j.Logger;
26 import org.ejbca.core.ejb.ServiceLocator;
27 import org.ejbca.core.ejb.ra.IUserAdminSessionLocal;
28 import org.ejbca.core.ejb.ra.IUserAdminSessionLocalHome;
29 import org.ejbca.core.model.approval.ApprovalDataText;
30 import org.ejbca.core.model.approval.ApprovalDataVO;
31 import org.ejbca.core.model.approval.ApprovalException;
32 import org.ejbca.core.model.approval.ApprovalRequest;
33 import org.ejbca.core.model.approval.ApprovalRequestExecutionException;
34 import org.ejbca.core.model.approval.WaitingForApprovalException;
35 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
36 import org.ejbca.core.model.log.Admin;
37 import org.ejbca.core.model.ra.UserDataVO;
38 import org.ejbca.core.model.ra.raadmin.UserDoesntFullfillEndEntityProfile;
39 import org.ejbca.util.CertTools;
40
41 /**
42  * Approval Request created when trying to add an end entity.
43  *
44  *
45  *
46  * @author Philip Vendil
47  * @version $Id: AddEndEntityApprovalRequest.java,v 1.3 2006/08/12 09:49:30 herrvendil Exp $
48  */

49 public class AddEndEntityApprovalRequest extends ApprovalRequest {
50
51     private static final long serialVersionUID = -1L;
52
53     private static final Logger log = Logger.getLogger(AddEndEntityApprovalRequest.class);
54     
55     private static final int LATEST_VERSION = 1;
56     
57     private UserDataVO userdata;
58     private boolean clearpwd;
59     
60     
61     /**
62      * Constuctor used in externaliziation only
63      */

64     public AddEndEntityApprovalRequest() {}
65
66
67     public AddEndEntityApprovalRequest(UserDataVO userdata, boolean clearpwd, Admin requestAdmin, String JavaDoc requestSignature, int numOfReqApprovals, int cAId, int endEntityProfileId) {
68         super(requestAdmin, requestSignature, REQUESTTYPE_SIMPLE,
69                 numOfReqApprovals, cAId, endEntityProfileId);
70         this.userdata = userdata;
71         this.clearpwd = clearpwd;
72     }
73
74
75     public void execute() throws ApprovalRequestExecutionException {
76         log.debug("Executing AddEndEntity for user:" + userdata.getUsername());
77         try{
78             ServiceLocator locator = ServiceLocator.getInstance();
79             IUserAdminSessionLocalHome userdatahome = (IUserAdminSessionLocalHome) locator.getLocalHome(IUserAdminSessionLocalHome.COMP_NAME);
80             IUserAdminSessionLocal usersession = userdatahome.create();
81         
82             usersession.addUser(getRequestAdmin(), userdata, clearpwd);
83         }catch( DuplicateKeyException JavaDoc e){
84             throw new ApprovalRequestExecutionException("Error, user already exists", e);
85         } catch (CreateException JavaDoc e) {
86             throw new ApprovalRequestExecutionException("Error creating userdata session", e);
87         } catch (AuthorizationDeniedException e) {
88             throw new ApprovalRequestExecutionException("Authorization Denied :" + e.getMessage(), e);
89         } catch (UserDoesntFullfillEndEntityProfile e) {
90             throw new ApprovalRequestExecutionException("User Doesn't fullfil end entity profile :" + e.getMessage() + e.getMessage(), e);
91         } catch (ApprovalException e) {
92             throw new EJBException JavaDoc("This should never happen",e);
93         } catch (WaitingForApprovalException e) {
94             throw new EJBException JavaDoc("This should never happen",e);
95         }
96
97     }
98
99     /**
100      * Approval Id is genereated of This approval type (i.e AddEndEntityApprovalRequest) and UserName
101      */

102     public int generateApprovalId() {
103         return new String JavaDoc(getApprovalType() + ";" + userdata.getUsername()).hashCode();
104     }
105
106
107     public int getApprovalType() {
108         return ApprovalDataVO.APPROVALTYPE_ADDENDENTITY;
109     }
110
111
112
113     public List JavaDoc getNewRequestDataAsText(Admin admin) {
114         ArrayList JavaDoc retval = new ArrayList JavaDoc();
115         retval.add(new ApprovalDataText("USERNAME",userdata.getUsername(),true,false));
116         retval.add(new ApprovalDataText("SUBJECTDN",CertTools.stringToBCDNString(userdata.getDN()),true,false));
117         retval.add(getTextWithNoValueString("SUBJECTALTNAME",userdata.getSubjectAltName()));
118         retval.add(getTextWithNoValueString("SUBJECTDIRATTRIBUTES",userdata.getExtendedinformation().getSubjectDirectoryAttributes()));
119         retval.add(getTextWithNoValueString("EMAIL",userdata.getEmail()));
120         retval.add(new ApprovalDataText("CA",getCAName(admin, userdata.getCAId()),true,false));
121         retval.add(new ApprovalDataText("ENDENTITYPROFILE",getEndEntityProfileName(admin,userdata.getEndEntityProfileId()),true,false));
122         retval.add(new ApprovalDataText("CERTIFICATEPROFILE",getCertificateProfileName(admin,userdata.getCertificateProfileId()),true,false));
123         retval.add(getTokenName(admin,userdata.getTokenType()));
124         retval.add(getTextWithNoValueString("HARDTOKENISSUERALIAS",getHardTokenIssuerName(admin,userdata.getHardTokenIssuerId())));
125         retval.add(new ApprovalDataText("ADMINISTRATOR",userdata.getAdministrator() ? "YES" : "NO",true,true));
126         retval.add(new ApprovalDataText("KEYRECOVERABLE",userdata.getKeyRecoverable() ? "YES" : "NO",true,true));
127         retval.add(new ApprovalDataText("SENDNOTIFICATION",userdata.getSendNotification() ? "YES" : "NO",true,true));
128         return retval;
129     }
130     
131     private ApprovalDataText getTextWithNoValueString(String JavaDoc header, String JavaDoc data){
132         if(data==null || data.equals("")){
133             return new ApprovalDataText(header,"NOVALUE",true,true);
134         }
135             
136         return new ApprovalDataText(header,data,true,false);
137     }
138
139     public List JavaDoc getOldRequestDataAsText(Admin admin) {
140         return null;
141     }
142
143
144
145     public boolean isExecutable() {
146         return true;
147     }
148     
149     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
150         super.writeExternal(out);
151         out.writeInt(LATEST_VERSION);
152         out.writeObject(userdata);
153         out.writeBoolean(clearpwd);
154     }
155
156     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
157         super.readExternal(in);
158         int version = in.readInt();
159         if(version == 1){
160             userdata = (UserDataVO) in.readObject();
161             clearpwd = in.readBoolean();
162         }
163
164     }
165
166 }
167
Popular Tags