public void renewCA(Admin admin, int caid, IResponseMessage responsemessage)  throws CADoesntExistsException, AuthorizationDeniedException{
public void renewCA(Admin admin, int caid, IResponseMessage responsemessage)  throws CADoesntExistsException, AuthorizationDeniedException, CertPathValidatorException{
    public void renewCA(Admin admin, int caid, IResponseMessage responsemessage)  throws CADoesntExistsException, AuthorizationDeniedException{        Collection cachain = null;        Certificate cacertificate = 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,"Administrator isn't authorized to renew CA",e);			throw new AuthorizationDeniedException("Not authorized to renew 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){            if(ca.getSignedBy() == CAInfo.SELFSIGNED){			   // create selfsigned certificate			                  if( ca instanceof X509CA){               			     UserAuthData cainfodata = new UserAuthData("nobody", ca.getSubjectDN(), ca.getSubjectDN().hashCode(), ((X509CA) ca).getSubjectAltName(), null, 														  0,  ca.getCertificateProfileId());                                CertificateProfile certprofile = getCertificateStoreSession().getCertificateProfile(admin, ca.getCertificateProfileId());														  				 cacertificate = ca.generateCertificate(cainfodata, ca.getCAToken().getPublicSignKey(),-1, ca.getValidity(), certprofile);               }                                  				   // Build Certificate Chain				cachain = new ArrayList();				cachain.add(cacertificate);                				 				                                      }else{			   // Resign with CA above.          			   if(ca.getSignedBy() > CAInfo.SPECIALCAIDBORDER || ca.getSignedBy() < 0){				   // Create CA signed by other internal CA.				   					 CADataLocal signcadata = cadatahome.findByPrimaryKey(new Integer(ca.getSignedBy()));   					 CA signca = signcadata.getCA();					 // Check validity of signers certificate					 X509Certificate signcert = (X509Certificate) signca.getCACertificate();                  					try{					  signcert.checkValidity();                   					}catch(CertificateExpiredException ce){			        	// Signers Certificate has expired.   				       signcadata.setStatus(SecConst.CA_EXPIRED);  				       getLogSession().log(admin, signcadata.getCAId().intValue(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Signing CA " + signcadata.getSubjectDN() + " has expired",ce);				       throw new EJBException(ce);   			         }catch(CertificateNotYetValidException cve){			  				         getLogSession().log(admin, signcadata.getCAId().intValue(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Signing CA " + signcadata.getSubjectDN() + " is not yet valid",cve);				         throw new EJBException(cve);				    			          }					 // Create cacertificate                 					 				     if( ca instanceof X509CA){               				       UserAuthData cainfodata = new UserAuthData("nobody", ca.getSubjectDN(), ca.getSubjectDN().hashCode(), ((X509CA) ca).getSubjectAltName(), null, 					 									   0,  ca.getCertificateProfileId());               				      CertificateProfile certprofile = getCertificateStoreSession().getCertificateProfile(admin, ca.getCertificateProfileId());														  				      cacertificate = signca.generateCertificate(cainfodata, ca.getCAToken().getPublicSignKey(),-1, ca.getValidity(), certprofile);				    }                                                                  					  // Build Certificate Chain					 Collection rootcachain = signca.getCertificateChain();					 cachain = new ArrayList();					 cachain.add(cacertificate);					 cachain.addAll(rootcachain);			   }   			  			               }                  }else{                          // if external signer then use signed certificate.		  // check the validity of the certificate chain.		      		    if(responsemessage instanceof X509ResponseMessage){			  cacertificate = ((X509ResponseMessage) responsemessage).getCertificate();        		    }else{			  getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error: illegal response message."); 			  throw new EJBException(new EjbcaException("Error: illegal response message."));        			    }            		              			cachain = new ArrayList();		    cachain.add(cacertificate);		    cachain.addAll(ca.getRequestCertificateChain());					    CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters( cachain );		    CertStore store = CertStore.getInstance("Collection", ccsp );								    CertPath cp = CertificateFactory.getInstance("X.509","BC").generateCertPath((ArrayList) cachain);											    Set trust = new HashSet();		    trust.add( new TrustAnchor( (X509Certificate) ((ArrayList)cachain).get(cachain.size()-1), null ) );		    CertPathValidator cpv = CertPathValidator.getInstance("PKIX","BC");		    PKIXParameters param = new PKIXParameters( trust );		    param.addCertStore(store);		    param.setDate( new Date() );		    PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) cpv.validate(cp, param);		    		    		    		   				                                  }           // Set statuses.          if(cacertificate instanceof X509Certificate)            cadata.setExpireTime(((X509Certificate) cacertificate).getNotAfter().getTime());          cadata.setStatus(SecConst.CA_ACTIVE);                       ca.setCertificateChain(cachain);          cadata.setCA(ca);            		}catch(Exception e){			getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Couldn't Renew CA.",e);		   throw new EJBException(e);		}  				getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_INFO_CAEDITED,"CA Renew Successfully.");                                        } // renewCA