KickJava   Java API By Example, From Geeks To Geeks.

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


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.EJBException JavaDoc;
23
24 import org.apache.commons.lang.StringUtils;
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.UserDataConstants;
38 import org.ejbca.core.model.ra.UserDataVO;
39 import org.ejbca.core.model.ra.raadmin.UserDoesntFullfillEndEntityProfile;
40 import org.ejbca.util.CertTools;
41
42 /**
43  * Approval Request created when trying to edit an end entity.
44  *
45  *
46  *
47  * @author Philip Vendil
48  * @version $Id: EditEndEntityApprovalRequest.java,v 1.5 2006/08/20 12:49:21 anatom Exp $
49  */

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

65     public EditEndEntityApprovalRequest() {}
66
67
68     public EditEndEntityApprovalRequest(UserDataVO newuserdata, boolean clearpwd, UserDataVO orguserdata, Admin requestAdmin, String JavaDoc requestSignature, int numOfReqApprovals, int cAId, int endEntityProfileId) {
69         super(requestAdmin, requestSignature, REQUESTTYPE_COMPARING,
70                 numOfReqApprovals, cAId, endEntityProfileId);
71         this.newuserdata = newuserdata;
72         this.clearpwd = clearpwd;
73         this.orguserdata = orguserdata;
74     }
75
76
77     public void execute() throws ApprovalRequestExecutionException {
78         log.debug("Executing ChangeEndEntity for user:" + newuserdata.getUsername());
79         try{
80             ServiceLocator locator = ServiceLocator.getInstance();
81             IUserAdminSessionLocalHome userdatahome = (IUserAdminSessionLocalHome) locator.getLocalHome(IUserAdminSessionLocalHome.COMP_NAME);
82             IUserAdminSessionLocal usersession = userdatahome.create();
83         
84             usersession.changeUser(getRequestAdmin(), newuserdata, clearpwd);
85         }catch (CreateException JavaDoc e) {
86             throw new ApprovalRequestExecutionException("Error creating newuserdata 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() + ";" + newuserdata.getUsername()).hashCode();
104     }
105
106
107     public int getApprovalType() {
108         return ApprovalDataVO.APPROVALTYPE_EDITENDENTITY;
109     }
110
111
112
113     public List JavaDoc getNewRequestDataAsText(Admin admin) {
114         ArrayList JavaDoc retval = new ArrayList JavaDoc();
115         retval.add(new ApprovalDataText("USERNAME",newuserdata.getUsername(),true,false));
116         String JavaDoc passwordtext = "NOTSHOWN";
117         if((newuserdata.getPassword() == null && !StringUtils.isEmpty(orguserdata.getPassword())) ||
118            (!StringUtils.isEmpty(newuserdata.getPassword()) && orguserdata.getPassword() == null)) {
119             passwordtext = "NEWPASSWORD";
120         }
121         if(newuserdata.getPassword() != null && orguserdata.getPassword() != null){
122             if(!newuserdata.getPassword().equals(orguserdata.getPassword())){
123                 passwordtext = "NEWPASSWORD";
124             }
125         }
126         retval.add(new ApprovalDataText("PASSWORD",passwordtext,true,true));
127         retval.add(new ApprovalDataText("SUBJECTDN",CertTools.stringToBCDNString(newuserdata.getDN()),true,false));
128         retval.add(getTextWithNoValueString("SUBJECTALTNAME",newuserdata.getSubjectAltName()));
129         retval.add(getTextWithNoValueString("SUBJECTDIRATTRIBUTES",newuserdata.getExtendedinformation().getSubjectDirectoryAttributes()));
130         retval.add(getTextWithNoValueString("EMAIL",newuserdata.getEmail()));
131         retval.add(new ApprovalDataText("CA",getCAName(admin, newuserdata.getCAId()),true,false));
132         retval.add(new ApprovalDataText("ENDENTITYPROFILE",getEndEntityProfileName(admin,newuserdata.getEndEntityProfileId()),true,false));
133         retval.add(new ApprovalDataText("CERTIFICATEPROFILE",getCertificateProfileName(admin,newuserdata.getCertificateProfileId()),true,false));
134         retval.add(getTokenName(admin,newuserdata.getTokenType()));
135         retval.add(getTextWithNoValueString("HARDTOKENISSUERALIAS",getHardTokenIssuerName(admin,newuserdata.getHardTokenIssuerId())));
136         retval.add(new ApprovalDataText("ADMINISTRATOR",newuserdata.getAdministrator() ? "YES" : "NO",true,true));
137         retval.add(new ApprovalDataText("KEYRECOVERABLE",newuserdata.getKeyRecoverable() ? "YES" : "NO",true,true));
138         retval.add(new ApprovalDataText("SENDNOTIFICATION",newuserdata.getSendNotification() ? "YES" : "NO",true,true));
139         retval.add(new ApprovalDataText("STATUS",(String JavaDoc) UserDataConstants.STATUS_TEXT.get(new Integer JavaDoc(newuserdata.getStatus())),true,true));
140         return retval;
141     }
142     
143     private ApprovalDataText getTextWithNoValueString(String JavaDoc header, String JavaDoc data){
144         if(data==null || data.equals("")){
145             return new ApprovalDataText(header,"NOVALUE",true,true);
146         }
147             
148         return new ApprovalDataText(header,data,true,false);
149     }
150
151     public List JavaDoc getOldRequestDataAsText(Admin admin) {
152         ArrayList JavaDoc retval = new ArrayList JavaDoc();
153         retval.add(new ApprovalDataText("USERNAME",orguserdata.getUsername(),true,false));
154         retval.add(new ApprovalDataText("PASSWORD","NOTSHOWN",true,true));
155         retval.add(new ApprovalDataText("SUBJECTDN",CertTools.stringToBCDNString(orguserdata.getDN()),true,false));
156         retval.add(getTextWithNoValueString("SUBJECTALTNAME",orguserdata.getSubjectAltName()));
157         retval.add(getTextWithNoValueString("SUBJECTDIRATTRIBUTES",orguserdata.getExtendedinformation().getSubjectDirectoryAttributes()));
158         retval.add(getTextWithNoValueString("EMAIL",orguserdata.getEmail()));
159         retval.add(new ApprovalDataText("CA",getCAName(admin, orguserdata.getCAId()),true,false));
160         retval.add(new ApprovalDataText("ENDENTITYPROFILE",getEndEntityProfileName(admin,orguserdata.getEndEntityProfileId()),true,false));
161         retval.add(new ApprovalDataText("CERTIFICATEPROFILE",getCertificateProfileName(admin,orguserdata.getCertificateProfileId()),true,false));
162         retval.add(getTokenName(admin,orguserdata.getTokenType()));
163         retval.add(getTextWithNoValueString("HARDTOKENISSUERALIAS",getHardTokenIssuerName(admin,orguserdata.getHardTokenIssuerId())));
164         retval.add(new ApprovalDataText("ADMINISTRATOR",orguserdata.getAdministrator() ? "YES" : "NO",true,true));
165         retval.add(new ApprovalDataText("KEYRECOVERABLE",orguserdata.getKeyRecoverable() ? "YES" : "NO",true,true));
166         retval.add(new ApprovalDataText("SENDNOTIFICATION",orguserdata.getSendNotification() ? "YES" : "NO",true,true));
167         retval.add(new ApprovalDataText("STATUS",(String JavaDoc) UserDataConstants.STATUS_TEXT.get(new Integer JavaDoc(orguserdata.getStatus())),true,true));
168         return retval;
169     }
170
171
172
173     public boolean isExecutable() {
174         return true;
175     }
176     
177     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
178         super.writeExternal(out);
179         out.writeInt(LATEST_VERSION);
180         out.writeObject(newuserdata);
181         out.writeBoolean(clearpwd);
182         out.writeObject(orguserdata);
183     }
184
185     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
186         super.readExternal(in);
187         int version = in.readInt();
188         if(version == 1){
189             newuserdata = (UserDataVO) in.readObject();
190             clearpwd = in.readBoolean();
191             orguserdata = (UserDataVO) in.readObject();
192         }
193
194     }
195
196 }
197
Popular Tags