getSignSession().publishCACertificate(admin, ca.getCertificateChain(), ca.getCRLPublishers(), SecConst.CERTTYPE_SUBCA);
getSignSession().publishCACertificate(admin, ca.getCertificateChain(), ca.getCRLPublishers(), CertificateDataBean.CERTTYPE_SUBCA);
    public IResponseMessage processRequest(Admin admin, CAInfo cainfo, IRequestMessage requestmessage)    throws CAExistsException, CADoesntExistsException, AuthorizationDeniedException, CATokenOfflineException {    	CA ca = null;    	Collection certchain = null;    	Collection certpublishers = null;    	IResponseMessage returnval = null;    	// check authorization    	try{    		getAuthorizationSession().isAuthorizedNoLog(admin,"/super_administrator");    	}catch(AuthorizationDeniedException e){    		getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Administrator isn't authorized to process CA",e);    		throw new AuthorizationDeniedException("Not authorized to process a CA  ");    	}    	// Check that CA doesn't already exists    	try{    		int caid = cainfo.getCAId();    		if(caid >=0 && caid <= CAInfo.SPECIALCAIDBORDER){    			getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when processing CA " + cainfo.getName() +". CA already exists.");    			throw new CAExistsException("Error when processing CA " + cainfo.getName() +". CA already exists.");    		}    		cadatahome.findByPrimaryKey(new Integer(caid));    		getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when processing CA " + cainfo.getName() +". CA already exists.");    		throw new CAExistsException("Error when processing CA " + cainfo.getName() +". CA already exists.");    	}catch(javax.ejb.FinderException fe) {}    	try{    		cadatahome.findByName(cainfo.getName());    		getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when processing CA " + cainfo.getName() +". CA already exists.");    		throw new CAExistsException("Error when processing CA " + cainfo.getName() +". CA already exists.");    	}catch(javax.ejb.FinderException fe) {}    	//get signing CA    	if(cainfo.getSignedBy() > CAInfo.SPECIALCAIDBORDER || cainfo.getSignedBy() < 0){    		try{    			CADataLocal signcadata = cadatahome.findByPrimaryKey(new Integer(cainfo.getSignedBy()));    			CA signca = signcadata.getCA();    			try{    				// 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);    				}    				// Get public key from request    				PublicKey publickey = requestmessage.getRequestPublicKey();    				// Create cacertificate    				Certificate cacertificate = null;    				if(cainfo instanceof X509CAInfo){    					UserAuthData cadata = new UserAuthData("nobody", null, cainfo.getSubjectDN(), cainfo.getSubjectDN().hashCode(), ((X509CAInfo) cainfo).getSubjectAltName(), null,    							0,  cainfo.getCertificateProfileId(), null);    					CertificateProfile certprofile = getCertificateStoreSession().getCertificateProfile(admin, cainfo.getCertificateProfileId());    					certpublishers = certprofile.getPublisherList();    					cacertificate = signca.generateCertificate(cadata, publickey, -1, cainfo.getValidity(), certprofile);    					returnval = new X509ResponseMessage();    					returnval.setCertificate(cacertificate);    				}    				// Build Certificate Chain    				Collection rootcachain = signca.getCertificateChain();    				certchain = new ArrayList();    				certchain.add(cacertificate);    				certchain.addAll(rootcachain);    				if(cainfo instanceof X509CAInfo){    					X509CAInfo x509cainfo = (X509CAInfo) cainfo;    					// Create X509CA    					ca = new X509CA((X509CAInfo) cainfo);    					ca.setCertificateChain(certchain);    					ca.setCAToken(new NullCAToken());    				}    				// set status to active    				cadatahome.create(cainfo.getSubjectDN(), cainfo.getName(), SecConst.CA_EXTERNAL, ca);    				// Publish CA certificates.    			    getSignSession().publishCACertificate(admin, ca.getCertificateChain(), ca.getCRLPublishers(), SecConst.CERTTYPE_SUBCA);    			}catch(CATokenOfflineException e){    				signca.setStatus(SecConst.CA_OFFLINE);    				getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Couldn't Process  CA.",e);    				throw e;    			}    		}catch(Exception e){    			getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Couldn't Process  CA.",e);    			throw new EJBException(e);    		}    	}    	if(certchain != null)    		getLogSession().log(admin, cainfo.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_INFO_CAEDITED,"CA processed successfully");    	else    		getLogSession().log(admin, admin.getCAId(), LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when processing CA");    	return returnval;    } // processRequest