List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:com.amalto.workbench.providers.datamodel.util.SchemaItemLabelCreator.java
protected String getLableForElement(Element element) { try {/*from w w w . j a va 2 s. c om*/ if (element.getLocalName().equals("documentation")) {//$NON-NLS-1$ return "Documentation: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (element.getLocalName().equals("appinfo")) {//$NON-NLS-1$ String source = element.getAttribute("source");//$NON-NLS-1$ if (source != null) { if (source.startsWith("X_Label_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(8).toLowerCase()) + " Label: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$ return "Foreign Key: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$ return "Foreign Key Info: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$ return "Source System: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$ return "Target System(s): " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$ return Util.iso2lang.get(source.substring(14).toLowerCase()) + " Description: "//$NON-NLS-1$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.equals("X_Write")) {//$NON-NLS-1$ return "Writable By : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$ return "Look Field : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Workflow")) {//$NON-NLS-1$ return "Workflow access : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Hide")) {//$NON-NLS-1$ return "No Access to : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.startsWith("X_Facet")) {//$NON-NLS-1$ return source.substring(2, 7) + "_Msg_" + source.substring(8) + ": "//$NON-NLS-1$//$NON-NLS-2$ + element.getChildNodes().item(0).getNodeValue(); } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$ return source + ": " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_Schematron")) {//$NON-NLS-1$ String pattern = (String) element.getFirstChild().getUserData("pattern_name");//$NON-NLS-1$ if (pattern == null) { Element el = Util.parse(element.getChildNodes().item(0).getNodeValue()) .getDocumentElement(); if (el.getAttributes().getNamedItem("name") != null)//$NON-NLS-1$ pattern = el.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$ } return "Validation Rule: " + (pattern == null ? "" : pattern);//$NON-NLS-1$//$NON-NLS-2$ } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$ return "Foreign Key resolution: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$ return "Foreign Key integrity: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$ return "Foreign Key integrity override: " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$ } if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$ return "Foreign Key Filter: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$ } else { return source + ": " + Util.nodeToString(element);//$NON-NLS-1$ } } else { return Util.nodeToString(element); } } else { return Util.nodeToString(element); } } catch (Exception e) { log.error(e.getMessage(), e); } return "?? " + element.getClass().getName() + " : " + element.toString();//$NON-NLS-1$//$NON-NLS-2$ }
From source file:edu.internet2.middleware.shibboleth.common.config.attribute.filtering.AttributeFilterPolicyBeanDefinitionParser.java
/** {@inheritDoc} */ protected String resolveId(Element configElement, AbstractBeanDefinition beanDefinition, ParserContext parserContext) {/*from w ww. j a v a 2 s. c o m*/ if (!configElement.hasAttributeNS(null, "id")) { log.warn( "AttributeFilterPolicy elements should include an 'id' attribute. This is not currently required but will be in future versions."); } return getQualifiedId(configElement, configElement.getLocalName(), configElement.getAttributeNS(null, "id")); }
From source file:be.agiv.security.client.SecureConversationClient.java
/** * Gives back a secure conversation token using the given R-STS security * token. The R-STS security token should apply to this web service. * /*from w w w .j a v a2s .c o m*/ * @param rStsSecurityToken * the R-STS security token. * @return the secure conversation token to be used to secure the web * service calls. */ public SecurityToken getSecureConversationToken(SecurityToken rStsSecurityToken) { RequestSecurityTokenType requestSecurityToken = this.objectFactory.createRequestSecurityTokenType(); List<Object> requestSecurityTokenContent = requestSecurityToken.getAny(); requestSecurityTokenContent .add(this.objectFactory.createTokenType(WSConstants.SECURE_CONVERSATION_TOKEN_TYPE)); requestSecurityTokenContent.add(this.objectFactory.createRequestType(WSConstants.ISSUE_REQUEST_TYPE)); EntropyType entropy = this.objectFactory.createEntropyType(); requestSecurityTokenContent.add(this.objectFactory.createEntropy(entropy)); BinarySecretType binarySecret = this.objectFactory.createBinarySecretType(); entropy.getAny().add(this.objectFactory.createBinarySecret(binarySecret)); binarySecret.setType(WSConstants.SECRET_TYPE_NONCE); byte[] entropyData = new byte[256 / 8]; this.secureRandom.setSeed(System.currentTimeMillis()); this.secureRandom.nextBytes(entropyData); binarySecret.setValue(entropyData); requestSecurityTokenContent.add(this.objectFactory.createKeySize(256L)); BindingProvider bindingProvider = (BindingProvider) this.port; this.wsAddressingHandler.setAddressing(WSConstants.SEC_CONV_ISSUE_ACTION, this.location); this.wsSecurityHandler.setKey(rStsSecurityToken.getKey(), rStsSecurityToken.getAttachedReference(), rStsSecurityToken.getToken()); RequestSecurityTokenResponseCollectionType requestSecurityTokenResponseCollection = this.port .requestSecurityToken(requestSecurityToken); SecurityToken securityToken = new SecurityToken(); List<RequestSecurityTokenResponseType> requestSecurityTokenResponseList = requestSecurityTokenResponseCollection .getRequestSecurityTokenResponse(); RequestSecurityTokenResponseType requestSecurityTokenResponse = requestSecurityTokenResponseList.get(0); List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny(); for (Object contentObject : requestSecurityTokenResponseContent) { LOG.debug("content object: " + contentObject.getClass().getName()); if (contentObject instanceof Element) { Element contentElement = (Element) contentObject; LOG.debug("element name: " + contentElement.getLocalName()); } if (contentObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) contentObject; QName qname = jaxbElement.getName(); if (WSConstants.ENTROPY_QNAME.equals(qname)) { LOG.debug("trust:Entropy"); EntropyType serverEntropy = (EntropyType) jaxbElement.getValue(); List<Object> entropyContent = serverEntropy.getAny(); for (Object entropyObject : entropyContent) { if (entropyObject instanceof JAXBElement) { JAXBElement entropyElement = (JAXBElement) entropyObject; if (WSConstants.BINARY_SECRET_QNAME.equals(entropyElement.getName())) { BinarySecretType serverBinarySecret = (BinarySecretType) entropyElement.getValue(); byte[] serverSecret = serverBinarySecret.getValue(); P_SHA1 p_SHA1 = new P_SHA1(); byte[] key; try { key = p_SHA1.createKey(entropyData, serverSecret, 0, 256 / 8); } catch (ConversationException e) { LOG.error(e); return null; } LOG.debug("client secret size: " + entropyData.length); LOG.debug("server secret size: " + serverSecret.length); LOG.debug("key size: " + key.length); securityToken.setKey(key); } } } } else if (WSConstants.LIFETIME_QNAME.equals(qname)) { LOG.debug("trust:Lifetime"); LifetimeType lifetime = (LifetimeType) jaxbElement.getValue(); String createdValue = lifetime.getCreated().getValue(); DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTimeParser(); DateTime created = dateTimeFormatter.parseDateTime(createdValue); securityToken.setCreated(created.toDate()); String expiresString = lifetime.getExpires().getValue(); DateTime expires = dateTimeFormatter.parseDateTime(expiresString); securityToken.setExpires(expires.toDate()); } else if (WSConstants.REQUESTED_ATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) { ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue(); String tokenIdentifier = reference.getURI().substring(1); securityToken.setAttachedReference(tokenIdentifier); } } } } else if (WSConstants.REQUESTED_UNATTACHED_REFERENCE_QNAME.equals(qname)) { RequestedReferenceType requestedReference = (RequestedReferenceType) jaxbElement.getValue(); SecurityTokenReferenceType securityTokenReference = requestedReference .getSecurityTokenReference(); List<Object> securityTokenReferenceContent = securityTokenReference.getAny(); for (Object securityTokenReferenceObject : securityTokenReferenceContent) { LOG.debug("SecurityTokenReference object: " + securityTokenReferenceObject.getClass().getName()); if (securityTokenReferenceObject instanceof JAXBElement) { JAXBElement securityTokenReferenceElement = (JAXBElement) securityTokenReferenceObject; LOG.debug("SecurityTokenReference element: " + securityTokenReferenceElement.getName()); if (WSConstants.REFERENCE_QNAME.equals(securityTokenReferenceElement.getName())) { ReferenceType reference = (ReferenceType) securityTokenReferenceElement.getValue(); String tokenIdentifier = reference.getURI(); securityToken.setUnattachedReference(tokenIdentifier); } } } } } } Element requestedSecurityToken = this.wsTrustHandler.getRequestedSecurityToken(); securityToken.setToken(requestedSecurityToken); securityToken.setStsLocation(this.location); securityToken.setRealm(this.location); // what else? securityToken.setParentSecurityToken(rStsSecurityToken); return securityToken; }
From source file:com.twinsoft.convertigo.engine.util.WsReference.java
private static void extractSoapVariables(XmlSchema xmlSchema, List<RequestableHttpVariable> variables, Node node, String longName, boolean isMulti, QName variableType) throws EngineException { if (node == null) return;// www .j a va2 s.c o m int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { Element element = (Element) node; if (element != null) { String elementName = element.getLocalName(); if (longName != null) elementName = longName + "_" + elementName; if (!element.getAttribute("soapenc:arrayType").equals("") && !element.hasChildNodes()) { String avalue = element.getAttribute("soapenc:arrayType"); element.setAttribute("soapenc:arrayType", avalue.replaceAll("\\[\\]", "[1]")); Element child = element.getOwnerDocument().createElement("item"); String atype = avalue.replaceAll("\\[\\]", ""); child.setAttribute("xsi:type", atype); if (atype.startsWith("xsd:")) { String variableName = elementName + "_item"; child.appendChild( element.getOwnerDocument().createTextNode("$(" + variableName.toUpperCase() + ")")); RequestableHttpVariable httpVariable = createHttpVariable(true, variableName, new QName(Constants.URI_2001_SCHEMA_XSD, atype.split(":")[1])); variables.add(httpVariable); } element.appendChild(child); } // extract from attributes NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node child = map.item(i); if (child.getNodeName().equals("soapenc:arrayType")) continue; if (child.getNodeName().equals("xsi:type")) continue; if (child.getNodeName().equals("soapenv:encodingStyle")) continue; String variableName = getVariableName(variables, elementName + "_" + child.getLocalName()); child.setNodeValue("$(" + variableName.toUpperCase() + ")"); RequestableHttpVariable httpVariable = createHttpVariable(false, variableName, Constants.XSD_STRING); variables.add(httpVariable); } // extract from children nodes boolean multi = false; QName qname = Constants.XSD_STRING; NodeList children = element.getChildNodes(); if (children.getLength() > 0) { Node child = element.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.COMMENT_NODE) { String value = child.getNodeValue(); if (value.startsWith("type:")) { String schemaType = child.getNodeValue().substring("type:".length()).trim(); qname = getVariableSchemaType(xmlSchema, schemaType); } if (value.indexOf("repetitions:") != -1) { multi = true; } } else if (child.getNodeType() == Node.TEXT_NODE) { String value = child.getNodeValue().trim(); if (value.equals("?") || !value.equals("")) { String variableName = getVariableName(variables, elementName); child.setNodeValue("$(" + variableName.toUpperCase() + ")"); RequestableHttpVariable httpVariable = createHttpVariable(isMulti, variableName, variableType); variables.add(httpVariable); } } else if (child.getNodeType() == Node.ELEMENT_NODE) { extractSoapVariables(xmlSchema, variables, child, elementName, multi, qname); multi = false; qname = Constants.XSD_STRING; } child = child.getNextSibling(); } } } } }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileC.java
protected void extendSignatureTag(Element signatureEl, Document originalData, SignatureFormat signatureFormat) { super.extendSignatureTag(signatureEl, originalData, signatureFormat); try {/* w ww .j a va2 s.c o m*/ Element qualifyingProperties = XMLUtils.getElement(signatureEl, "./ds:Object/xades:QualifyingProperties"); Element unsignedPropertiesNode = XMLUtils.getElement(qualifyingProperties, "./xades:UnsignedProperties"); Element unsignedSignaturePropertiesNode = XMLUtils.getElement(unsignedPropertiesNode, "./xades:UnsignedSignatureProperties"); List<Node> toRemove = new ArrayList<Node>(); if (unsignedSignaturePropertiesNode != null) { /* If we change a level C of a previous signature, we need to remove other node than level -T. */ NodeList children = unsignedSignaturePropertiesNode.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; if (!"SignatureTimeStamp".equals(e.getLocalName())) { toRemove.add(e); } } } } /* We replace only if we go to level C, XL */ if (toRemove.size() == 0 || signatureFormat == SignatureFormat.XAdES_C || signatureFormat == SignatureFormat.XAdES_XL || signatureFormat == SignatureFormat.XAdES_A) { for (Node e : toRemove) { LOG.warning("Remove element " + e.getLocalName()); unsignedSignaturePropertiesNode.removeChild(e); } UnsignedPropertiesType unsignedPropertiesType = null; if (unsignedPropertiesNode != null) { unsignedPropertiesType = ((JAXBElement<UnsignedPropertiesType>) unmarshaller .unmarshal(unsignedPropertiesNode)).getValue(); } else { unsignedPropertiesType = xadesObjectFactory.createUnsignedPropertiesType(); } extendSignatureTag(signatureEl, unsignedPropertiesType); if (unsignedPropertiesNode != null) { qualifyingProperties.removeChild(unsignedPropertiesNode); } marshaller.marshal(xadesObjectFactory.createUnsignedProperties(unsignedPropertiesType), qualifyingProperties); } } catch (JAXBException e) { throw new RuntimeException("JAXB error: " + e.getMessage(), e); } catch (XPathExpressionException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.vmware.demo.SamlService.java
public String validateSAMLResponse(String samlResponse, String samlCert) throws Exception { String decodedString = ""; try {//ww w . j av a 2s .c o m decodedString = decodeSAMLResponse(samlResponse); InputStream inputStream = new ByteArrayInputStream(decodedString.getBytes("UTF-8")); // Parse XML BasicParserPool parserPoolManager = new BasicParserPool(); parserPoolManager.setNamespaceAware(true); parserPoolManager.setIgnoreElementContentWhitespace(true); Document document = parserPoolManager.parse(inputStream); Element metadataRoot = document.getDocumentElement(); QName qName = new QName(metadataRoot.getNamespaceURI(), metadataRoot.getLocalName(), metadataRoot.getPrefix()); // Unmarshall document Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(qName); Response response = (Response) unmarshaller.unmarshall(metadataRoot); Issuer issuer = response.getIssuer(); logger.info("Parsed response. Issued:" + response.getIssueInstant().toString() + ", issuer: " + issuer.getValue()); java.security.cert.X509Certificate jX509Cert = SamlUtils.parsePemCertificate(samlCert); if (null == jX509Cert) { logger.info("Failed to parse cert. " + samlCert); return ""; } PublicKey publicCert = jX509Cert.getPublicKey(); logger.info("Extracted cert. Cert:" + publicCert); X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicCert.getEncoded()); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey publicKey = keyFactory.generatePublic(publicKeySpec); logger.debug("Key created by provider: " + keyFactory.getProvider().toString()); // Setup validation BasicX509Credential publicCredential = new BasicX509Credential(); publicCredential.setPublicKey(publicKey); SignatureValidator signatureValidator = new SignatureValidator(publicCredential); Signature signature = response.getSignature(); // Validate try { signatureValidator.validate(signature); logger.info("Assertion signature validated."); } catch (ValidationException e) { logger.error("Failed to validate signature of assertion", e); throw e; } // Get decryption key RSAPrivateKey privateKey = null; BasicX509Credential decryptionCredential = new BasicX509Credential(); decryptionCredential.setPrivateKey(privateKey); StaticKeyInfoCredentialResolver skicr = new StaticKeyInfoCredentialResolver(decryptionCredential); // Decrypt assertion Decrypter decrypter = new Decrypter(null, skicr, new InlineEncryptedKeyResolver()); if (response.getEncryptedAssertions().isEmpty()) { logger.info("Nothing to decrypt in assertion."); } else { Assertion decryptedAssertion; try { decryptedAssertion = decrypter.decrypt(response.getEncryptedAssertions().get(0)); logger.info("Assertion decryption succeeded."); } catch (DecryptionException e) { logger.error("Failed to decrypt assertion", e); throw e; } // Extract attributes, log in output List<AttributeStatement> attributeStatements = decryptedAssertion.getAttributeStatements(); for (int i = 0; i < attributeStatements.size(); i++) { List<Attribute> attributes = attributeStatements.get(i).getAttributes(); for (int x = 0; x < attributes.size(); x++) { String strAttributeName = attributes.get(x).getDOM().getAttribute("Name"); List<XMLObject> attributeValues = attributes.get(x).getAttributeValues(); for (int y = 0; y < attributeValues.size(); y++) { String strAttributeValue = attributeValues.get(y).getDOM().getTextContent(); logger.info(strAttributeName + " = " + strAttributeValue); } } } } } catch (Exception ex) { logger.error("Failed to validate assertion", ex); throw ex; } return decodedString; }
From source file:com.fujitsu.dc.test.jersey.box.ServiceSourceTest.java
/** * PROPPATCH????./*ww w . j a va2 s .c o m*/ * @param doc ??XML * @param resorce PROPPATCH?? * @param map ???KeyValue * Key?Value???????? * Valuenull???Key??????remove???? */ private void checkProppatchResponse(Element doc, String resorce, Map<String, String> map) { NodeList response = doc.getElementsByTagName("response"); assertEquals(1, response.getLength()); Element node = (Element) response.item(0); assertEquals( resorce, node.getElementsByTagName("href").item(0).getFirstChild().getNodeValue()); assertEquals( "HTTP/1.1 200 OK", node.getElementsByTagName("status").item(0).getFirstChild().getNodeValue()); for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) { Object key = it.next(); Object value = map.get(key); String textContext = null; NodeList tmp = node.getElementsByTagName("prop").item(0).getChildNodes(); for (int i = 0; i < tmp.getLength(); i++) { Node child = tmp.item(i); if (child instanceof Element) { Element childElement = (Element) child; if (childElement.getLocalName().equals(key)) { textContext = childElement.getTextContent(); break; } } } assertEquals(value, textContext); } }
From source file:org.apache.taverna.activities.wsdl.T2WSDLSOAPInvoker.java
@Override protected void addSoapHeader(SOAPEnvelope envelope) throws SOAPException { if (wsrfEndpointReference != null) { // Extract elements // Add WSA-stuff // Add elements Document wsrfDoc;// w w w . j a v a2 s . c o m try { wsrfDoc = parseWsrfEndpointReference(wsrfEndpointReference); } catch (Exception e) { logger.warn("Could not parse endpoint reference, ignoring:\n" + wsrfEndpointReference, e); return; } Element wsrfRoot = wsrfDoc.getDocumentElement(); Element endpointRefElem = null; if (!wsrfRoot.getNamespaceURI().equals(WSA200403NS) || !wsrfRoot.getLocalName().equals(ENDPOINT_REFERENCE)) { // Only look for child if the parent is not an EPR NodeList nodes = wsrfRoot.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(ENDPOINT_REFERENCE) && node.getNamespaceURI().equals(WSA200403NS)) { // Support wrapped endpoint reference for backward compatibility // and convenience (T2-677) endpointRefElem = (Element) node; break; } } } if (endpointRefElem == null) { logger.warn("Unexpected element name for endpoint reference, but inserting anyway: " + wsrfRoot.getTagName()); endpointRefElem = wsrfRoot; } Element refPropsElem = null; NodeList nodes = endpointRefElem.getChildNodes(); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(REFERENCE_PROPERTIES) && node.getNamespaceURI().equals(WSA200403NS)) { refPropsElem = (Element) node; break; } } if (refPropsElem == null) { logger.warn("Could not find " + REFERENCE_PROPERTIES); return; } SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } NodeList refProps = refPropsElem.getChildNodes(); for (int i = 0, n = refProps.getLength(); i < n; i++) { Node node = refProps.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) { SOAPElement soapElement = SOAPFactory.newInstance().createElement((Element) node); header.addChildElement(soapElement); Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements(); while (headers.hasNext()) { SOAPHeaderElement headerElement = headers.next(); if (headerElement.getElementQName().equals(soapElement.getElementQName())) { headerElement.setMustUnderstand(false); headerElement.setActor(null); } } } } } }
From source file:org.devefx.httpmapper.spring.config.ListenersBeanDefinitionParser.java
public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compDefinition); RuntimeBeanReference pathMatcherRef = null; if (element.hasAttribute("path-matcher")) { pathMatcherRef = new RuntimeBeanReference(element.getAttribute("path-matcher")); }//from w w w.j ava 2s . c o m List<Element> listeners = DomUtils.getChildElementsByTagName(element, "bean", "ref", "listener"); for (Element listener : listeners) { RootBeanDefinition mappedListenerDef = new RootBeanDefinition(MappedListener.class); mappedListenerDef.setSource(parserContext.extractSource(listener)); mappedListenerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); ManagedList<String> includePatterns = null; ManagedList<String> excludePatterns = null; Object listenerBean; if ("listener".equals(listener.getLocalName())) { includePatterns = getIncludePatterns(listener, "mapping"); excludePatterns = getIncludePatterns(listener, "exclude-mapping"); Element beanElem = DomUtils.getChildElementsByTagName(listener, "bean", "ref").get(0); listenerBean = parserContext.getDelegate().parsePropertySubElement(beanElem, null); } else { listenerBean = parserContext.getDelegate().parsePropertySubElement(listener, null); } mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns); mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns); mappedListenerDef.getConstructorArgumentValues().addIndexedArgumentValue(2, listenerBean); if (pathMatcherRef != null) { mappedListenerDef.getPropertyValues().add("pathMatcher", pathMatcherRef); } String beanName = parserContext.getReaderContext().registerWithGeneratedName(mappedListenerDef); parserContext.registerComponent(new BeanComponentDefinition(mappedListenerDef, beanName)); } parserContext.popAndRegisterContainingComponent(); return null; }
From source file:be.fedict.eid.idp.protocol.ws_federation.sts.SecurityTokenServicePortImpl.java
@Override public RequestSecurityTokenResponseCollectionType requestSecurityToken(RequestSecurityTokenType request) { List<Object> requestContent = request.getAny(); String expectedAudience = null; for (Object requestObject : requestContent) { LOG.debug("request object type: " + requestObject.getClass().getName()); if (requestObject instanceof JAXBElement) { JAXBElement jaxbElement = (JAXBElement) requestObject; QName qname = jaxbElement.getName(); if (WSTrustConstants.TOKEN_TYPE_QNAME.equals(qname)) { String tokenType = (String) jaxbElement.getValue(); if (false == WSTrustConstants.STATUS_TOKEN_TYPE.equals(tokenType)) { throw new SecurityException("invalid response token type: " + tokenType); }// w w w . ja va 2 s . c om } else if (WSTrustConstants.REQUEST_TYPE_QNAME.equals(qname)) { String requestType = (String) jaxbElement.getValue(); if (false == WSTrustConstants.VALIDATE_REQUEST_TYPE.equals(requestType)) { throw new SecurityException("invalid request type: " + requestType); } } else if (WSTrustConstants.VALIDATE_TARGET_QNAME.equals(qname)) { ValidateTargetType validateTarget = (ValidateTargetType) jaxbElement.getValue(); Object validateTargetObject = validateTarget.getAny(); if (null == validateTargetObject) { throw new SecurityException("missing ValidateTarget content"); } LOG.debug("ValidateTarget content type: " + validateTargetObject.getClass().getName()); // TODO: verify content is indeed SecurityTokenReference } } else if (requestObject instanceof AppliesTo) { AppliesTo appliesTo = (AppliesTo) requestObject; LOG.debug("wsp:AppliesTo present"); List<Object> appliesToContent = appliesTo.getAny(); for (Object appliesToObject : appliesToContent) { LOG.debug("AppliesTo object type: " + appliesToObject.getClass().getName()); if (appliesToObject instanceof JAXBElement) { JAXBElement appliesToElement = (JAXBElement) appliesToObject; QName appliesToQName = appliesToElement.getName(); if (WSTrustConstants.ENDPOINT_REFERENCE_QNAME.equals(appliesToQName)) { EndpointReferenceType endpointReference = (EndpointReferenceType) appliesToElement .getValue(); expectedAudience = endpointReference.getAddress().getValue(); } } } } } Element tokenElement = WSSecuritySoapHandler.getToken(this.context); if (null == tokenElement) { throw new SecurityException("missing Token"); } LOG.debug("token element: " + tokenElement.getLocalName()); LOG.debug("expected audience: " + expectedAudience); ServletContext servletContext = (ServletContext) context.getMessageContext() .get(MessageContext.SERVLET_CONTEXT); IdentityProviderConfiguration identityProviderConfiguration = IdentityProviderConfigurationFactory .getInstance(servletContext); boolean valid; String reason = null; try { validateToken(tokenElement, expectedAudience, identityProviderConfiguration); valid = true; } catch (Exception e) { LOG.error("error validating SAML token: " + e.getMessage(), e); valid = false; reason = e.getMessage(); } RequestSecurityTokenResponseCollectionType responseCollection = this.objectFactory .createRequestSecurityTokenResponseCollectionType(); List<RequestSecurityTokenResponseType> requestSecurityTokenResponses = responseCollection .getRequestSecurityTokenResponse(); RequestSecurityTokenResponseType requestSecurityTokenResponse = this.objectFactory .createRequestSecurityTokenResponseType(); requestSecurityTokenResponses.add(requestSecurityTokenResponse); List<Object> rstsContent = requestSecurityTokenResponse.getAny(); rstsContent.add(this.objectFactory.createTokenType(WSTrustConstants.STATUS_TOKEN_TYPE)); StatusType status = this.objectFactory.createStatusType(); rstsContent.add(this.objectFactory.createStatus(status)); if (valid) { status.setCode(WSTrustConstants.VALID_STATUS_CODE); } else { status.setCode(WSTrustConstants.INVALID_STATUS_CODE); status.setReason(reason); } return responseCollection; }