public void handleMessage(Message message) throws Fault { if (binding.getHandlerChain().isEmpty()) { return; } HandlerChainInvoker invoker = getInvoker(message); if (invoker.getLogicalHandlers().isEmpty()) { return; } XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); Document doc = DOMUtils.newDocument(); message.setContent(Node.class, doc); W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc); // set up the namespace context try { writer.setNamespaceContext(origWriter.getNamespaceContext()); } catch (XMLStreamException ex) { // don't set the namespaceContext } // Replace stax writer with DomStreamWriter message.setContent(XMLStreamWriter.class, writer); message.put(ORIGINAL_WRITER, origWriter); message.getInterceptorChain().add(ending); }
public void handleMessage(Message message) throws Fault { if (binding.getHandlerChain().isEmpty()) { return; } HandlerChainInvoker invoker = getInvoker(message); if (invoker.getLogicalHandlers().isEmpty()) { return; } XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); Node nd = message.getContent(Node.class); SOAPMessage m = message.getContent(SOAPMessage.class); Document document = null; if (m != null) { document = m.getSOAPPart(); } else if (nd != null) { document = nd.getOwnerDocument(); } else { document = DOMUtils.newDocument(); message.setContent(Node.class, document); } W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment()); // Replace stax writer with DomStreamWriter message.setContent(XMLStreamWriter.class, writer); message.put(ORIGINAL_WRITER, origWriter); message.getInterceptorChain().add(ending); } @Override
public W3CDOMStreamWriter() { document = DOMUtils.newDocument(); }
public W3CDOMStreamWriter() throws ParserConfigurationException { document = DOMUtils.newDocument(); }
public W3CDOMStreamWriter() throws ParserConfigurationException { document = DOMUtils.newDocument(); }
public W3CDOMStreamWriter() { document = DOMUtils.newDocument(); }
public void handleMessage(Message message) throws Fault { try { SamlAssertionWrapper assertionWrapper = createAssertion(message); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String encodedToken = encodeToken(DOM2Writer.nodeToString(assertionElement)); Map<String, List<String>> headers = getHeaders(message); StringBuilder builder = new StringBuilder(); builder.append("SAML").append(" ").append(encodedToken); headers.put("Authorization", CastUtils.cast(Collections.singletonList(builder.toString()), String.class)); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); LOG.warning(sw.toString()); throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString())); } }
public void handleMessage(Message message) throws Fault { try { SamlAssertionWrapper assertionWrapper = createAssertion(message); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String encodedToken = encodeToken(DOM2Writer.nodeToString(assertionElement)); Map<String, List<String>> headers = getHeaders(message); StringBuilder builder = new StringBuilder(); builder.append("SAML").append(" ").append(encodedToken); headers.put("Authorization", CastUtils.cast(Collections.singletonList(builder.toString()), String.class)); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); LOG.warning(sw.toString()); throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString())); } }
public DOMSource sayHi(DOMSource in) { Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types", "ns1:sayHiResponse"); Element el2 = doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types", "ns1:responseType"); el2.appendChild(doc.createTextNode("Bonjour")); el.appendChild(el2); doc.appendChild(el); return new DOMSource(doc); } private Element getElement(Node nd) {
public void handleMessage(Message message) throws Fault { Form form = getRequestForm(message); if (form == null) { return; } try { SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(message); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String encodedToken = encodeToken(DOM2Writer.nodeToString(assertionElement)); updateForm(form, encodedToken); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); LOG.warning(sw.toString()); throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString())); } }
public void handleMessage(Message message) throws Fault { Form form = getRequestForm(message); if (form == null) { return; } try { SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(message); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String encodedToken = encodeToken(DOM2Writer.nodeToString(assertionElement)); updateForm(form, encodedToken); } catch (Exception ex) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); LOG.warning(sw.toString()); throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString())); } }
protected Element createResponse(Idp idp, String requestID, Assertion assertion) throws Exception { Document doc = DOMUtils.newDocument(); Status status = SAML2PResponseComponentBuilder.createStatus( "urn:oasis:names:tc:SAML:2.0:status:Success", null ); String issuer = isUseRealmForIssuer() ? idp.getRealm() : idp.getIdpUrl().toString(); Response response = SAML2PResponseComponentBuilder.createSAMLResponse(requestID, issuer, status); response.getAssertions().add(assertion); Element policyElement = OpenSAMLUtil.toDom(response, doc); doc.appendChild(policyElement); return policyElement; }
protected Element createLogoutResponse(Idp idp, String statusValue, String destination, String requestID) throws Exception { Document doc = DOMUtils.newDocument(); Status status = SAML2PResponseComponentBuilder.createStatus(statusValue, null); String issuer = useRealmForIssuer ? idp.getRealm() : idp.getIdpUrl().toString(); LogoutResponse response = SAML2PResponseComponentBuilder.createSAMLLogoutResponse(requestID, issuer, status, destination); // Sign the LogoutResponse signResponse(response, idp); Element policyElement = OpenSAMLUtil.toDom(response, doc); doc.appendChild(policyElement); return policyElement; }
public DOMSource greetMe(DOMSource in) throws GreetMeFault { Element eval = getElement(in.getNode()); eval = DOMUtils.getFirstElement(eval); String val = DOMUtils.getContent(eval); if ("fault".equals(val)) { Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS("http://apache.org/hello_world_soap_http_source/" + "source/types", "ns1:greetMeFaultDetail"); el.appendChild(doc.createTextNode("Some fault detail")); doc.appendChild(el); throw new GreetMeFault("Fault String", new DOMSource(doc)); } Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types", "ns1:greetMeResponse"); Element el2 = doc.createElementNS("http://apache.org/hello_world_soap_http_source/source/types", "ns1:responseType"); el2.appendChild(doc.createTextNode("Hello " + val)); el.appendChild(el2); doc.appendChild(el); return new DOMSource(doc); }
public String createSAMLResponse(RequestContext context, boolean logout, boolean requestor, Idp idp, String requestID, String destination) throws ProcessingException { Document doc = DOMUtils.newDocument(); String statusValue = "urn:oasis:names:tc:SAML:2.0:status:Responder"; if (requestor) { statusValue = "urn:oasis:names:tc:SAML:2.0:status:Requester"; } Status status = SAML2PResponseComponentBuilder.createStatus(statusValue, null); Element responseElement = null; try { if (logout) { responseElement = createLogoutResponse(idp, statusValue, destination, requestID); } else { Response response = SAML2PResponseComponentBuilder.createSAMLResponse(requestID, idp.getRealm(), status); Element policyElement = OpenSAMLUtil.toDom(response, doc); doc.appendChild(policyElement); responseElement = policyElement; } return encodeResponse(responseElement); } catch (Exception e) { LOG.warn("Error marshalling SAML Token: {}", e.getMessage()); throw new ProcessingException(TYPE.BAD_REQUEST); } }
public void handleMessage(Message message) throws Fault { if (binding.getHandlerChain().isEmpty()) { return; } HandlerChainInvoker invoker = getInvoker(message); if (invoker.getLogicalHandlers().isEmpty()) { return; } XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); Document doc = DOMUtils.newDocument(); message.setContent(Node.class, doc); W3CDOMStreamWriter writer = new W3CDOMStreamWriter(doc); // set up the namespace context try { writer.setNamespaceContext(origWriter.getNamespaceContext()); } catch (XMLStreamException ex) { // don't set the namespaceContext } // Replace stax writer with DomStreamWriter message.setContent(XMLStreamWriter.class, writer); message.put(ORIGINAL_WRITER, origWriter); message.getInterceptorChain().add(ending); }
public void handleMessage(Message message) throws Fault { if (binding.getHandlerChain().isEmpty()) { return; } HandlerChainInvoker invoker = getInvoker(message); if (invoker.getLogicalHandlers().isEmpty()) { return; } XMLStreamWriter origWriter = message.getContent(XMLStreamWriter.class); Node nd = message.getContent(Node.class); SOAPMessage m = message.getContent(SOAPMessage.class); Document document = null; if (m != null) { document = m.getSOAPPart(); } else if (nd != null) { document = nd.getOwnerDocument(); } else { document = DOMUtils.newDocument(); message.setContent(Node.class, document); } W3CDOMStreamWriter writer = new W3CDOMStreamWriter(document.createDocumentFragment()); // Replace stax writer with DomStreamWriter message.setContent(XMLStreamWriter.class, writer); message.put(ORIGINAL_WRITER, origWriter); message.getInterceptorChain().add(ending); } @Override
@org.junit.Test public void testBinarySecurityToken() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = BinarySecurityTokenTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = BinarySecurityTokenTest.class.getResource("DoubleItTokens.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); // Successful invocation QName portQName = new QName(NAMESPACE, "DoubleItBinarySecurityTokenPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(port, PORT); // Mock up a BinarySecurityToken to add SecurityToken securityToken = new SecurityToken(); securityToken.setId("_" + UUID.randomUUID().toString()); Document doc = DOMUtils.newDocument(); BinarySecurity binarySecurity = new BinarySecurity(doc); binarySecurity.setValueType("http://custom-value-type"); binarySecurity.setToken("This is a token".getBytes()); securityToken.setToken(binarySecurity.getElement()); ((BindingProvider)port).getRequestContext().put(SecurityConstants.TOKEN, securityToken); assertEquals(50, port.doubleIt(25)); ((java.io.Closeable)port).close(); bus.shutdown(true); }
@Test public void testSAML2BearerAuthenticationDirect() throws Exception { String address = "https://localhost:" + port + "/oauth2-auth/token"; WebClient wc = createWebClient(address); Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES); SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password"); SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true); samlCallbackHandler.setIssuer("alice"); String audienceURI = "https://localhost:" + port + "/oauth2-auth/token"; samlCallbackHandler.setAudience(audienceURI); SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler, signInfo); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String assertion = DOM2Writer.nodeToString(assertionElement); String encodedAssertion = Base64UrlUtility.encode(assertion); Map<String, String> extraParams = new HashMap<>(); extraParams.put(Constants.CLIENT_AUTH_ASSERTION_TYPE, Constants.CLIENT_AUTH_SAML2_BEARER); extraParams.put(Constants.CLIENT_AUTH_ASSERTION_PARAM, encodedAssertion); ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new CustomGrant(), extraParams); assertNotNull(at.getTokenKey()); }
@Test public void testSAML2BearerGrant() throws Exception { String address = "https://localhost:" + port + "/oauth2/token"; WebClient wc = createWebClient(address); Crypto crypto = new CryptoLoader().loadCrypto(CRYPTO_RESOURCE_PROPERTIES); SelfSignInfo signInfo = new SelfSignInfo(crypto, "alice", "password"); SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(false); String audienceURI = "https://localhost:" + port + "/oauth2/token"; samlCallbackHandler.setAudience(audienceURI); SamlAssertionWrapper assertionWrapper = SAMLUtils.createAssertion(samlCallbackHandler, signInfo); Document doc = DOMUtils.newDocument(); Element assertionElement = assertionWrapper.toDOM(doc); String assertion = DOM2Writer.nodeToString(assertionElement); Saml2BearerGrant grant = new Saml2BearerGrant(assertion); ClientAccessToken at = OAuthClientUtils.getAccessToken(wc, new Consumer("alice", "alice"), grant, false); assertNotNull(at.getTokenKey()); }