try{ getAuthorizationSession().isAuthorizedNoLog(admin,"/super_administrator"); }catch(AuthorizationDeniedException e){ getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Not authorized to make certificate request for CA",e); throw new AuthorizationDeniedException("Not authorized to make certificate request for CA with caid = " + caid); }   CADataLocal cadata = null; try{ cadata = this.cadatahome.findByPrimaryKey(new Integer(caid)); CA ca = cadata.getCA();  try{  if(ca.getSignedBy() == CAInfo.SIGNEDBYEXTERNALCA){   ca.setRequestCertificateChain(createCertChain(cachain));    ASN1Set attributes = null;    PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name(ca.getSubjectDN()), ca.getCAToken().getPublicKey(SecConst.CAKEYPURPOSE_CERTSIGN), attributes, ca.getCAToken().getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN));   returnval = new PKCS10RequestMessage(req);  if(setstatustowaiting){ cadata.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE); ca.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE); }  cadata.setCA(ca); }else{  getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error: cannot create certificate request for internal CA"); throw new EJBException(new EjbcaException("Error: cannot create certificate request for internal CA")); } }catch(CATokenOfflineException e) { ca.setStatus(SecConst.CA_OFFLINE); getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e); throw e; } }catch(CertPathValidatorException e) { getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e); throw e;
try{ getAuthorizationSession().isAuthorizedNoLog(admin,"/super_administrator"); }catch(AuthorizationDeniedException e){ getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Not authorized to make certificate request for CA",e); throw new AuthorizationDeniedException("Not authorized to make certificate request for CA with caid = " + caid); }   CADataLocal cadata = null; try{ cadata = this.cadatahome.findByPrimaryKey(new Integer(caid)); CA ca = cadata.getCA();  try{  if(ca.getSignedBy() == CAInfo.SIGNEDBYEXTERNALCA){   ca.setRequestCertificateChain(createCertChain(cachain));    ASN1Set attributes = null;    PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA", CertTools.stringToBcX509Name(ca.getSubjectDN()), ca.getCAToken().getPublicKey(SecConst.CAKEYPURPOSE_CERTSIGN), attributes, ca.getCAToken().getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN));   returnval = new PKCS10RequestMessage(req);  if(setstatustowaiting){ cadata.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE); ca.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE); }  cadata.setCA(ca); }else{  getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error: cannot create certificate request for internal CA"); throw new EJBException(new EjbcaException("Error: cannot create certificate request for internal CA")); } }catch(CATokenOfflineException e) { ca.setStatus(SecConst.CA_OFFLINE); getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e); throw e; } }catch(CATokenOfflineException e) { throw e; }catch(CertPathValidatorException e) { getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e); throw e;
    public IRequestMessage  makeRequest(Admin admin, int caid, Collection cachain, boolean setstatustowaiting) throws CADoesntExistsException, AuthorizationDeniedException, CertPathValidatorException, CATokenOfflineException{    	PKCS10RequestMessage returnval = null;        // Check authorization		try{			getAuthorizationSession().isAuthorizedNoLog(admin,"/super_administrator");		}catch(AuthorizationDeniedException e){			getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Not authorized to make certificate request for CA",e);			throw new AuthorizationDeniedException("Not authorized to make certificate request for CA with caid = " + caid);		}		// Get CA info.		CADataLocal cadata = null;		try{		  cadata = this.cadatahome.findByPrimaryKey(new Integer(caid));		  CA ca = cadata.getCA();		  try{		// if issuer is insystem CA or selfsigned, then generate new certificate.		    if(ca.getSignedBy() == CAInfo.SIGNEDBYEXTERNALCA){			  ca.setRequestCertificateChain(createCertChain(cachain));		       // generate PKCS10CertificateRequest		       // TODO implement PKCS10 Certificate Request arributes.		      ASN1Set attributes = null;			  /* We don't use these uneccesary attributes			      DERConstructedSequence kName = new DERConstructedSequence();				  DERConstructedSet  kSeq = new DERConstructedSet();				  kName.addObject(PKCSObjectIdentifiers.pkcs_9_at_emailAddress);				  kSeq.addObject(new DERIA5String("foo@bar.se"));				  kName.addObject(kSeq);				  req.setAttributes(kName);				 */			  PKCS10CertificationRequest req = new PKCS10CertificationRequest("SHA1WithRSA",					CertTools.stringToBcX509Name(ca.getSubjectDN()), ca.getCAToken().getPublicKey(SecConst.CAKEYPURPOSE_CERTSIGN), attributes, ca.getCAToken().getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN));		       // create PKCS10RequestMessage			  returnval = new PKCS10RequestMessage(req);               // Set statuses.              if(setstatustowaiting){                 cadata.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE);                 ca.setStatus(SecConst.CA_WAITING_CERTIFICATE_RESPONSE);              }              cadata.setCA(ca);		    }else{		       // Cannot create certificate request for internal CA		       getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error: cannot create certificate request for internal CA");		       throw new EJBException(new EjbcaException("Error: cannot create certificate request for internal CA"));		    }		  }catch(CATokenOfflineException e) {		    ca.setStatus(SecConst.CA_OFFLINE);		    getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e);		    throw e;		  }		}catch(CertPathValidatorException e) {		  getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e);		  throw e;        }catch(Exception e){			getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request",e);		   throw new EJBException(e);		}		getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_INFO_CAEDITED,"Certificate request generated successfully.");        return returnval;    } // makeRequest