public IRequestMessage  makeRequest(Admin admin, int caid, Collection cachain, boolean setstatustowaiting) throws CADoesntExistsException, AuthorizationDeniedException{
public IRequestMessage  makeRequest(Admin admin, int caid, Collection cachain, boolean setstatustowaiting) throws CADoesntExistsException, AuthorizationDeniedException, CertPathValidatorException{
    public IRequestMessage  makeRequest(Admin admin, int caid, Collection cachain, boolean setstatustowaiting) throws CADoesntExistsException, AuthorizationDeniedException{    	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();            		// if issuer is insystem CA or selfsigned, then generate new certificate.		  if(ca.getSignedBy() == CAInfo.SIGNEDBYEXTERNALCA){		     // set certificate chain		    ArrayList cacerts = new ArrayList();		    cacerts.addAll(cachain);						CertPath cp = CertificateFactory.getInstance("X.509","BC").generateCertPath( cacerts );					    ca.setRequestCertificateChain(cp.getCertificates());		    		    		   		     // 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().getPublicSignKey(), attributes, ca.getCAToken().getPrivateSignKey());					   		     // 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(Exception e){			getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when creating certificate request");		   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