List of usage examples for javax.xml.namespace QName QName
public QName(final String namespaceURI, final String localPart)
QName
constructor specifying the Namespace URI and local part.
If the Namespace URI is null
, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .
From source file:com.trsst.client.Client.java
/** * Returns a Feed for the specified feed id, and will attempt to decrypt any * encrypted content with the specified key. * /*from www .j a v a 2 s . c om*/ * @param urn * a feed or entry urn id. * @param decryptionKey * one or more private keys used to attempt to decrypt content. * @return a Feed containing the latest entries for this feed id. */ public Feed pull(String urn, PrivateKey[] decryptionKeys) { Feed feed = pull(urn); if (feed == null) { return null; } Content content; MimeType contentType; for (Entry entry : feed.getEntries()) { content = entry.getContentElement(); if (content != null && (contentType = content.getMimeType()) != null && "application/xenc+xml".equals(contentType.toString())) { // if this message was intended for us, we will be able to // decrypt one of the elements into an AES key to decrypt the // encrypted entry itself QName publicEncryptName = new QName(Common.NS_URI, Common.ENCRYPT); QName publicSignName = new QName(Common.NS_URI, Common.SIGN); QName encryptedDataName = new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"); QName cipherDataName = new QName("http://www.w3.org/2001/04/xmlenc#", "CipherData"); QName cipherValueName = new QName("http://www.w3.org/2001/04/xmlenc#", "CipherValue"); String encodedBytes; byte[] decodedBytes; Element publicKeyElement, cipherData, cipherValue, result; List<Element> encryptedElements = content.getElements(); int lastIndex = encryptedElements.size() - 1; Element element; PublicKey publicKey = null; byte[] decryptedKey = null; publicKeyElement = feed.getFirstChild(publicEncryptName); if (publicKeyElement == null) { // fall back on signing key publicKeyElement = feed.getFirstChild(publicSignName); } if (publicKeyElement != null && publicKeyElement.getText() != null) { try { publicKey = Common.toPublicKeyFromX509(publicKeyElement.getText()); } catch (GeneralSecurityException gse) { log.error("Could not parse public key: " + publicKeyElement); } } if (publicKey != null) { // TODO: if we're the author, we can start loop at // (lastIndex-1) for (int i = 0; i < encryptedElements.size(); i++) { element = encryptedElements.get(i); if (encryptedDataName.equals(element.getQName())) { cipherData = element.getFirstChild(cipherDataName); if (cipherData != null) { cipherValue = cipherData.getFirstChild(cipherValueName); if (cipherValue != null) { encodedBytes = cipherValue.getText(); if (encodedBytes != null) { decodedBytes = new Base64().decode(encodedBytes); if (i != lastIndex) { // if we're not at the last index // (the payload) so we should // attempt // to decrypt this AES key for (PrivateKey decryptionKey : decryptionKeys) { try { decryptedKey = Crypto.decryptKeyWithIES(decodedBytes, entry.getUpdated().getTime(), publicKey, decryptionKey); if (decryptedKey != null) { // success: // skip to lastIndex i = lastIndex - 1; break; } } catch (GeneralSecurityException e) { // key did not fit log.trace("Could not decrypt key: " + entry.getId(), e); } catch (Throwable t) { log.warn( "Error while decrypting key on entry: " + entry.getId(), t); } } } else if (decryptedKey != null) { // if we're at the last index // (the payload) and we have an // AES key: attempt to decrypt try { result = decryptElementAES(decodedBytes, decryptedKey); for (Element ee : encryptedElements) { ee.discard(); } content.setValueElement(result); break; } catch (SecurityException e) { log.error("Key did not decrypt element: " + entry.getId(), e); } catch (Throwable t) { log.warn("Could not decrypt element on entry: " + entry.getId(), t); } } } else { log.warn("No cipher text for entry: " + entry.getId()); } } else { log.warn("No cipher value for entry: " + entry.getId()); } } else { log.warn("No cipher data for entry: " + entry.getId()); } } } } else { log.error("No public key for feed: " + feed.getId()); } } } return feed; }
From source file:org.apache.servicemix.http.HttpWsdlTest.java
protected void testWSDL(final Definition def, int portNumber) throws Exception { // Add a receiver component ActivationSpec asEcho = new ActivationSpec("echo", new EchoComponent() { public Document getServiceDescription(ServiceEndpoint endpoint) { try { Document doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(def); return doc; } catch (Exception e) { throw new RuntimeException(e); }/*from w w w.j av a 2 s . co m*/ } }); asEcho.setEndpoint("myConsumer"); asEcho.setService(new QName("http://test", "MyConsumerService")); container.activateComponent(asEcho); // HTTP Component HttpEndpoint ep = new HttpEndpoint(); ep.setService(new QName("http://test", "MyConsumerService")); ep.setEndpoint("myConsumer"); ep.setRoleAsString("consumer"); ep.setLocationURI("http://localhost:" + portNumber + "/Service"); ep.setSoap(true); HttpComponent http = new HttpComponent(); http.setEndpoints(new HttpEndpoint[] { ep }); container.activateComponent(http, "HttpWsdlTest"); // Start container container.start(); GetMethod get = new GetMethod("http://localhost:" + portNumber + "/Service/?wsdl"); int state = new HttpClient().executeMethod(get); assertEquals(HttpServletResponse.SC_OK, state); Document doc = (Document) new SourceTransformer() .toDOMNode(new StringSource(get.getResponseBodyAsString())); get.releaseConnection(); // Test WSDL WSDLFactory factory = WSDLFactory.newInstance(); WSDLReader reader = factory.newWSDLReader(); Definition definition; definition = reader.readWSDL("http://localhost:" + portNumber + "/Service/?wsdl", doc); assertNotNull(definition); assertNotNull(definition.getImports()); assertEquals(1, definition.getImports().size()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); WSDLFactory.newInstance().newWSDLWriter().writeWSDL(definition, baos); log.info(baos.toString()); }
From source file:org.apache.servicemix.camel.nmr.ws.rm.WSRMTest.java
public void testDecoupled() throws Exception { SpringBusFactory bf = new SpringBusFactory(); bus = bf.createBus("/org/apache/servicemix/camel/ws/rm/decoupled.xml"); BusFactory.setDefaultBus(bus);// w w w. ja v a2 s.co m LoggingInInterceptor in = new LoggingInInterceptor(); bus.getInInterceptors().add(in); bus.getInFaultInterceptors().add(in); LoggingOutInterceptor out = new LoggingOutInterceptor(); bus.getOutInterceptors().add(out); bus.getOutFaultInterceptors().add(out); QName serviceName = new QName("http://cxf.apache.org/greeter_control", "GreeterService"); URL wsdl = new ClassPathResource("/wsdl/greeter_control.wsdl").getURL(); GreeterService gs = new GreeterService(wsdl, serviceName); final Greeter greeter = gs.getGreeterPort(); LOG.fine("Created greeter client."); ConnectionHelper.setKeepAliveConnection(greeter, true); TwowayThread t = new TwowayThread(greeter); t.start(); // allow for partial response to twoway request to arrive long wait = 3000; while (wait > 0) { long start = System.currentTimeMillis(); try { Thread.sleep(wait); } catch (InterruptedException ex) { // ignore } wait -= System.currentTimeMillis() - start; } greeter.greetMeOneWay("oneway"); t.join(); assertEquals("Unexpected response to twoway request", "oneway", t.getResponse()); }
From source file:se.vgregion.portal.patientcontext.SearchController.java
/** * Patient search event./* ww w . ja v a 2s. c om*/ * * @param formBean FormBean from view * @param patientContext PatientContext * @param response ActionResponse for event propagation * @param prefs PortletPreferences */ @ActionMapping("searchEvent") public void searchEvent(@ModelAttribute("searchPatient") SearchPatientFormBean formBean, @ModelAttribute("patientContext") PatientContext patientContext, ActionResponse response, PortletPreferences prefs) { String groupCode = prefs.getValue("group.code", PatientEvent.DEFAULT_GROUP_CODE); // Log patient PatientEvent patient; if (formBean.getHistorySearchText() == null || "0".equals(formBean.getHistorySearchText())) { // validate search patient if (formBean.getSearchText() == null) { return; } patient = new PatientEvent(formBean.getSearchText(), groupCode); } else { patient = new PatientEvent(formBean.getHistorySearchText(), groupCode); } // patient selection changed if (!patient.equals(patientContext.getCurrentPatient())) { // update patient context patientContext.addToHistory(patient); patientContext.setCurrentPatient(patient); } // patient change event QName qname = new QName("http://vgregion.se/patientcontext/events", "pctx.change"); response.setEvent(qname, patient); }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractCredentialBeanDefinitionParser.java
/** * Parses the private key from the credential configuration. * /*w ww. j a v a 2 s . c om*/ * @param configChildren children of the credential element * @param builder credential build */ protected void parsePrivateKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "PrivateKey")); if (keyElems == null || keyElems.isEmpty()) { return; } log.debug("Parsing credential private key"); Element privKeyElem = keyElems.get(0); byte[] encodedKey = getEncodedPrivateKey(DatatypeHelper.safeTrimOrNullString(privKeyElem.getTextContent())); String keyPassword = DatatypeHelper.safeTrimOrNullString(privKeyElem.getAttributeNS(null, "password")); char[] keyPasswordCharArray = null; if (keyPassword != null) { keyPasswordCharArray = keyPassword.toCharArray(); } try { PrivateKey privKey = SecurityHelper.decodePrivateKey(encodedKey, keyPasswordCharArray); builder.addPropertyValue("privateKey", privKey); } catch (KeyException e) { throw new FatalBeanException("Unable to create credential, unable to parse private key", e); } }
From source file:nl.ordina.bag.etl.dao.postgres.BAGMutatiesDAOImpl.java
@Override public void insert(final BAGMutatie mutatie) throws DAOException { try {/*from w w w . j av a 2 s . co m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { try { PreparedStatement ps = connection.prepareStatement("insert into bag_mutatie (" + "id," + "tijdstip_verwerking," + "volgnr_verwerking," + "object_type," + "mutatie_product" + ") values ((select coalesce(max(id),0) + 1 from bag_mutatie),?,?,?,?)"); ps.setTimestamp(1, Utils.toTimestamp(mutatie.getTijdstipVerwerking())); ps.setLong(2, mutatie.getVolgnrVerwerking()); ps.setInt(3, mutatie.getObjectType().ordinal()); ps.setString(4, XMLMessageBuilder.getInstance(MutatieProduct.class) .handle(new JAXBElement<MutatieProduct>(new QName( "http://www.kadaster.nl/schemas/bag-verstrekkingen/extract-producten-lvc/v20090901", "Mutatie-product"), MutatieProduct.class, mutatie.getMutatieProduct()))); return ps; } catch (JAXBException e) { throw new DAOException(e); } } }); } catch (DataAccessException e) { throw new DAOException(e); } }
From source file:edu.internet2.middleware.shibboleth.common.config.relyingparty.RelyingPartyGroupBeanDefinitionParser.java
/** * Parses the security related configuration elements. * //from w w w . j ava 2s . c om * @param configChildren relying party group children * @param builder bean definition builder * @param parserContext current parsing context */ protected void parseSecurityConfiguration(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder, ParserContext parserContext) { List<Element> creds = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Credential")); builder.addPropertyValue("credentials", SpringConfigurationUtils.parseInnerCustomElements(creds, parserContext)); List<Element> engines = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "TrustEngine")); builder.addPropertyValue("trustEngines", SpringConfigurationUtils.parseInnerCustomElements(engines, parserContext)); List<Element> secPols = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "SecurityPolicy")); builder.addPropertyValue("securityPolicies", SpringConfigurationUtils.parseInnerCustomElements(secPols, parserContext)); }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractBasicCredentialBeanDefinitionParser.java
/** * Parses the public key from the credential configuration. * // w w w .j a v a2 s . co m * @param configChildren children of the credential element * @param builder credential build */ protected void parsePublicKey(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> keyElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "PublicKey")); if (keyElems == null || keyElems.isEmpty()) { return; } log.debug("Parsing credential public key"); Element pubKeyElem = keyElems.get(0); byte[] encodedKey = getEncodedPublicKey(DatatypeHelper.safeTrimOrNullString(pubKeyElem.getTextContent())); String keyPassword = DatatypeHelper.safeTrimOrNullString(pubKeyElem.getAttributeNS(null, "password")); char[] keyPasswordCharArray = null; if (keyPassword != null) { keyPasswordCharArray = keyPassword.toCharArray(); } try { PublicKey pubKey = SecurityHelper.decodePublicKey(encodedKey, keyPasswordCharArray); builder.addPropertyValue("publicKey", pubKey); } catch (KeyException e) { throw new FatalBeanException("Unable to create credential, unable to parse public key", e); } }
From source file:com.evolveum.midpoint.schema.util.ReportTypeUtil.java
public static PrismContainerDefinition<ReportConfigurationType> findReportConfigurationDefinition( PrismSchema schema) {/*from w w w . ja v a 2s . co m*/ if (schema == null) { return null; } QName configContainerQName = new QName(schema.getNamespace(), ReportType.F_CONFIGURATION.getLocalPart()); return schema.findContainerDefinitionByElementName(configContainerQName); }
From source file:be.e_contract.mycarenet.ehbox.EHealthBoxConsultationClient.java
/** * Main constructor./*from w ww . j a v a2 s . c o m*/ * * @param location * the URL of the eHealthBox Consultation version 3.0 web * service. */ public EHealthBoxConsultationClient(String location) { EhBoxConsultationService consultationService = EhBoxConsultationServiceFactory.newInstance(); this.ehBoxConsultationPort = consultationService.getEhBoxConsultationPort(); QName consultationPortQName = new QName("urn:be:fgov:ehealth:ehbox:consultation:protocol:v3", "ehBoxConsultationPort"); this.consultationDispatch = consultationService.createDispatch(consultationPortQName, Source.class, Service.Mode.PAYLOAD); this.wsSecuritySOAPHandler = new WSSecuritySOAPHandler(); this.inboundAttachmentsSOAPHandler = new InboundAttachmentsSOAPHandler(); configureBindingProvider((BindingProvider) this.ehBoxConsultationPort, location); configureBindingProvider(this.consultationDispatch, location); this.objectFactory = new ObjectFactory(); }