List of usage examples for javax.xml.namespace QName equals
public final boolean equals(Object objectToTest)
Test this QName
for equality with another Object
.
If the Object
to be tested is not a QName
or is null
, then this method returns false
.
Two QName
s are considered equal if and only if both the Namespace URI and local part are equal.
From source file:org.apereo.portal.portlet.rendering.PortletEventCoordinatationService.java
protected EventDefinition getEventDefintion(IPortletWindow portletWindow, QName name) { PortletApplicationDefinition appDD = portletWindow.getPlutoPortletWindow().getPortletDefinition() .getApplication();//ww w .j ava 2 s .c o m for (EventDefinition def : appDD.getEventDefinitions()) { if (def.getQName() != null) { if (def.getQName().equals(name)) return def; } else { QName tmp = new QName(appDD.getDefaultNamespace(), def.getName()); if (tmp.equals(name)) return def; } } throw new IllegalStateException(); }
From source file:org.apereo.portal.portlet.rendering.PortletEventCoordinatationService.java
protected Set<QName> getAllAliases(QName eventName, PortletApplicationDefinition portletApplicationDefinition) { final List<? extends EventDefinition> eventDefinitions = portletApplicationDefinition.getEventDefinitions(); if (eventDefinitions == null || eventDefinitions.isEmpty()) { return Collections.emptySet(); }/*from ww w . j a v a 2 s .c o m*/ final String defaultNamespace = portletApplicationDefinition.getDefaultNamespace(); for (final EventDefinition eventDefinition : eventDefinitions) { final QName defQName = eventDefinition.getQualifiedName(defaultNamespace); if (defQName != null && defQName.equals(eventName)) { final List<QName> aliases = eventDefinition.getAliases(); if (aliases == null || aliases.isEmpty()) { return Collections.emptySet(); } return new LinkedHashSet<QName>(aliases); } } return Collections.emptySet(); }
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 w w w .j a v a 2 s .co m*/ //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.codice.ddf.security.interceptor.AnonymousInterceptor.java
@Override public void handleMessage(SoapMessage message) throws Fault { if (anonymousAccessDenied) { LOGGER.debug("AnonymousAccess not enabled - no message checking performed."); return;//from w w w . j a v a 2s . c o m } if (message != null) { SoapVersion version = message.getVersion(); SOAPMessage soapMessage = getSOAPMessage(message); SOAPFactory soapFactory = null; SOAPElement securityHeader = null; //Check if security header exists; if not, execute AnonymousInterceptor logic String actor = (String) getOption(WSHandlerConstants.ACTOR); if (actor == null) { actor = (String) message.getContextualProperty(SecurityConstants.ACTOR); } Element existingSecurityHeader = null; try { LOGGER.debug("Checking for security header."); existingSecurityHeader = WSSecurityUtil.getSecurityHeader(soapMessage.getSOAPPart(), actor); } catch (WSSecurityException e1) { LOGGER.debug("Issue with getting security header", e1); } if (existingSecurityHeader == null) { LOGGER.debug("Current request has no security header, continuing with AnonymousInterceptor"); AssertionInfoMap assertionInfoMap = message.get(AssertionInfoMap.class); // if there is a policy we need to follow or we are ignoring policies, prepare the SOAP message if ((assertionInfoMap != null) || overrideEndpointPolicies) { RequestData reqData = new CXFRequestData(); WSSConfig config = (WSSConfig) message.getContextualProperty(WSSConfig.class.getName()); WSSecurityEngine engine = null; if (config != null) { engine = new WSSecurityEngine(); engine.setWssConfig(config); } if (engine == null) { engine = new WSSecurityEngine(); config = engine.getWssConfig(); } reqData.setWssConfig(config); try { soapFactory = SOAPFactory.newInstance(); } catch (SOAPException e) { LOGGER.error("Could not create a SOAPFactory.", e); return; // can't add anything if we can't create it } if (soapFactory != null) { //Create security header try { securityHeader = soapFactory.createElement(WSConstants.WSSE_LN, WSConstants.WSSE_PREFIX, WSConstants.WSSE_NS); securityHeader.addAttribute( new QName(WSConstants.URI_SOAP11_ENV, WSConstants.ATTR_MUST_UNDERSTAND), "1"); } catch (SOAPException e) { LOGGER.error("Unable to create security header for anonymous user.", e); return; // can't create the security - just return } } } EffectivePolicy effectivePolicy = message.get(EffectivePolicy.class); Exchange exchange = message.getExchange(); BindingOperationInfo bindingOperationInfo = exchange.getBindingOperationInfo(); Endpoint endpoint = exchange.get(Endpoint.class); if (null == endpoint) { return; } EndpointInfo endpointInfo = endpoint.getEndpointInfo(); Bus bus = exchange.get(Bus.class); PolicyEngine policyEngine = bus.getExtension(PolicyEngine.class); if (effectivePolicy == null) { if (policyEngine != null) { if (MessageUtils.isRequestor(message)) { effectivePolicy = policyEngine.getEffectiveClientResponsePolicy(endpointInfo, bindingOperationInfo, message); } else { effectivePolicy = policyEngine.getEffectiveServerRequestPolicy(endpointInfo, bindingOperationInfo, message); } } } //Auto analyze endpoint policies //Token Assertions String tokenAssertion = null; String tokenType = null; //Security Binding Assertions boolean layoutLax = false; boolean layoutStrict = false; boolean layoutLaxTimestampFirst = false; boolean layoutLaxTimestampLast = false; boolean requireClientCert = false; QName secBindingAssertion = null; //Supporting Token Assertions QName supportingTokenAssertion = null; boolean policyRequirementsSupported = false; // if there is a policy, try to follow it as closely as possible if (effectivePolicy != null) { Policy policy = effectivePolicy.getPolicy(); if (policy != null) { AssertionInfoMap infoMap = new AssertionInfoMap(policy); Set<Map.Entry<QName, Collection<AssertionInfo>>> entries = infoMap.entrySet(); for (Map.Entry<QName, Collection<AssertionInfo>> entry : entries) { Collection<AssertionInfo> assetInfoList = entry.getValue(); for (AssertionInfo info : assetInfoList) { LOGGER.debug("Assertion Name: {}", info.getAssertion().getName().getLocalPart()); QName qName = info.getAssertion().getName(); StringWriter out = new StringWriter(); XMLStreamWriter writer = null; try { writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out); } catch (XMLStreamException e) { LOGGER.debug("Error with XMLStreamWriter", e); } catch (FactoryConfigurationError e) { LOGGER.debug("Error with FactoryConfiguration", e); } try { if (writer != null) { info.getAssertion().serialize(writer); writer.flush(); } } catch (XMLStreamException e) { LOGGER.debug("Error with XMLStream", e); } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException ignore) { //ignore } } } LOGGER.trace("Assertion XML: {}", out.toString()); String xml = out.toString(); // TODO DDF-1205 complete support for dynamic policy handling if (qName.equals(SP12Constants.TRANSPORT_BINDING)) { secBindingAssertion = qName; } else if (qName.equals(SP12Constants.INCLUDE_TIMESTAMP)) { createIncludeTimestamp(soapFactory, securityHeader); } else if (qName.equals(SP12Constants.LAYOUT)) { String xpathLax = "/Layout/Policy/Lax"; String xpathStrict = "/Layout/Policy/Strict"; String xpathLaxTimestampFirst = "/Layout/Policy/LaxTimestampFirst"; String xpathLaxTimestampLast = "/Layout/Policy/LaxTimestampLast"; } else if (qName.equals(SP12Constants.TRANSPORT_TOKEN)) { } else if (qName.equals(SP12Constants.HTTPS_TOKEN)) { String xpath = "/HttpsToken/Policy/RequireClientCertificate"; } else if (qName.equals(SP12Constants.SIGNED_SUPPORTING_TOKENS)) { String xpath = "/SignedSupportingTokens/Policy//IssuedToken/RequestSecurityTokenTemplate/TokenType"; tokenType = retrieveXmlValue(xml, xpath); supportingTokenAssertion = qName; } else if (qName.equals(SP12Constants.SUPPORTING_TOKENS)) { String xpath = "/SupportingTokens/Policy//IssuedToken/RequestSecurityTokenTemplate/TokenType"; tokenType = retrieveXmlValue(xml, xpath); supportingTokenAssertion = qName; } else if (qName.equals( org.apache.cxf.ws.addressing.policy.MetadataConstants.ADDRESSING_ASSERTION_QNAME)) { createAddressing(message, soapMessage, soapFactory); } else if (qName.equals(SP12Constants.TRUST_13)) { } else if (qName.equals(SP12Constants.ISSUED_TOKEN)) { //Check Token Assertion String xpath = "/IssuedToken/@IncludeToken"; tokenAssertion = retrieveXmlValue(xml, xpath); } else if (qName.equals(SP12Constants.WSS11)) { } } } //Check security and token policies if (tokenAssertion != null && tokenType != null && tokenAssertion.trim().equals(SP12Constants.INCLUDE_ALWAYS_TO_RECIPIENT) && tokenType.trim().equals(TOKEN_SAML20)) { policyRequirementsSupported = true; } else { LOGGER.warn( "AnonymousInterceptor does not support the policies presented by the endpoint."); } } else { if (overrideEndpointPolicies) { LOGGER.debug( "WS Policy is null, override is true - an anonymous assertion will be generated"); } else { LOGGER.warn( "WS Policy is null, override flag is false - no anonymous assertion will be generated."); } } } else { if (overrideEndpointPolicies) { LOGGER.debug( "Effective WS Policy is null, override is true - an anonymous assertion will be generated"); } else { LOGGER.warn( "Effective WS Policy is null, override flag is false - no anonymous assertion will be generated."); } } if (policyRequirementsSupported || overrideEndpointPolicies) { LOGGER.debug("Creating anonymous security token."); if (soapFactory != null) { HttpServletRequest request = (HttpServletRequest) message .get(AbstractHTTPDestination.HTTP_REQUEST); createSecurityToken(version, soapFactory, securityHeader, request.getRemoteAddr()); try { // Add security header to SOAP message soapMessage.getSOAPHeader().addChildElement(securityHeader); } catch (SOAPException e) { LOGGER.error("Issue when adding security header to SOAP message:" + e.getMessage()); } } else { LOGGER.debug("Security Header was null so not creating a SAML Assertion"); } } } else { LOGGER.debug("SOAP message contains security header, no action taken by the AnonymousInterceptor."); } if (LOGGER.isTraceEnabled()) { try { LOGGER.trace("SOAP request after anonymous interceptor: {}", SecurityLogger.getFormattedXml(soapMessage.getSOAPHeader().getParentNode())); } catch (SOAPException e) { //ignore } } } else { LOGGER.error("Incoming SOAP message is null - anonymous interceptor makes no sense."); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswMarshallHelper.java
static void writeFields(HierarchicalStreamWriter writer, MarshallingContext context, MetacardImpl metacard, List<QName> fieldsToWrite) { for (QName qName : fieldsToWrite) { if (qName != null && !qName.equals(CswRecordMetacardType.OWS_BOUNDING_BOX_QNAME)) { String attrName = DefaultCswRecordMap.getDefaultCswRecordMap().getDefaultMetacardFieldFor(qName); AttributeDescriptor ad = metacard.getMetacardType().getAttributeDescriptor(attrName); if (ad == null) { ad = new AttributeDescriptorImpl(attrName, false, false, false, false, BasicTypes.STRING_TYPE); }//from w ww .ja v a 2 s . com writeAttribute(writer, context, metacard, ad, qName); } } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.impl.CswRecordConverter.java
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { if (source == null || !(source instanceof Metacard)) { LOGGER.warn("Failed to marshal Metacard: {}", source); return;/*from www. ja v a 2 s . c o m*/ } Metacard metacard = (Metacard) source; if (fieldsToWrite != null) { for (QName qName : fieldsToWrite) { if (qName != null && !qName.equals(CswRecordMetacardType.OWS_BOUNDING_BOX_QNAME)) { String attrName = DefaultCswRecordMap.getDefaultCswRecordMap() .getDefaultMetacardFieldFor(qName); AttributeDescriptor ad = metacard.getMetacardType().getAttributeDescriptor(attrName); if (ad == null) { ad = new AttributeDescriptorImpl(attrName, false, false, false, false, BasicTypes.STRING_TYPE); } writeAttribute(writer, context, metacard, ad, qName); } } } else { // write all fields Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors(); for (AttributeDescriptor ad : attrDescs) { List<QName> qNames = DefaultCswRecordMap.getDefaultCswRecordMap().getCswFieldsFor(ad.getName()); for (QName qName : qNames) { writeAttribute(writer, context, metacard, ad, qName); } } } if ((fieldsToWrite == null || fieldsToWrite.contains(CswRecordMetacardType.CSW_TEMPORAL_QNAME)) && metacard.getEffectiveDate() != null && metacard.getExpirationDate() != null) { StringBuilder sb = new StringBuilder(); sb.append(ISODateTimeFormat.dateTime().print(((Date) metacard.getEffectiveDate()).getTime())) .append(" to ") .append(ISODateTimeFormat.dateTime().print(((Date) metacard.getExpirationDate()).getTime())); writeValue(writer, context, null, CswRecordMetacardType.CSW_TEMPORAL_QNAME, sb.toString()); } if ((fieldsToWrite == null || fieldsToWrite.contains(CswRecordMetacardType.CSW_SOURCE_QNAME)) && metacard.getSourceId() != null) { writeValue(writer, context, null, CswRecordMetacardType.CSW_SOURCE_QNAME, metacard.getSourceId()); } if (fieldsToWrite == null || fieldsToWrite.contains(CswRecordMetacardType.OWS_BOUNDING_BOX_QNAME)) { writeBoundingBox(writer, context, metacard); } }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswEndpoint.java
/** * Creates an Operation object for the OperationsMetadata section TODO: We currently don't use * the constraint or metadata elements, those can be added in as desired * * @param name The name of the operation * @param types The request types supported (GET/POST) * @return The constructed Operation object *///from www. j av a 2s .c om private Operation buildOperation(String name, List<QName> types) { Operation op = new Operation(); op.setName(name); ArrayList<DCP> dcpList = new ArrayList<>(); DCP dcp = new DCP(); HTTP http = new HTTP(); for (QName type : types) { RequestMethodType rmt = new RequestMethodType(); rmt.setHref(uri.getBaseUri().toASCIIString()); JAXBElement<RequestMethodType> requestElement = new JAXBElement<>(type, RequestMethodType.class, rmt); if (type.equals(CswConstants.POST)) { requestElement.getValue().getConstraint() .add(createDomainType(CswConstants.POST_ENCODING, CswConstants.XML)); } http.getGetOrPost().add(requestElement); } dcp.setHTTP(http); dcpList.add(dcp); op.setDCP(dcpList); return op; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.Validator.java
/** * Verifies that if types are passed, then they exist. * * @param types List of QNames representing types * @param version the specified version of the types *//*from www.ja v a 2 s . com*/ void validateTypes(List<QName> types, String version) throws CswException { if (types == null || types.size() == 0) { // No type at all is valid, just return return; } if (types.size() == 1) { QName typeName = types.get(0); QName cswOutputSchema = new QName(CswConstants.CSW_OUTPUT_SCHEMA, CswConstants.CSW_RECORD_LOCAL_NAME); QName gmdOutputSchema = new QName(GmdMetacardType.GMD_NAMESPACE, GmdMetacardType.GMD_LOCAL_NAME); QName ebrimOutputSchema = new QName(CswConstants.EBRIM_SCHEMA, CswConstants.EBRIM_RECORD_LOCAL_NAME); if (!typeName.equals(cswOutputSchema) && !typeName.equals(gmdOutputSchema) && !typeName.equals(ebrimOutputSchema)) { throw createUnknownTypeException(types.get(0).toString()); } } }
From source file:org.deegree.feature.persistence.shape.ShapeFeatureStore.java
@Override public FeatureInputStream query(Query query) throws FilterEvaluationException, FeatureStoreException { if (query.getTypeNames() == null || query.getTypeNames().length > 1) { String msg = "Only queries with exactly one or zero type name(s) are supported."; throw new UnsupportedOperationException(msg); }//from ww w . j av a2s. co m HashSet<Integer> idFilterNums = null; if (query.getFilter() instanceof IdFilter) { idFilterNums = new HashSet<Integer>(); IdFilter f = (IdFilter) query.getFilter(); List<ResourceId> ids = f.getSelectedIds(); for (ResourceId id : ids) { if (id.getRid().startsWith(fidPrefix)) { String[] ss = id.getRid().split("_"); idFilterNums.add(Integer.valueOf(ss[1])); } } } if (query.getTypeNames().length == 0 && !(query.getFilter() instanceof IdFilter) || idFilterNums != null && idFilterNums.isEmpty()) { return new MemoryFeatureInputStream(new GenericFeatureCollection()); } if (query.getTypeNames().length > 0) { QName featureType = query.getTypeNames()[0].getFeatureTypeName(); if (featureType != null && !featureType.equals(ft.getName())) { // or null? return new MemoryFeatureInputStream(new GenericFeatureCollection()); } } checkForUpdate(); if (!available) { return null; } Filter filter = query.getFilter(); Pair<Filter, Envelope> filterPair = splitOffBBoxConstraint(filter); List<Pair<Integer, Long>> recNumsAndPos = new LinkedList<Pair<Integer, Long>>(); Envelope bbox = getTransformedEnvelope(query.getPrefilterBBoxEnvelope()); if (bbox == null) { getEnvelope(null); } boolean queryIndex = filterPair.first == null || !generateAlphanumericIndexes; Pair<Filter, SortProperty[]> p = queryIndex ? null : dbfIndex.query(recNumsAndPos, filterPair.first, query.getSortProperties()); HashSet<Integer> recNums = new HashSet<Integer>(unzipPair(recNumsAndPos).first); if (idFilterNums != null) { recNums.addAll(idFilterNums); } recNumsAndPos = shp.query(bbox, filter == null || p == null ? null : recNums); LOG.debug("{} records matching after BBOX filtering", recNumsAndPos.size()); // don't forget about filters if dbf index could not be queried if (p == null) { p = new Pair<Filter, SortProperty[]>(filterPair.first, query.getSortProperties()); } FeatureInputStream rs = new IteratorFeatureInputStream(new FeatureIterator(recNumsAndPos.iterator())); if (p.first != null) { LOG.debug("Applying in-memory filtering."); rs = new FilteredFeatureInputStream(rs, p.first); } if (p.second != null && p.second.length > 0) { LOG.debug("Applying in-memory sorting."); rs = new MemoryFeatureInputStream(Features.sortFc(rs.toCollection(), p.second)); } return rs; }
From source file:org.deegree.services.wfs.query.QueryAnalyzer.java
/** * Repairs a {@link ValueReference} that contains the local name of a {@link FeatureType}'s property or a prefixed * name, but without a correct namespace binding. * <p>//from w w w.j av a2 s .c o m * This types of propertynames especially occurs in WFS 1.0.0 requests. * </p> * * @param propName * property name to be repaired, must be "simple", i.e. contain only of a QName * @param typeName * feature type specification from the query, must not be <code>null</code> * @throws OWSException * if no match could be found */ private void repairSimpleUnqualified(ValueReference propName, TypeName typeName) throws OWSException { FeatureType ft = service.lookupFeatureType(typeName.getFeatureTypeName()); List<QName> propNames = new ArrayList<QName>(); // TODO which GML version for (PropertyType pt : ft.getPropertyDeclarations()) { propNames.add(pt.getName()); } QName match = QNameUtils.findBestMatch(propName.getAsQName(), propNames); if (match == null) { String msg = "Specified PropertyName '" + propName.getAsText() + "' does not exist for feature type '" + ft.getName() + "'."; throw new OWSException(msg, INVALID_PARAMETER_VALUE, "PropertyName"); } if (!match.equals(propName.getAsQName())) { LOG.debug("Repairing unqualified PropertyName: " + QNameUtils.toString(propName.getAsQName()) + " -> " + QNameUtils.toString(match)); // vague match String text = match.getLocalPart(); if (!match.getPrefix().equals(DEFAULT_NS_PREFIX)) { text = match.getPrefix() + ":" + match.getLocalPart(); } NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace(match.getPrefix(), match.getNamespaceURI()); propName.set(text, nsContext); } }