List of usage examples for javax.xml.bind JAXB marshal
public static void marshal(Object jaxbObject, Result xml)
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * Serializes a JAXB object and prints to stdout * * @param obj//from www .j ava2 s . co m * @return serialized text */ public static String JAXB_ToString(Object obj) { StringWriter sw = new StringWriter(); JAXB.marshal(obj, sw); return (sw.toString()); }
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * * returns the public key of the signing certificate used for a signed * JAXB object./*ww w . ja v a 2 s .c o m*/ * * @param obj * @return null if the item is not signed or if it references a * certificate that is not present in the current keystore * @throws IllegalArgumentException for null input * @throws java.security.cert.CertificateException */ public X509Certificate getSigningCertificatePublicKey(Object obj) throws IllegalArgumentException, CertificateException { DOMResult domResult = new DOMResult(); JAXB.marshal(obj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); //this is our signed node return getSigningCertificatePublicKey(docElement); }
From source file:org.apache.juddi.v3.client.cryptor.DigSigUtil.java
/** * Verifies the signature on an enveloped digital signature on a UDDI * entity, such as a business, service, tmodel or binding template. * <br><Br>/*from w w w.ja va2 s . com*/ * It is expected that either the public key of the signing certificate * is included within the signature keyinfo section OR that sufficient * information is provided in the signature to reference a public key * located within the Trust Store provided<br><Br> Optionally, this * function also validate the signing certificate using the options * provided to the configuration map. * * @param obj an enveloped signed JAXB object * @param OutErrorMessage a human readable error message explaining the * reason for failure * @return true if the validation passes the signature validation test, * and optionally any certificate validation or trust chain validation * @throws IllegalArgumentException for null input */ public boolean verifySignedUddiEntity(Object obj, AtomicReference<String> OutErrorMessage) throws IllegalArgumentException { if (OutErrorMessage == null) { OutErrorMessage = new AtomicReference<String>(); OutErrorMessage.set(""); } if (obj == null) { throw new IllegalArgumentException("obj"); } try { DOMResult domResult = new DOMResult(); JAXB.marshal(obj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); //this is our signed node X509Certificate signingcert = getSigningCertificatePublicKey(docElement); if (signingcert != null) { logger.info( "verifying signature based on X509 public key " + signingcert.getSubjectDN().toString()); if (map.containsKey(CHECK_TIMESTAMPS) && Boolean.parseBoolean(map.getProperty(CHECK_TIMESTAMPS))) { signingcert.checkValidity(); } if (map.containsKey(CHECK_REVOCATION_STATUS_OCSP) && Boolean.parseBoolean(map.getProperty(CHECK_REVOCATION_STATUS_OCSP))) { logger.info("verifying revocation status via OSCP for X509 public key " + signingcert.getSubjectDN().toString()); X500Principal issuerX500Principal = signingcert.getIssuerX500Principal(); logger.info("certificate " + signingcert.getSubjectDN().toString() + " was issued by " + issuerX500Principal.getName() + ", attempting to retrieve certificate"); Security.setProperty("ocsp.enable", "false"); X509Certificate issuer = FindCertByDN(issuerX500Principal); if (issuer == null) { OutErrorMessage.set( "Unable to verify certificate status from OCSP because the issuer of the certificate is not in the trust store. " + OutErrorMessage.get()); //throw new CertificateException("unable to locate the issuers certificate in the trust store"); } else { RevocationStatus check = OCSP.check(signingcert, issuer); logger.info("certificate " + signingcert.getSubjectDN().toString() + " revocation status is " + check.getCertStatus().toString() + " reason " + check.getRevocationReason().toString()); if (check.getCertStatus() != RevocationStatus.CertStatus.GOOD) { OutErrorMessage .set("Certificate status is " + check.getCertStatus().toString() + " reason " + check.getRevocationReason().toString() + "." + OutErrorMessage.get()); //throw new CertificateException("Certificate status is " + check.getCertStatus().toString() + " reason " + check.getRevocationReason().toString()); } } } if (map.containsKey(CHECK_REVOCATION_STATUS_CRL) && Boolean.parseBoolean(map.getProperty(CHECK_REVOCATION_STATUS_CRL))) { logger.info("verifying revokation status via CRL for X509 public key " + signingcert.getSubjectDN().toString()); Security.setProperty("ocsp.enable", "false"); System.setProperty("com.sun.security.enableCRLDP", "true"); X509CertSelector targetConstraints = new X509CertSelector(); targetConstraints.setCertificate(signingcert); PKIXParameters params = new PKIXParameters(GetTrustStore()); params.setRevocationEnabled(true); CertPath certPath = cf.generateCertPath(Arrays.asList(signingcert)); CertPathValidator certPathValidator = CertPathValidator .getInstance(CertPathValidator.getDefaultType()); CertPathValidatorResult result = certPathValidator.validate(certPath, params); try { PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result; logger.info("revokation status via CRL PASSED for X509 public key " + signingcert.getSubjectDN().toString()); } catch (Exception ex) { OutErrorMessage.set("Certificate status is via CRL Failed: " + ex.getMessage() + "." + OutErrorMessage.get()); } } if (map.containsKey(CHECK_TRUST_CHAIN) && Boolean.parseBoolean(map.getProperty(CHECK_TRUST_CHAIN))) { logger.info("verifying trust chain X509 public key " + signingcert.getSubjectDN().toString()); try { PKIXParameters params = new PKIXParameters(GetTrustStore()); params.setRevocationEnabled(false); CertPath certPath = cf.generateCertPath(Arrays.asList(signingcert)); CertPathValidator certPathValidator = CertPathValidator .getInstance(CertPathValidator.getDefaultType()); CertPathValidatorResult result = certPathValidator.validate(certPath, params); PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult) result; TrustAnchor ta = pkixResult.getTrustAnchor(); X509Certificate cert = ta.getTrustedCert(); logger.info( "trust chain validated X509 public key " + signingcert.getSubjectDN().toString()); } catch (Exception ex) { OutErrorMessage.set("Certificate status Trust validation failed: " + ex.getMessage() + "." + OutErrorMessage.get()); } } boolean b = verifySignature(docElement, signingcert.getPublicKey(), OutErrorMessage); if ((OutErrorMessage.get() == null || OutErrorMessage.get().length() == 0) && b) { //no error message and its cryptographically valid return true; } return false; } //last chance validation logger.info( "signature did not have an embedded X509 public key. reverting to user specified certificate"); //cert wasn't included in the signature, revert to some other means KeyStore ks = KeyStore.getInstance(map.getProperty(SIGNATURE_KEYSTORE_FILETYPE)); URL url = Thread.currentThread().getContextClassLoader() .getResource(map.getProperty(SIGNATURE_KEYSTORE_FILE)); if (url == null) { try { url = new File(map.getProperty(SIGNATURE_KEYSTORE_FILE)).toURI().toURL(); } catch (Exception x) { } } if (url == null) { try { url = this.getClass().getClassLoader().getResource(map.getProperty(SIGNATURE_KEYSTORE_FILE)); } catch (Exception x) { } } if (url == null) { logger.error(""); OutErrorMessage.set("The signed entity is signed but does not have a certificate attached and" + "you didn't specify a keystore for me to look it up in. " + OutErrorMessage.get()); return false; } KeyStore.PrivateKeyEntry keyEntry = null; ks.load(url.openStream(), map.getProperty(SIGNATURE_KEYSTORE_FILE_PASSWORD).toCharArray()); if (map.getProperty(SIGNATURE_KEYSTORE_KEY_PASSWORD) == null) { keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(map.getProperty(SIGNATURE_KEYSTORE_KEY_ALIAS), new KeyStore.PasswordProtection( map.getProperty(SIGNATURE_KEYSTORE_FILE_PASSWORD).toCharArray())); } else { keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(map.getProperty(SIGNATURE_KEYSTORE_KEY_ALIAS), new KeyStore.PasswordProtection( map.getProperty(SIGNATURE_KEYSTORE_KEY_PASSWORD).toCharArray())); } Certificate origCert = keyEntry.getCertificate(); if (map.containsKey(CHECK_TIMESTAMPS)) { if (origCert.getPublicKey() instanceof X509Certificate) { X509Certificate x = (X509Certificate) origCert.getPublicKey(); x.checkValidity(); } } PublicKey validatingKey = origCert.getPublicKey(); return verifySignature(docElement, validatingKey, OutErrorMessage); } catch (Exception e) { //throw new RuntimeException(e); logger.error("Error caught validating signature", e); OutErrorMessage.set(e.getMessage()); return false; } }
From source file:org.apache.juddi.v3.tck.JUDDI_300_MultiNodeIntegrationTest.java
public static void testSetupReplicationConfig() { //this only runs if it is JUDDI and Replication is enabled if (!TckPublisher.isReplicationEnabled() || !TckPublisher.isJUDDI()) { logger.info("TCK says that replication is disabled...skipping replication config..."); return;/*from w w w .ja v a 2 s . c o m*/ } try { init(); refreshTokens(); logger.info("fetching current replication config..."); ReplicationConfiguration replicationNode1 = null; try { replicationNode1 = juddiApiServiceNode1.getReplicationNodes(rootNode1Token); } catch (Exception ex) { System.out.println("Error getting replication config"); ex.printStackTrace(); Assert.fail(ex.getMessage()); } //if (replicationNode1.getCommunicationGraph() == null) { replicationNode1.setCommunicationGraph(new CommunicationGraph()); //} replicationNode1.getOperator().clear(); replicationNode1.getSignature().clear(); Operator op = new Operator(); op.setOperatorNodeID("uddi:juddi.apache.org:node1"); op.setSoapReplicationURL(manager.getClientConfig().getUDDINode(CFG_node1_MARY).getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("bob", "en")); op.getContact().get(0).setUseType("admin"); //if (!Contains(replicationNode1.getOperator(), op)) { replicationNode1.getOperator().add(op); //} op = new Operator(); op.setOperatorNodeID("uddi:another.juddi.apache.org:node2"); op.setSoapReplicationURL(manager.getClientConfig().getUDDINode(CFG_node2_SAM).getReplicationUrl()); op.setOperatorStatus(OperatorStatusType.NORMAL); op.getContact().add(new Contact()); op.getContact().get(0).getPersonName().add(new PersonName("mary", "en")); op.getContact().get(0).setUseType("admin"); //if (!Contains(replicationNode1.getOperator(), op)) { replicationNode1.getOperator().add(op); } //if (!replicationNode1.getCommunicationGraph().getNode().contains("uddi:another.juddi.apache.org:node2")) { replicationNode1.getCommunicationGraph().getNode().add("uddi:another.juddi.apache.org:node2"); //} //if (!replicationNode1.getCommunicationGraph().getNode().contains("uddi:juddi.apache.org:node1")) { replicationNode1.getCommunicationGraph().getNode().add("uddi:juddi.apache.org:node1"); //} replicationNode1.setSerialNumber(0L); replicationNode1.setTimeOfConfigurationUpdate(""); replicationNode1.setMaximumTimeToGetChanges(BigInteger.ONE); replicationNode1.setMaximumTimeToSyncRegistry(BigInteger.ONE); if (replicationNode1.getRegistryContact().getContact() == null) { replicationNode1.getRegistryContact().setContact(new Contact()); replicationNode1.getRegistryContact().getContact().getPersonName() .add(new PersonName("unknown", null)); } if (TckCommon.isDebug()) { JAXB.marshal(replicationNode1, System.out); } logger.info(manager.getClientConfig().getConfigurationFile() + " Setting replication config on Node 1...@" + ((BindingProvider) juddiApiServiceNode1) .getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)); logger.info("Setting replication url on Node 1...@" + manager.getClientConfig().getUDDINode(CFG_node1_MARY).getReplicationUrl()); juddiApiServiceNode1.setReplicationNodes(rootNode1Token, replicationNode1); logger.info("Setting replication config on Node 2...@" + ((BindingProvider) juddiApiServiceNode2) .getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY)); logger.info("Setting replication url on Node 2...@" + manager.getClientConfig().getUDDINode(CFG_node2_SAM).getReplicationUrl()); juddiApiServiceNode2.setReplicationNodes(rootNode2Token, replicationNode1); } catch (Exception ex) { TckCommon.PrintMarker(); ex.printStackTrace(); TckCommon.PrintMarker(); } }
From source file:org.apache.juddi.v3.tck.JUDDI_300_MultiNodeIntegrationTest.java
/** * transfer business from mary/node1 to sam/node2, then delete * * @throws Exception/* w w w . ja v a 2s .c o m*/ */ @Test public void testMultiNodeBusinessCustodyTransfer() throws Exception { logger.info("testMultiNodeBusinessCustodyTransfer"); try { Assume.assumeTrue(TckPublisher.isReplicationEnabled() && TckPublisher.isCustodyTransferEnabled()); Assume.assumeTrue(TckPublisher.isJUDDI()); refreshTokens(); testSetupReplicationConfig(); getReplicationStatus(); //create mary's business, node1 BusinessEntity mary = new BusinessEntity(); mary.getName().add(new Name("Mary's biz on " + CFG_node1_MARY, null)); mary.setBusinessServices(new BusinessServices()); BusinessService bs = new BusinessService(); bs.getName().add(new Name("Mary's service", null)); bs.setBindingTemplates(new BindingTemplates()); BindingTemplate bt = new BindingTemplate(); bt.setAccessPoint(new AccessPoint("http://localhost/mary", "wsdlDeployment")); bs.getBindingTemplates().getBindingTemplate().add(bt); mary.getBusinessServices().getBusinessService().add(bs); SaveBusiness sb = new SaveBusiness(); sb.setAuthInfo(maryTokenNode1); sb.getBusinessEntity().add(mary); BusinessDetail saveBusiness = publishMary.saveBusiness(sb); Thread.sleep(5000); //sleep a bit and wait for replication to do it's thing GetOperationalInfo operationalInfo = new GetOperationalInfo(); operationalInfo.setAuthInfo(maryTokenNode1); operationalInfo.getEntityKey().add(saveBusiness.getBusinessEntity().get(0).getBusinessKey()); OperationalInfos beforeNode1 = inquiryMary.getOperationalInfo(operationalInfo); operationalInfo.setAuthInfo(samTokenNode2); OperationalInfos beforeNode2 = null; int timeout = TckPublisher.getSubscriptionTimeout(); while (timeout > 0) { logger.info("Waiting for the update..."); try { GetBusinessDetail gbd = new GetBusinessDetail(); gbd.setAuthInfo(samTokenNode2); gbd.getBusinessKey().add(saveBusiness.getBusinessEntity().get(0).getBusinessKey()); BusinessDetail businessDetail = inquirySamNode2.getBusinessDetail(gbd); if (businessDetail != null && !businessDetail.getBusinessEntity().isEmpty()) { logger.info( "Mary's business exists on Sams node, grabbing the operational info to confirm ownership..."); } beforeNode2 = inquirySamNode2.getOperationalInfo(operationalInfo); break; } catch (Exception ex) { logger.warn(ex.getMessage()); } timeout--; Thread.sleep(1000); } Assert.assertNotNull(beforeNode1); Assert.assertNotNull(beforeNode2); JAXB.marshal(beforeNode1, System.out); JAXB.marshal(beforeNode2, System.out); //confirm we're replicated correctly Assert.assertEquals(beforeNode1.getOperationalInfo().get(0).getAuthorizedName(), beforeNode2.getOperationalInfo().get(0).getAuthorizedName()); Assert.assertEquals(beforeNode1.getOperationalInfo().get(0).getEntityKey(), beforeNode2.getOperationalInfo().get(0).getEntityKey()); Assert.assertEquals(beforeNode1.getOperationalInfo().get(0).getEntityKey(), saveBusiness.getBusinessEntity().get(0).getBusinessKey()); Assert.assertEquals(beforeNode1.getOperationalInfo().get(0).getNodeID(), beforeNode2.getOperationalInfo().get(0).getNodeID()); //get a transfer token, node1 KeyBag kb = new KeyBag(); kb.getKey().add(saveBusiness.getBusinessEntity().get(0).getBusinessKey()); Holder<String> sourceNode = new Holder<String>(); Holder<XMLGregorianCalendar> expiration = new Holder<XMLGregorianCalendar>(); Holder<byte[]> token = new Holder<byte[]>(); custodyMary.getTransferToken(maryTokenNode1, kb, sourceNode, expiration, token); //sam accepts the transfer token, node 2 TransferEntities transferEntities = new TransferEntities(); transferEntities.setAuthInfo(samTokenNode2); transferEntities.setKeyBag(kb); transferEntities.setTransferToken(new TransferToken()); transferEntities.getTransferToken().setExpirationTime(expiration.value); transferEntities.getTransferToken().setNodeID(sourceNode.value); transferEntities.getTransferToken().setOpaqueToken(token.value); custodySam.transferEntities(transferEntities); //stuff happens //Thread.sleep(5000); //confirm the transfer timeout = TckPublisher.getSubscriptionTimeout(); OperationalInfos afterNode1 = null; OperationalInfos afterNode2 = null; while (timeout > 0) { logger.info("Waiting for the update..."); try { operationalInfo.setAuthInfo(maryTokenNode1); //operationalInfo.getEntityKey().add(saveBusiness.getBusinessEntity().get(0).getBusinessKey()); afterNode1 = inquiryMary.getOperationalInfo(operationalInfo); if (afterNode1.getOperationalInfo().get(0).getAuthorizedName() .equals(TckPublisher.getSamPublisherId())) { logger.info("Mary's biz on node 1 is now owned by Sam"); //node 1 is up to date operationalInfo.setAuthInfo(samTokenNode2); afterNode2 = inquirySamNode2.getOperationalInfo(operationalInfo); if (afterNode2.getOperationalInfo().get(0).getAuthorizedName() .equals(TckPublisher.getSamPublisherId())) { //node 2 is up to date logger.info("Mary's biz on node 2 is now owned by Sam"); break; } else { logger.info("Mary's biz on node 2 is still owned by Mary"); } } else { logger.info("Mary's biz on node 1 is still owned by Mary"); } } catch (Exception ex) { logger.warn(ex.getMessage()); } timeout--; Thread.sleep(1000); } //operationalInfo.setAuthInfo(maryTokenNode1); // operationalInfo.getEntityKey().add(saveBusiness.getBusinessEntity().get(0).getBusinessKey()); Assert.assertNotNull(afterNode1); Assert.assertNotNull(afterNode2); if (TckCommon.isDebug()) { JAXB.marshal(afterNode1, System.out); JAXB.marshal(afterNode2, System.out); } //confirm we're replicated correctly Assert.assertEquals(afterNode1.getOperationalInfo().get(0).getAuthorizedName(), afterNode2.getOperationalInfo().get(0).getAuthorizedName()); Assert.assertEquals(afterNode1.getOperationalInfo().get(0).getEntityKey(), afterNode2.getOperationalInfo().get(0).getEntityKey()); Assert.assertEquals(afterNode1.getOperationalInfo().get(0).getEntityKey(), saveBusiness.getBusinessEntity().get(0).getBusinessKey()); Assert.assertEquals(afterNode1.getOperationalInfo().get(0).getNodeID(), afterNode2.getOperationalInfo().get(0).getNodeID()); //confirm that the entity now belongs to sam Assert.assertEquals(afterNode1.getOperationalInfo().get(0).getAuthorizedName(), TckPublisher.getSamPublisherId()); Assert.assertNotEquals(beforeNode1.getOperationalInfo().get(0).getNodeID(), afterNode1.getOperationalInfo().get(0).getNodeID()); } finally { resetTmodels(); resetBusinesses(); } }
From source file:org.apache.juddi.v3.tck.JUDDI_300_MultiNodeIntegrationTest.java
/** * covers business, tmodels and publisher assertions * * @throws Exception/* ww w .java2s . c o m*/ */ @Test // @Ignore public void testReplicationTModelBusinessPublisherAssertionAddDelete() throws Exception { Assume.assumeTrue(TckPublisher.isReplicationEnabled()); Assume.assumeTrue(TckPublisher.isJUDDI()); try { //TckCommon.PrintMarker(); logger.info("testReplicationTModelBusinessPublisherAssertionAddDelete"); resetTmodels(); resetBusinesses(); TModel saveMaryPublisherTmodel = maryTModelNode1.saveMaryPublisherTmodel(maryTokenNode1); samTModelNode2.saveSamSyndicatorTmodel(samTokenNode2); BusinessEntity saveMaryPublisherBusiness = maryBizNode1.saveMaryPublisherBusiness(maryTokenNode1); // TModel saveSamSyndicatorTmodel = samTModelNode2.saveSamSyndicatorTmodel(samTokenNode2); BusinessEntity saveSamSyndicatorBusiness = samBizNode2.saveSamSyndicatorBusiness(samTokenNode2); // getReplicationStatus();//block until synched //confirm mary's tmodel is on the other node GetTModelDetail findTModel = new GetTModelDetail(); findTModel.setAuthInfo(samTokenNode2); findTModel.getTModelKey().add(TckTModel.MARY_PUBLISHER_TMODEL_KEY); TModelDetail tModelDetail = null; int timeout = TckPublisher.getSubscriptionTimeout(); while (timeout > 0) { logger.info("Waiting for the update..."); try { tModelDetail = inquirySamNode2.getTModelDetail(findTModel); break; } catch (Exception ex) { logger.warn(ex.getMessage()); tModelDetail = null; } timeout--; Thread.sleep(1000); } Assert.assertNotNull(tModelDetail); Assert.assertNotNull(tModelDetail.getTModel()); Assert.assertTrue(tModelDetail.getTModel().size() == 1); Assert.assertTrue( tModelDetail.getTModel().get(0).getTModelKey().equals(TckTModel.MARY_PUBLISHER_TMODEL_KEY)); GetBusinessDetail gbd = new GetBusinessDetail(); gbd.setAuthInfo(samTokenNode2); gbd.getBusinessKey().add(TckBusiness.MARY_BUSINESS_KEY); //confirm mary's biz made it too timeout = TckPublisher.getSubscriptionTimeout(); BusinessDetail businessDetail = null; while (timeout > 0) { logger.info("Waiting for the update..."); try { businessDetail = inquirySamNode2.getBusinessDetail(gbd); break; } catch (Exception ex) { logger.warn(ex.getMessage()); businessDetail = null; } timeout--; Thread.sleep(1000); } logger.info("Business replicated"); Assert.assertNotNull(businessDetail); Assert.assertNotNull(businessDetail.getBusinessEntity()); Assert.assertTrue(businessDetail.getBusinessEntity().get(0).getBusinessKey() .equals(TckBusiness.MARY_BUSINESS_KEY)); logger.info(">>> Saving a new publisher assertion on node 2 (sam)"); //setup a publisher assertion PublisherAssertion pa = new PublisherAssertion(); pa.setFromKey(TckBusiness.SAM_BUSINESS_KEY); pa.setToKey(TckBusiness.MARY_BUSINESS_KEY); pa.setKeyedReference(new KeyedReference(UDDIConstants.RELATIONSHIPS, "parent-child", "child")); AddPublisherAssertions apa = new AddPublisherAssertions(); apa.setAuthInfo(samTokenNode2); apa.getPublisherAssertion().add(pa); publishSamNode2.addPublisherAssertions(apa); logger.info("Confirming that the assertion is saved on node2 (sam, origin)"); List<AssertionStatusItem> assertionStatusReport = null; boolean found = false; assertionStatusReport = publishSamNode2.getAssertionStatusReport(samTokenNode2, null); logger.info("Publisher assertions returned: " + assertionStatusReport.size()); for (int x = 0; x < assertionStatusReport.size(); x++) { JAXB.marshal(assertionStatusReport.get(x), System.out); if (assertionStatusReport.get(x).getFromKey().equalsIgnoreCase(TckBusiness.SAM_BUSINESS_KEY) && assertionStatusReport.get(x).getToKey().equalsIgnoreCase(TckBusiness.MARY_BUSINESS_KEY) && assertionStatusReport.get(x).getKeyedReference().getTModelKey() .equalsIgnoreCase(UDDIConstants.RELATIONSHIPS) && assertionStatusReport.get(x).getKeyedReference().getKeyName() .equalsIgnoreCase("parent-child") && assertionStatusReport.get(x).getKeyedReference().getKeyValue() .equalsIgnoreCase("child")) { found = true; break; } } Assert.assertTrue("Assertion not found on Sam's node (2)!!", found); logger.info("Ok it's saved."); //wait for synch timeout = TckPublisher.getSubscriptionTimeout(); logger.info("confirming that the assertion made it to node 1"); found = false; while (timeout > 0) { logger.info("Waiting for the update..."); try { assertionStatusReport = publishMary.getAssertionStatusReport(maryTokenNode1, null); logger.info("Publisher assertions returned: " + assertionStatusReport.size()); for (int x = 0; x < assertionStatusReport.size(); x++) { JAXB.marshal(assertionStatusReport.get(x), System.out); if (assertionStatusReport.get(x).getFromKey().equalsIgnoreCase(TckBusiness.SAM_BUSINESS_KEY) && assertionStatusReport.get(x).getToKey() .equalsIgnoreCase(TckBusiness.MARY_BUSINESS_KEY) && assertionStatusReport.get(x).getKeyedReference().getTModelKey() .equalsIgnoreCase(UDDIConstants.RELATIONSHIPS) && assertionStatusReport.get(x).getKeyedReference().getKeyName() .equalsIgnoreCase("parent-child") && assertionStatusReport.get(x).getKeyedReference().getKeyValue() .equalsIgnoreCase("child")) { found = true; break; } } if (found) { break; } } catch (Exception ex) { logger.warn(ex.getMessage()); Assert.fail("Unexpected failure " + ex.getMessage()); } timeout--; Thread.sleep(1000); } Assert.assertTrue("Assertion wasn't replicated", found); logger.info("Publisher Assertion replicated..."); logger.info("confirming the pa is still on node 2 origin (sam)"); found = false; assertionStatusReport = publishSamNode2.getAssertionStatusReport(samTokenNode2, null); logger.info("Publisher assertions returned: " + assertionStatusReport.size()); for (int x = 0; x < assertionStatusReport.size(); x++) { JAXB.marshal(assertionStatusReport.get(x), System.out); if (assertionStatusReport.get(x).getFromKey().equalsIgnoreCase(TckBusiness.SAM_BUSINESS_KEY) && assertionStatusReport.get(x).getToKey().equalsIgnoreCase(TckBusiness.MARY_BUSINESS_KEY) && assertionStatusReport.get(x).getKeyedReference().getTModelKey() .equalsIgnoreCase(UDDIConstants.RELATIONSHIPS) && assertionStatusReport.get(x).getKeyedReference().getKeyName() .equalsIgnoreCase("parent-child") && assertionStatusReport.get(x).getKeyedReference().getKeyValue() .equalsIgnoreCase("child")) { found = true; break; } } Assert.assertTrue("The PA is not found on node 2(origin), very strange", found); //delete the pa DeletePublisherAssertions dpa = new DeletePublisherAssertions(); dpa.setAuthInfo(samTokenNode2); dpa.getPublisherAssertion().add(pa); String sam = TckCommon.DumpAllBusinesses(samTokenNode2, inquirySamNode2); String mary = TckCommon.DumpAllBusinesses(maryTokenNode1, inquiryMary); logger.info("Publisher Assertion deletion..."); try { publishSamNode2.deletePublisherAssertions(dpa); } catch (Exception ex) { ex.printStackTrace(); logger.info("Sam's businesses " + sam); logger.info("Mary's businesses " + mary); Assert.fail("unable to delete the assertion on sam's node!"); } //wait for synch timeout = TckPublisher.getSubscriptionTimeout(); found = false; while (timeout > 0) { logger.info("Waiting for the update..."); try { assertionStatusReport = publishMary.getAssertionStatusReport(maryTokenNode1, null); found = false; for (int x = 0; x < assertionStatusReport.size(); x++) { JAXB.marshal(assertionStatusReport.get(x), System.out); if (assertionStatusReport.get(x).getFromKey().equalsIgnoreCase(TckBusiness.SAM_BUSINESS_KEY) && assertionStatusReport.get(x).getToKey() .equalsIgnoreCase(TckBusiness.MARY_BUSINESS_KEY) && assertionStatusReport.get(x).getKeyedReference().getTModelKey() .equalsIgnoreCase(UDDIConstants.RELATIONSHIPS) && assertionStatusReport.get(x).getKeyedReference().getKeyName() .equalsIgnoreCase("parent-child") && assertionStatusReport.get(x).getKeyedReference().getKeyValue() .equalsIgnoreCase("child")) //still there { found = true; } } if (!found) { break; } } catch (Exception ex) { logger.warn(ex.getMessage()); Assert.fail("Unexpected failure " + ex.getMessage()); } timeout--; Thread.sleep(1000); } Assert.assertFalse("Assertion deletion wasn't replicated", found); logger.info("Publisher assertion deletion replicated"); //clean up maryBizNode1.deleteMaryPublisherBusiness(maryTokenNode1); maryTModelNode1.deleteMaryPublisherTmodel(maryTokenNode1); //delete both timeout = TckPublisher.getSubscriptionTimeout(); businessDetail = null; while (timeout > 0) { logger.info("Waiting for the update..."); try { businessDetail = inquirySamNode2.getBusinessDetail(gbd); } catch (Exception ex) { logger.warn(ex.getMessage()); businessDetail = null; break; } timeout--; Thread.sleep(1000); } //check node2 for delete biz, should be gone if (businessDetail != null) { Assert.fail(TckBusiness.MARY_BUSINESS_KEY + " wasn't deleted on node 2"); } logger.info("Mary's business deletion was replicated"); tModelDetail = inquirySamNode2.getTModelDetail(findTModel); while (timeout > 0) { logger.info("Waiting for the update..."); try { tModelDetail = inquirySamNode2.getTModelDetail(findTModel); Assert.assertNotNull(tModelDetail); Assert.assertNotNull(tModelDetail.getTModel()); Assert.assertNotNull(tModelDetail.getTModel().get(0)); Assert.assertEquals(tModelDetail.getTModel().get(0).getTModelKey(), TckTModel.MARY_PUBLISHER_TMODEL_KEY); if (tModelDetail.getTModel().get(0).isDeleted()) { break; } } catch (Exception ex) { logger.warn(ex.getMessage()); tModelDetail = null; break; } timeout--; Thread.sleep(1000); } Assert.assertNotNull(tModelDetail); Assert.assertNotNull(tModelDetail.getTModel()); Assert.assertNotNull(tModelDetail.getTModel().get(0)); Assert.assertEquals(tModelDetail.getTModel().get(0).getTModelKey(), TckTModel.MARY_PUBLISHER_TMODEL_KEY); Assert.assertEquals(tModelDetail.getTModel().get(0).isDeleted(), true); logger.info("Mary's tModel was deleted(hidden) replicated"); // TckCommon.PrintMarker(); } finally { samBizNode2.deleteSamSyndicatorBusiness(samTokenNode2); resetTmodels(); resetBusinesses(); } //check node2 for a "hidden" tmodel should be accessible via getDetails }
From source file:org.apache.juddi.v3.tck.JUDDI_300_MultiNodeIntegrationTest.java
private void waitUntilSynched(UDDIReplicationPortType repl) throws Exception { List<ChangeRecordIDType> mary = repl.getHighWaterMarks(); JAXB.marshal(mary.get(0), System.out); Long highmary = mary.get(0).getOriginatingUSN(); Thread.sleep(1000);//from w ww. j a v a 2 s .c o m Long highmary2 = mary.get(0).getOriginatingUSN(); int counter = 0; while (highmary2 > highmary && counter < 90) { //indicates that there are still changes being processed highmary = highmary2; //= mary.get(0).getOriginatingUSN(); Thread.sleep(1000); mary = repl.getHighWaterMarks(); highmary2 = mary.get(0).getOriginatingUSN(); logger.info("Changes are still being processesed...." + highmary2 + ">" + highmary); counter++; } if (counter == 90) { TckCommon.PrintMarker(); logger.info("Changes are still being processed after a " + counter + "sec wait!!"); } }
From source file:org.apache.juddi.v3.tck.TckBusiness.java
private <T> T signJAXBObject(T jaxbObj) { DOMResult domResult = new DOMResult(); JAXB.marshal(jaxbObj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); try {/*from w ww . ja v a 2 s.c om*/ KeyStore ks = KeyStore.getInstance(SIGNATURE_KEYSTORE_TYPE); URL url = Thread.currentThread().getContextClassLoader().getResource(SIGNATURE_KEYSTORE); ks.load(url.openStream(), SIGNATURE_KEYSTORE_PASSWORD.toCharArray()); KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(SIGNATURE_KEYSTORE_ALIAS, new KeyStore.PasswordProtection(SIGNATURE_KEYSTORE_PASSWORD.toCharArray())); PrivateKey privateKey = keyEntry.getPrivateKey(); Certificate origCert = keyEntry.getCertificate(); PublicKey validatingKey = origCert.getPublicKey(); TckSigningUtil.signDOM(docElement, privateKey, origCert); DOMSource domSource = new DOMSource(doc); T result = (T) JAXB.unmarshal(domSource, jaxbObj.getClass()); return result; } catch (Exception e) { throw new RuntimeException("Signature failure due to: " + e.getMessage(), e); } }
From source file:org.apache.juddi.v3.tck.TckBusiness.java
private boolean verifySignedJAXBObject(Object obj) { try {//from w w w .j a va 2s . c o m DOMResult domResult = new DOMResult(); JAXB.marshal(obj, domResult); Document doc = ((Document) domResult.getNode()); Element docElement = doc.getDocumentElement(); KeyStore ks = KeyStore.getInstance(SIGNATURE_KEYSTORE_TYPE); URL url = Thread.currentThread().getContextClassLoader().getResource(SIGNATURE_KEYSTORE); ks.load(url.openStream(), SIGNATURE_KEYSTORE_PASSWORD.toCharArray()); KeyStore.PrivateKeyEntry keyEntry = (KeyStore.PrivateKeyEntry) ks.getEntry(SIGNATURE_KEYSTORE_ALIAS, new KeyStore.PasswordProtection(SIGNATURE_KEYSTORE_PASSWORD.toCharArray())); PrivateKey privateKey = keyEntry.getPrivateKey(); Certificate origCert = keyEntry.getCertificate(); PublicKey validatingKey = origCert.getPublicKey(); return TckSigningUtil.verifySignature(docElement, validatingKey); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.juddi.v3.tck.TckBusiness.java
public BusinessEntity saveBusiness(String authInfo, String businessXML, String businessKey, boolean serialize) { logger.info("attempting to save business " + businessKey + " from " + businessXML); try {/*from ww w .j a va 2s.co m*/ SaveBusiness sb = new SaveBusiness(); sb.setAuthInfo(authInfo); BusinessEntity beIn = (BusinessEntity) EntityCreator.buildFromDoc(businessXML, "org.uddi.api_v3"); if (beIn == null) { throw new Exception("Unload to load source xml document from " + businessXML); } sb.getBusinessEntity().add(beIn); BusinessDetail saveBusiness = publication.saveBusiness(sb); logger.info("Business saved with key " + saveBusiness.getBusinessEntity().get(0).getBusinessKey()); if (serialize) { JAXB.marshal(saveBusiness, System.out); } // Now get the entity and check the values GetBusinessDetail gb = new GetBusinessDetail(); gb.getBusinessKey().add(businessKey); BusinessDetail bd = inquiry.getBusinessDetail(gb); List<BusinessEntity> beOutList = bd.getBusinessEntity(); BusinessEntity beOut = beOutList.get(0); if (serialize) { JAXB.marshal(beOut, new File("target/aftersave.xml")); } assertEquals(beIn.getBusinessKey(), beOut.getBusinessKey()); TckValidator.checkNames(beIn.getName(), beOut.getName()); TckValidator.checkDescriptions(beIn.getDescription(), beOut.getDescription()); TckValidator.checkDiscoveryUrls(beIn.getDiscoveryURLs(), beOut.getDiscoveryURLs()); TckValidator.checkContacts(beIn.getContacts(), beOut.getContacts()); TckValidator.checkCategories(beIn.getCategoryBag(), beOut.getCategoryBag()); TckValidator.checkSignatures(beIn.getSignature(), beOut.getSignature()); return beOut; } catch (Throwable e) { logger.error(e.getMessage(), e); Assert.fail("No exception should be thrown"); } return null; }