List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:org.apache.vxquery.xmlquery.translator.XMLQueryTranslator.java
private ILogicalExpression ce(SequenceType type, Object value) throws SystemException { try {/*from w w w .j a v a 2 s . c o m*/ ItemType it = type.getItemType(); if (it.isAtomicType()) { AtomicType at = (AtomicType) it; byte[] bytes = null; switch (at.getTypeId()) { case BuiltinTypeConstants.XS_BOOLEAN_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_BOOLEAN_TAG); dOut.writeByte(((Boolean) value).booleanValue() ? 1 : 0); break; } case BuiltinTypeConstants.XS_INT_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_INT_TAG); dOut.writeInt(((Number) value).intValue()); break; } case BuiltinTypeConstants.XS_INTEGER_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_INTEGER_TAG); dOut.writeLong(((Number) value).longValue()); break; } case BuiltinTypeConstants.XS_DOUBLE_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_DOUBLE_TAG); dOut.writeDouble(((Number) value).doubleValue()); break; } case BuiltinTypeConstants.XS_STRING_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_STRING_TAG); stringVB.write((CharSequence) value, dOut); break; } case BuiltinTypeConstants.XS_DECIMAL_TYPE_ID: { baaos.reset(); // TODO Remove the creation of the separate byte array. DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable(); doublep.set(new byte[DoublePointable.TYPE_TRAITS.getFixedLength()], 0, DoublePointable.TYPE_TRAITS.getFixedLength()); doublep.setDouble(((Number) value).doubleValue()); CastToDecimalOperation castToDecimal = new CastToDecimalOperation(); castToDecimal.convertDouble(doublep, dOut); break; } case BuiltinTypeConstants.XS_QNAME_TYPE_ID: { QName qname = (QName) value; baaos.reset(); dOut.write((byte) ValueTag.XS_QNAME_TAG); stringVB.write(qname.getNamespaceURI(), dOut); stringVB.write(qname.getPrefix(), dOut); stringVB.write(qname.getLocalPart(), dOut); break; } case BuiltinTypeConstants.XS_UNTYPED_ATOMIC_TYPE_ID: { baaos.reset(); dOut.write((byte) ValueTag.XS_UNTYPED_ATOMIC_TAG); stringVB.write((CharSequence) value, dOut); break; } default: throw new SystemException(ErrorCode.SYSE0001); } bytes = Arrays.copyOf(baaos.getByteArray(), baaos.size()); return new ConstantExpression(new VXQueryConstantValue(type, bytes)); } throw new UnsupportedOperationException(); } catch (IOException e) { throw new SystemException(ErrorCode.SYSE0001, e); } }
From source file:org.apache.ws.axis.security.WSDoAllReceiver.java
/** * Axis calls invoke to handle a message. * <p/>// www . j av a2 s. c om * * @param msgContext message context. * @throws AxisFault */ public void invoke(MessageContext msgContext) throws AxisFault { boolean doDebug = log.isDebugEnabled(); if (doDebug) { log.debug("WSDoAllReceiver: enter invoke() with msg type: " + msgContext.getCurrentMessage().getMessageType()); } long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0; if (tlog.isDebugEnabled()) { t0 = System.currentTimeMillis(); } RequestData reqData = new RequestData(); /* * The overall try, just to have a finally at the end to perform some * housekeeping. */ try { reqData.setMsgContext(msgContext); Vector actions = new Vector(); String action = null; if ((action = (String) getOption(WSHandlerConstants.ACTION)) == null) { action = (String) msgContext.getProperty(WSHandlerConstants.ACTION); } if (action == null) { throw new AxisFault("WSDoAllReceiver: No action defined"); } int doAction = WSSecurityUtil.decodeAction(action, actions); String actor = (String) getOption(WSHandlerConstants.ACTOR); Message sm = msgContext.getCurrentMessage(); Document doc = null; /** * We did not receive anything...Usually happens when we get a * HTTP 202 message (with no content) */ if (sm == null) { return; } try { doc = sm.getSOAPEnvelope().getAsDocument(); if (doDebug) { log.debug("Received SOAP request: "); log.debug(org.apache.axis.utils.XMLUtils.PrettyDocumentToString(doc)); } } catch (Exception ex) { if (doDebug) { log.debug(ex.getMessage(), ex); } throw new AxisFault("WSDoAllReceiver: cannot convert into document", ex); } /* * Check if it's a response and if its a fault. Don't process * faults. */ String msgType = sm.getMessageType(); if (msgType != null && msgType.equals(Message.RESPONSE)) { SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement()); if (WSSecurityUtil.findElement(doc.getDocumentElement(), "Fault", soapConstants.getEnvelopeURI()) != null) { return; } } /* * To check a UsernameToken or to decrypt an encrypted message we * need a password. */ CallbackHandler cbHandler = null; if ((doAction & (WSConstants.ENCR | WSConstants.UT)) != 0) { cbHandler = getPasswordCB(reqData); } /* * Get and check the Signature specific parameters first because * they may be used for encryption too. */ doReceiverAction(doAction, reqData); Vector wsResult = null; if (tlog.isDebugEnabled()) { t1 = System.currentTimeMillis(); } try { wsResult = secEngine.processSecurityHeader(doc, actor, cbHandler, reqData.getSigCrypto(), reqData.getDecCrypto()); } catch (WSSecurityException ex) { if (doDebug) { log.debug(ex.getMessage(), ex); } throw new AxisFault("WSDoAllReceiver: security processing failed", ex); } if (tlog.isDebugEnabled()) { t2 = System.currentTimeMillis(); } if (wsResult == null) { // no security header found if (doAction == WSConstants.NO_SECURITY) { return; } else { throw new AxisFault("WSDoAllReceiver: Request does not contain required Security header"); } } if (reqData.getWssConfig().isEnableSignatureConfirmation() && msgContext.getPastPivot()) { checkSignatureConfirmation(reqData, wsResult); } /* * save the processed-header flags */ ArrayList processedHeaders = new ArrayList(); Iterator iterator = sm.getSOAPEnvelope().getHeaders().iterator(); while (iterator.hasNext()) { org.apache.axis.message.SOAPHeaderElement tempHeader = (org.apache.axis.message.SOAPHeaderElement) iterator .next(); if (tempHeader.isProcessed()) { processedHeaders.add(tempHeader.getQName()); } } /* * If we had some security processing, get the original SOAP part of * Axis' message and replace it with new SOAP part. This new part * may contain decrypted elements. */ SOAPPart sPart = (org.apache.axis.SOAPPart) sm.getSOAPPart(); ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLUtils.outputDOM(doc, os, true); sPart.setCurrentMessage(os.toByteArray(), SOAPPart.FORM_BYTES); if (doDebug) { log.debug("Processed received SOAP request"); log.debug(org.apache.axis.utils.XMLUtils.PrettyDocumentToString(doc)); } if (tlog.isDebugEnabled()) { t3 = System.currentTimeMillis(); } /* * set the original processed-header flags */ iterator = processedHeaders.iterator(); while (iterator.hasNext()) { QName qname = (QName) iterator.next(); Enumeration headersByName = sm.getSOAPEnvelope().getHeadersByName(qname.getNamespaceURI(), qname.getLocalPart()); while (headersByName.hasMoreElements()) { org.apache.axis.message.SOAPHeaderElement tempHeader = (org.apache.axis.message.SOAPHeaderElement) headersByName .nextElement(); tempHeader.setProcessed(true); } } /* * After setting the new current message, probably modified because * of decryption, we need to locate the security header. That is, we * force Axis (with getSOAPEnvelope()) to parse the string, build * the new header. Then we examine, look up the security header and * set the header as processed. * * Please note: find all header elements that contain the same actor * that was given to processSecurityHeader(). Then check if there is * a security header with this actor. */ SOAPHeader sHeader = null; try { sHeader = sm.getSOAPEnvelope().getHeader(); } catch (Exception ex) { if (doDebug) { log.debug(ex.getMessage(), ex); } throw new AxisFault("WSDoAllReceiver: cannot get SOAP header after security processing", ex); } Iterator headers = sHeader.examineHeaderElements(actor); SOAPHeaderElement headerElement = null; while (headers.hasNext()) { org.apache.axis.message.SOAPHeaderElement hE = (org.apache.axis.message.SOAPHeaderElement) headers .next(); if (hE.getLocalName().equals(WSConstants.WSSE_LN) && hE.getNamespaceURI().equals(WSConstants.WSSE_NS)) { headerElement = hE; break; } } ((org.apache.axis.message.SOAPHeaderElement) headerElement).setProcessed(true); /* * Now we can check the certificate used to sign the message. In the * following implementation the certificate is only trusted if * either it itself or the certificate of the issuer is installed in * the keystore. * * Note: the method verifyTrust(X509Certificate) allows custom * implementations with other validation algorithms for subclasses. */ // Extract the signature action result from the action vector WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.SIGN); if (actionResult != null) { X509Certificate returnCert = actionResult.getCertificate(); if (returnCert != null && !verifyTrust(returnCert, reqData)) { throw new AxisFault("WSDoAllReceiver: The certificate used for the signature is not trusted"); } } /* * Perform further checks on the timestamp that was transmitted in * the header. In the following implementation the timestamp is * valid if it was created after (now-ttl), where ttl is set on * server side, not by the client. * * Note: the method verifyTimestamp(Timestamp) allows custom * implementations with other validation algorithms for subclasses. */ // Extract the timestamp action result from the action vector actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.TS); if (actionResult != null) { Timestamp timestamp = actionResult.getTimestamp(); if (timestamp != null && !verifyTimestamp(timestamp, decodeTimeToLive(reqData))) { throw new AxisFault("WSDoAllReceiver: The timestamp could not be validated"); } } /* * now check the security actions: do they match, in right order? */ if (!checkReceiverResults(wsResult, actions)) { throw new AxisFault("WSDoAllReceiver: security processing failed (actions mismatch)"); } /* * All ok up to this point. Now construct and setup the security * result structure. The service may fetch this and check it. */ Vector results = null; if ((results = (Vector) msgContext.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) { results = new Vector(); msgContext.setProperty(WSHandlerConstants.RECV_RESULTS, results); } WSHandlerResult rResult = new WSHandlerResult(actor, wsResult); results.add(0, rResult); if (tlog.isDebugEnabled()) { t4 = System.currentTimeMillis(); tlog.debug("Receive request: total= " + (t4 - t0) + " request preparation= " + (t1 - t0) + " request processing= " + (t2 - t1) + " request to Axis= " + (t3 - t2) + " header, cert verify, timestamp= " + (t4 - t3) + "\n"); } if (doDebug) { log.debug("WSDoAllReceiver: exit invoke()"); } } catch (WSSecurityException e) { if (doDebug) { log.debug(e.getMessage(), e); } throw new AxisFault(e.getMessage(), e); } finally { reqData.clear(); reqData = null; } }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
private static void search(List<Element> list, Element baseElement, QName nodeName, boolean recursive) { if (nodeName == null) { list.add(baseElement);/*from w ww . j a v a 2s. c o m*/ } else { QName qname; if (nodeName.getNamespaceURI().length() > 0) { qname = new QName(baseElement.getNamespaceURI(), baseElement.getLocalName()); } else { qname = new QName(baseElement.getLocalName()); } if (qname.equals(nodeName)) { list.add(baseElement); } } if (recursive) { NodeList nlist = baseElement.getChildNodes(); int len = nlist.getLength(); for (int i = 0; i < len; i++) { Node child = nlist.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { search(list, (Element) child, nodeName, recursive); } } } }
From source file:org.apache.ws.security.message.token.DerivedKeyToken.java
/** * This will create a DerivedKeyToken object with the given DerivedKeyToken element * * @param elem The DerivedKeyToken DOM element * @throws WSSecurityException If the element is not a derived key token *//*from w ww.ja v a 2 s . co m*/ public DerivedKeyToken(Element elem) throws WSSecurityException { log.debug("DerivedKeyToken: created : element constructor"); this.element = elem; QName el = new QName(this.element.getNamespaceURI(), this.element.getLocalName()); if (!(el.equals(ConversationConstants.DERIVED_KEY_TOKEN_QNAME_05_02) || el.equals(ConversationConstants.DERIVED_KEY_TOKEN_QNAME_05_12))) { throw new WSSecurityException(WSSecurityException.INVALID_SECURITY_TOKEN, "badTokenType00", new Object[] { el }); } this.elementSecurityTokenReference = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.SECURITY_TOKEN_REFERENCE_LN, WSConstants.WSSE_NS); this.ns = el.getNamespaceURI(); this.elementProperties = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.PROPERTIES_LN, this.ns); this.elementGeneration = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.GENERATION_LN, this.ns); this.elementOffset = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.OFFSET_LN, this.ns); this.elementLength = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.LENGTH_LN, this.ns); this.elementLabel = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.LABEL_LN, this.ns); this.elementNonce = (Element) WSSecurityUtil.getDirectChild(this.element, ConversationConstants.NONCE_LN, this.ns); }
From source file:org.apache.ws.security.saml.ext.OpenSAMLUtil.java
/** * Method buildSignature ...// www . j a v a2 s. c o m * * @return Signature */ @SuppressWarnings("unchecked") public static Signature buildSignature() { QName qName = Signature.DEFAULT_ELEMENT_NAME; XMLObjectBuilder<Signature> builder = builderFactory.getBuilder(qName); if (builder == null) { LOG.error("Unable to retrieve builder for object QName " + qName); return null; } return (Signature) builder.buildObject(qName.getNamespaceURI(), qName.getLocalPart(), qName.getPrefix()); }
From source file:org.apache.ws.security.util.WSSecurityUtil.java
/** * Return a string for a particular QName, mapping a new prefix if * necessary.//ww w.ja va2s .c o m */ public static String getStringForQName(QName qname, Element e) { String uri = qname.getNamespaceURI(); String prefix = getPrefixNS(uri, e); if (prefix == null) { int i = 1; prefix = "ns" + i; while (getNamespace(prefix, e) != null) { i++; prefix = "ns" + i; } e.setAttributeNS(WSConstants.XMLNS_NS, "xmlns:" + prefix, uri); } return prefix + ":" + qname.getLocalPart(); }
From source file:org.apereo.portal.portlet.registry.PortletWindowRegistryImpl.java
protected StartElement addPortletWindowId(StartElement element, IPortletWindowId portletWindowId) { final Attribute windowIdAttribute = xmlEventFactory.createAttribute(PORTLET_WINDOW_ID_ATTR_NAME, portletWindowId.getStringId()); //Clone the start element to add the new attribute final QName name = element.getName(); final String prefix = name.getPrefix(); final String namespaceURI = name.getNamespaceURI(); final String localPart = name.getLocalPart(); @SuppressWarnings("unchecked") final Iterator<Attribute> attributes = element.getAttributes(); @SuppressWarnings("unchecked") final Iterator<Namespace> namespaces = element.getNamespaces(); final NamespaceContext namespaceContext = element.getNamespaceContext(); //Create a new iterator of the existing attributes + the new window id attribute final Iterator<Attribute> newAttributes = Iterators.concat(attributes, Iterators.forArray(windowIdAttribute)); return xmlEventFactory.createStartElement(prefix, namespaceURI, localPart, newAttributes, namespaces, namespaceContext);/*from w ww.j av a2 s . c o m*/ }
From source file:org.apereo.portal.portlet.rendering.PortletEventCoordinatationService.java
protected boolean supportsEvent(Event event, IPortletDefinitionId portletDefinitionId) { final QName eventName = event.getQName(); //The cache key to use final Tuple<IPortletDefinitionId, QName> key = new Tuple<IPortletDefinitionId, QName>(portletDefinitionId, eventName);/*from www .ja v a2 s . c om*/ //Check in the cache if the portlet definition supports this event final Element element = this.supportedEventCache.get(key); if (element != null) { final Boolean supported = (Boolean) element.getObjectValue(); if (supported != null) { return supported; } } final PortletApplicationDefinition portletApplicationDescriptor = this.portletDefinitionRegistry .getParentPortletApplicationDescriptor(portletDefinitionId); if (portletApplicationDescriptor == null) { return false; } final Set<QName> aliases = this.getAllAliases(eventName, portletApplicationDescriptor); final String defaultNamespace = portletApplicationDescriptor.getDefaultNamespace(); //No support found so far, do more complex namespace matching final PortletDefinition portletDescriptor = this.portletDefinitionRegistry .getParentPortletDescriptor(portletDefinitionId); if (portletDescriptor == null) { return false; } final List<? extends EventDefinitionReference> supportedProcessingEvents = portletDescriptor .getSupportedProcessingEvents(); for (final EventDefinitionReference eventDefinitionReference : supportedProcessingEvents) { final QName qualifiedName = eventDefinitionReference.getQualifiedName(defaultNamespace); if (qualifiedName == null) { continue; } //See if the supported qname and event qname match explicitly //Look for alias names if (qualifiedName.equals(eventName) || aliases.contains(qualifiedName)) { this.supportedEventCache.put(new Element(key, Boolean.TRUE)); return true; } //Look for namespaced events if (StringUtils.isEmpty(qualifiedName.getNamespaceURI())) { final QName namespacedName = new QName(defaultNamespace, qualifiedName.getLocalPart()); if (eventName.equals(namespacedName)) { this.supportedEventCache.put(new Element(key, Boolean.TRUE)); return true; } } } this.supportedEventCache.put(new Element(key, Boolean.FALSE)); return false; }
From source file:org.artificer.repository.hibernate.query.ArtificerToHibernateQueryVisitor.java
/** * @see org.artificer.common.query.xpath.visitors.XPathVisitor#visit(org.artificer.common.query.xpath.ast.ForwardPropertyStep) *//* w ww.ja va2 s. c o m*/ @Override public void visit(ForwardPropertyStep node) { if (node.getPropertyQName() != null) { QName property = node.getPropertyQName(); if (property.getNamespaceURI() == null || "".equals(property.getNamespaceURI())) property = new QName(ArtificerConstants.SRAMP_NS, property.getLocalPart()); if (property.getNamespaceURI().equals(ArtificerConstants.SRAMP_NS)) { if (corePropertyMap.containsKey(property)) { propertyContext = corePropertyMap.get(property); customPropertySubquery = null; } else { // Note: Typically, you'd expect to see a really simple MapJoin w/ key and value predicates. // However, *negation* ("not()") is needed and is tricky when just using a join. Instead, use // an "a1.id in (select a2.id from ArtificerArtifact a2 [map join and predicates)" -- easily negated. customPropertySubquery = query.subquery(ArtificerArtifact.class); From customPropertyFrom = customPropertySubquery.from(ArtificerArtifact.class); Join customPropertyJoin = customPropertyFrom.join("properties"); customPropertySubquery.select(customPropertyFrom.get("id")); customPropertyPredicates = new ArrayList<>(); customPropertyPredicates .add(criteriaBuilder.equal(customPropertyFrom.get("id"), from.get("id"))); customPropertyPredicates .add(criteriaBuilder.equal(customPropertyJoin.get("key"), property.getLocalPart())); customPropertyValuePath = customPropertyJoin.get("value"); predicates.add(criteriaBuilder.exists(customPropertySubquery)); propertyContext = null; } } else { throw new RuntimeException( Messages.i18n.format("XP_INVALID_PROPERTY_NS", property.getNamespaceURI())); } } }
From source file:org.cloudgraph.config.CloudGraphConfig.java
private CloudGraphConfig() { log.debug("initializing..."); try {//w w w .ja v a 2 s. c o m String fileName = EnvProperties.instance().getProperty(PROPERTY_NAME_CLOUDGRAPH_CONFIG); if (fileName == null) fileName = defaultConfigFileName; CloudGraphConfigDataBinding configBinding = new CloudGraphConfigDataBinding( new CloudGraphConfigValidationEventHandler()); config = unmarshalConfig(fileName, configBinding); for (Property prop : config.getProperties()) propertyNameToPropertyMap.put(prop.getName(), prop); for (Table table : config.tables) { TableConfig tableConfig = new TableConfig(table, this); if (this.tableNameToTableMap.get(tableConfig.getName()) != null) throw new CloudGraphConfigurationException( "a table definition already exists for table '" + table.getName() + "'"); this.tableNameToTableMap.put(table.getName(), tableConfig); for (DataGraph graph : table.getDataGraphs()) { DataGraphConfig dataGraphConfig = new DataGraphConfig(graph, tableConfig); QName qname = new QName(graph.getUri(), graph.getType()); PlasmaType configuredType = (PlasmaType) PlasmaTypeHelper.INSTANCE .getType(qname.getNamespaceURI(), qname.getLocalPart()); //if (configuredType.isAbstract()) // throw new CloudGraphConfigurationException("a data graph definition within table '" // + table.getName() + "' has an abstract type (uri/name), " // + graph.getUri() + "#" + graph.getType() + " - use a non abstract type"); if (graphURIToTableMap.get(qname) != null) throw new CloudGraphConfigurationException( "a data graph definition already exists within table '" + table.getName() + "' for type (uri/name), " + graph.getUri() + "#" + graph.getType()); graphURIToTableMap.put(qname, tableConfig); graphURIToGraphMap.put(qname, dataGraphConfig); /* Map<QName, PlasmaType> hierarchy = new HashMap<QName, PlasmaType>(); this.collectTypeHierarchy(configuredType, hierarchy); for (PlasmaType type : hierarchy.values()) { qname = type.getQualifiedName(); if (graphURIToTableMap.get(qname) != null) throw new CloudGraphConfigurationException("a data graph definition already exists within table '" + table.getName() + "' for type (uri/name), " + graph.getUri() + "#" + graph.getType()); graphURIToTableMap.put(qname, tableConfig); graphURIToGraphMap.put(qname, dataGraphConfig); } */ } } } catch (SAXException e) { throw new CloudGraphConfigurationException(e); } catch (JAXBException e) { throw new CloudGraphConfigurationException(e); } }