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 javax.ejb.CreateException ; 22 import javax.ejb.DuplicateKeyException ; 23 import javax.ejb.EJBException ; 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 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 64 public AddEndEntityApprovalRequest() {} 65 66 67 public AddEndEntityApprovalRequest(UserDataVO userdata, boolean clearpwd, Admin requestAdmin, String 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 e){ 84 throw new ApprovalRequestExecutionException("Error, user already exists", e); 85 } catch (CreateException 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 ("This should never happen",e); 93 } catch (WaitingForApprovalException e) { 94 throw new EJBException ("This should never happen",e); 95 } 96 97 } 98 99 102 public int generateApprovalId() { 103 return new String (getApprovalType() + ";" + userdata.getUsername()).hashCode(); 104 } 105 106 107 public int getApprovalType() { 108 return ApprovalDataVO.APPROVALTYPE_ADDENDENTITY; 109 } 110 111 112 113 public List getNewRequestDataAsText(Admin admin) { 114 ArrayList retval = new ArrayList (); 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 header, String 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 getOldRequestDataAsText(Admin admin) { 140 return null; 141 } 142 143 144 145 public boolean isExecutable() { 146 return true; 147 } 148 149 public void writeExternal(ObjectOutput out) throws IOException { 150 super.writeExternal(out); 151 out.writeInt(LATEST_VERSION); 152 out.writeObject(userdata); 153 out.writeBoolean(clearpwd); 154 } 155 156 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 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 |