List of usage examples for org.w3c.dom Document appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:org.apache.cxf.cwiki.SiteExporter.java
public int getBlogVersion(String pageId) throws Exception { Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntry"); Element el2 = doc.createElement("in0"); el.appendChild(el2);/*w w w.j a va 2 s . c o m*/ el2.setTextContent(loginToken); el2 = doc.createElement("in1"); el.appendChild(el2); el2.setTextContent(pageId); doc.appendChild(el); doc = getDispatch().invoke(doc); Node nd = doc.getDocumentElement().getFirstChild(); String version = DOMUtils.getChildContent(nd, "version"); return Integer.parseInt(version); }
From source file:com.enonic.vertical.engine.handlers.SectionHandler.java
public void updateSection(User user, Document doc) throws VerticalUpdateException, VerticalSecurityException { Element elem = doc.getDocumentElement(); int sectionKey = Integer.parseInt(elem.getAttribute("key")); boolean ordered = isSectionOrdered(sectionKey); CommonHandler commonHandler = getCommonHandler(); try {/*from w w w .j a va 2 s .c o m*/ commonHandler.updateEntities(doc, null); } catch (ProcessElementException pee) { // NOTE!! Ignored exception. Never thrown. VerticalEngineLogger.fatalEngine(this.getClass(), 0, "Ignored exception: %t", pee); } Element sectionElem = null; try { // Remove old content types for this section removeContentTypesForSection(sectionKey); sectionElem = doc.getDocumentElement(); Element contentTypesElem = XMLTool.getElement(sectionElem, "contenttypes"); Element[] contentTypes = XMLTool.getElements(contentTypesElem, "contenttype"); TIntArrayList contentTypeKeys = new TIntArrayList(); for (Element contentType : contentTypes) { contentTypeKeys.add(Integer.parseInt(contentType.getAttribute("key"))); } // Set the new ones setContentTypesForSection(sectionKey, contentTypeKeys.toArray()); // Apply the filter applySectionFilter(sectionKey); // set section content order if section is ordered if (!ordered && "true".equals(sectionElem.getAttribute("ordered"))) { int[] contentKeys = getContentKeysBySection(sectionKey); for (int i = 0; i < contentKeys.length; i++) { updateSectionContent(user, sectionKey, contentKeys[i], i + 1, true, null); } } else if (ordered && "false".equals(sectionElem.getAttribute("ordered"))) { int[] contentKeys = getContentKeysBySection(sectionKey); for (int contentKey : contentKeys) { updateSectionContent(user, sectionKey, contentKey, 0, true, null); } } } catch (VerticalCreateException vce) { String message = "Failed to create section contenttype filter: %t"; VerticalEngineLogger.errorUpdate(this.getClass(), 1, message, vce); } catch (VerticalRemoveException vre) { String message = "Failed to create section contenttype filter: %t"; VerticalEngineLogger.errorUpdate(this.getClass(), 1, message, vre); } // set section access rights SecurityHandler securityHandler = getSecurityHandler(); Element accessrightsElem = XMLTool.getElement(elem, "accessrights"); if (accessrightsElem != null) { accessrightsElem.setAttribute("key", sectionElem.getAttribute("key")); Document tempDoc = XMLTool.createDocument(); tempDoc.appendChild(tempDoc.importNode(accessrightsElem, true)); securityHandler.updateAccessRights(user, tempDoc); } }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testMissingRelayState() throws Exception { OpenSAMLUtil.initSamlEngine();/* w w w .j a v a 2 s . c o m*/ // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on not sending the RelayState"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testNoIssuer() throws Exception { OpenSAMLUtil.initSamlEngine();//w w w . ja v a 2 s . c o m // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, null, consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testMissingDestination() throws Exception { OpenSAMLUtil.initSamlEngine();//from w w w.ja v a 2 s . co m // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testUnsignedRequest() throws Exception { OpenSAMLUtil.initSamlEngine();/*from ww w .j ava 2s .c o m*/ // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testBadIssuer() throws Exception { OpenSAMLUtil.initSamlEngine();//from w ww.j a v a2 s . c o m // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld-xyz", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testUnknownRACS() throws Exception { OpenSAMLUtil.initSamlEngine();// ww w .j a v a 2 s.com // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/insecure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testEmptySeparateSignature() throws Exception { OpenSAMLUtil.initSamlEngine();/*from w w w . j av a2 s . c om*/ // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); String authnRequestEncoded = encodeAuthnRequest(authnRequestElement); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml/up?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; url += "&" + SSOConstants.SIGNATURE + "="; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); final HtmlPage idpPage = webClient.getPage(url); org.opensaml.saml.saml2.core.Response samlResponse = parseSAMLResponse(idpPage, relayState, consumerURL, authnRequest.getID()); String expected = "urn:oasis:names:tc:SAML:2.0:status:Requester"; Assert.assertEquals(expected, samlResponse.getStatus().getStatusCode().getValue()); webClient.close(); }
From source file:org.apache.cxf.fediz.systests.idp.IdpTest.java
@org.junit.Test public void testProblemWithParsingRequest() throws Exception { OpenSAMLUtil.initSamlEngine();/*from w w w.ja v a2 s. c o m*/ // Create SAML AuthnRequest Document doc = DOMUtils.createDocument(); doc.appendChild(doc.createElement("root")); // Create the AuthnRequest String consumerURL = "https://localhost:" + getRpHttpsPort() + "/" + getServletContextName() + "/secure/fedservlet"; AuthnRequest authnRequest = new DefaultAuthnRequestBuilder().createAuthnRequest(null, "urn:org:apache:cxf:fediz:fedizhelloworld-xyz", consumerURL); authnRequest.setDestination("https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml"); signAuthnRequest(authnRequest); Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc); // Don't inflate the token... String requestMessage = DOM2Writer.nodeToString(authnRequestElement); String authnRequestEncoded = Base64Utility.encode(requestMessage.getBytes("UTF-8")); String urlEncodedRequest = URLEncoder.encode(authnRequestEncoded, "UTF-8"); String relayState = UUID.randomUUID().toString(); String url = "https://localhost:" + getIdpHttpsPort() + "/fediz-idp/saml?"; url += SSOConstants.RELAY_STATE + "=" + relayState; url += "&" + SSOConstants.SAML_REQUEST + "=" + urlEncodedRequest; String user = "alice"; String password = "ecila"; final WebClient webClient = new WebClient(); webClient.getOptions().setUseInsecureSSL(true); webClient.getCredentialsProvider().setCredentials( new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())), new UsernamePasswordCredentials(user, password)); webClient.getOptions().setJavaScriptEnabled(false); try { webClient.getPage(url); Assert.fail("Failure expected on parsing the request in the IdP"); } catch (FailingHttpStatusCodeException ex) { Assert.assertEquals(ex.getStatusCode(), 400); } webClient.close(); }