org.apache.xml.security.utils.resolver.ResourceResolverException Java Examples
The following examples show how to use
org.apache.xml.security.utils.resolver.ResourceResolverException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { String id = context.attr.getNodeValue(); if (id.startsWith("#")) { id = id.substring(1); } if (LOG.isDebugEnabled()) { try { LOG.debug("Selected document: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Source)(new DOMSource(this.doc))))); } catch (TechnicalConnectorException var5) { LOG.error(var5.getMessage()); } } Node selectedElem = this.doc.getElementById(id); if (LOG.isDebugEnabled()) { LOG.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem); } this.processElement(context.attr, context.baseUri, selectedElem, id); XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setExcludeComments(true); result.setMIMEType("text/xml"); result.setSourceURI(context.baseUri != null ? context.baseUri.concat(context.attr.getNodeValue()) : context.attr.getNodeValue()); return result; }
Example #2
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void nullAttributeTwoDocs() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver( Arrays.<DSSDocument> asList(new InMemoryDocument(new byte[] { 1, 2, 3 }), new InMemoryDocument(new byte[] { 2, 3 })), DigestAlgorithm.SHA256); Attr attr = null; ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); // 2 docs + no name -> exception resolver.engineResolveURI(context); }); assertEquals("Unable to find document (detached signature)", exception.getMessage()); }
Example #3
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void emptyAttribute() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver(Collections.<DSSDocument>emptyList(), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); // Empty when(attr.getNodeValue()).thenReturn(""); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertFalse(resolver.engineCanResolveURI(context)); // will throw ResourceResolverException resolver.engineResolveURI(context); }); assertEquals("Unable to find document (detached signature)", exception.getMessage()); }
Example #4
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void nullListAndNullAttribute() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver(null, DigestAlgorithm.SHA256); Attr attr = null; // Empty ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); // will throw ResourceResolverException resolver.engineResolveURI(context); }); assertEquals("Unable to find document (detached signature)", exception.getMessage()); }
Example #5
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void nullAttribute() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver(Collections.<DSSDocument>emptyList(), DigestAlgorithm.SHA256); Attr attr = null; // Empty ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); // will throw ResourceResolverException resolver.engineResolveURI(context); }); assertEquals("Unable to find document (detached signature)", exception.getMessage()); }
Example #6
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { String id = context.attr.getNodeValue(); if (id.startsWith("#")) { id = id.substring(1); } if (LOG.isDebugEnabled()) { try { LOG.debug("Selected document: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Source)(new DOMSource(this.doc))))); } catch (TechnicalConnectorException var5) { LOG.error(var5.getMessage()); } } Node selectedElem = this.doc.getElementById(id); if (LOG.isDebugEnabled()) { LOG.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem); } this.processElement(context.attr, context.baseUri, selectedElem, id); XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setExcludeComments(true); result.setMIMEType("text/xml"); result.setSourceURI(context.baseUri != null ? context.baseUri.concat(context.attr.getNodeValue()) : context.attr.getNodeValue()); return result; }
Example #7
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void documentNameWithEmptyList() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver(Collections.<DSSDocument>emptyList(), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); // document name + no document in the list when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); // will throw ResourceResolverException resolver.engineResolveURI(context); }); assertEquals("Unable to find document (detached signature)", exception.getMessage()); }
Example #8
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 6 votes |
@Test public void engineCanResolveURIWithWrongDocumentNameInList() throws ResourceResolverException { Exception exception = assertThrows(ResourceResolverException.class, () -> { DetachedSignatureResolver resolver = new DetachedSignatureResolver( Arrays.<DSSDocument>asList(new InMemoryDocument(new byte[] { 1, 2, 3 }, "toto.xml", MimeType.XML)), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); // document name + wrong document in the list when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); // doc not found -> exception resolver.engineResolveURI(context); }); assertEquals("Unable to find document 'sample.xml' (detached signature)", exception.getMessage()); }
Example #9
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { String id = context.attr.getNodeValue(); if (id.startsWith("#")) { id = id.substring(1); } if (LOG.isDebugEnabled()) { try { LOG.debug("Selected document: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Source)(new DOMSource(this.doc))))); } catch (TechnicalConnectorException var5) { LOG.error(var5.getMessage()); } } Node selectedElem = this.doc.getElementById(id); if (LOG.isDebugEnabled()) { LOG.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem); } this.processElement(context.attr, context.baseUri, selectedElem, id); XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setExcludeComments(true); result.setMIMEType("text/xml"); result.setSourceURI(context.baseUri != null ? context.baseUri.concat(context.attr.getNodeValue()) : context.attr.getNodeValue()); return result; }
Example #10
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { String id = context.attr.getNodeValue(); if (id.startsWith("#")) { id = id.substring(1); } if (LOG.isDebugEnabled()) { try { LOG.debug("Selected document: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Source)(new DOMSource(this.doc))))); } catch (TechnicalConnectorException var5) { LOG.error(var5.getMessage()); } } Node selectedElem = this.doc.getElementById(id); if (LOG.isDebugEnabled()) { LOG.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem); } this.processElement(context.attr, context.baseUri, selectedElem, id); XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setExcludeComments(true); result.setMIMEType("text/xml"); result.setSourceURI(context.baseUri != null ? context.baseUri.concat(context.attr.getNodeValue()) : context.attr.getNodeValue()); return result; }
Example #11
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 6 votes |
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { String id = context.attr.getNodeValue(); if (id.startsWith("#")) { id = id.substring(1); } if (LOG.isDebugEnabled()) { try { LOG.debug("Selected document: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Source)(new DOMSource(this.doc))))); } catch (TechnicalConnectorException var5) { LOG.error(var5.getMessage()); } } Node selectedElem = this.doc.getElementById(id); if (LOG.isDebugEnabled()) { LOG.debug("Try to catch an Element with ID " + id + " and Element was " + selectedElem); } this.processElement(context.attr, context.baseUri, selectedElem, id); XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setExcludeComments(true); result.setMIMEType("text/xml"); result.setSourceURI(context.baseUri != null ? context.baseUri.concat(context.attr.getNodeValue()) : context.attr.getNodeValue()); return result; }
Example #12
Source File: DetachedSignatureResolver.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { DSSDocument document = getCurrentDocument(context); if (document instanceof DigestDocument) { DigestDocument digestDoc = (DigestDocument) document; return new XMLSignatureInput(digestDoc.getDigest(digestAlgorithm)); } else { return createFromCommonDocument(document); } }
Example #13
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void engineCanResolveURIWithDocumentNoNameInList() throws ResourceResolverException { DetachedSignatureResolver resolver = new DetachedSignatureResolver(Arrays.<DSSDocument>asList(new InMemoryDocument(new byte[] { 1, 2, 3 })), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); // document name + only one document when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #14
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void engineCanResolveURIWithDocumentNameInList() throws ResourceResolverException { DetachedSignatureResolver resolver = new DetachedSignatureResolver( Arrays.<DSSDocument>asList(new InMemoryDocument(new byte[] { 1, 2, 3 }, "sample.xml", MimeType.XML)), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #15
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void engineCanResolveURIWithDocumentNameInListOfMultiples() throws ResourceResolverException { DetachedSignatureResolver resolver = new DetachedSignatureResolver( Arrays.<DSSDocument>asList(new InMemoryDocument(new byte[] { 1, 2, 3 }, "sample.xml", MimeType.XML), new InMemoryDocument(new byte[] { 2, 3 }, "sample2.xml", MimeType.XML)), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #16
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void engineCanResolveURIWithDigestDocument() throws ResourceResolverException { DigestDocument doc = new DigestDocument(DigestAlgorithm.SHA256, "abcdef"); doc.setName("sample.xml"); DetachedSignatureResolver resolver = new DetachedSignatureResolver(Arrays.<DSSDocument>asList(doc), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #17
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void engineCanResolveURIWithDigestDocumentNoName() throws ResourceResolverException { DigestDocument doc = new DigestDocument(DigestAlgorithm.SHA256, "abcdef"); // doc.setName("sample.xml"); DetachedSignatureResolver resolver = new DetachedSignatureResolver(Arrays.<DSSDocument>asList(doc), DigestAlgorithm.SHA256); Attr attr = mock(Attr.class); when(attr.getNodeValue()).thenReturn("sample.xml"); ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #18
Source File: DetachedSignatureResolverTest.java From dss with GNU Lesser General Public License v2.1 | 5 votes |
@Test public void nullAttributeOneDoc() throws ResourceResolverException { DetachedSignatureResolver resolver = new DetachedSignatureResolver(Arrays.<DSSDocument>asList(new InMemoryDocument(new byte[] { 1, 2, 3 })), DigestAlgorithm.SHA256); Attr attr = null; ResourceResolverContext context = new ResourceResolverContext(attr, null, false); assertTrue(resolver.engineCanResolveURI(context)); assertNotNull(resolver.engineResolveURI(context)); }
Example #19
Source File: OtherSignerTests.java From xades4j with GNU Lesser General Public License v3.0 | 5 votes |
@Override public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException { XMLSignatureInput input = new XMLSignatureInput(context.attr.getValue().getBytes()); resolveCount++; return input; }
Example #20
Source File: QualifyingPropertyVerificationContext.java From xades4j with GNU Lesser General Public License v3.0 | 5 votes |
private <TObj> TObj getReferencedElement( String objReference, Map<Element, TObj> mapper) { if (!objReference.startsWith("#")) throw new IllegalArgumentException(); if (mapper.isEmpty()) return null; // A little workaround to be able to use the ResourceResolver. Attr refAttr = this.signatureDoc.createAttributeNS(null, "ref"); refAttr.setNodeValue(objReference); this.signatureDoc.createElementNS(null, "dummy").setAttributeNodeNS(refAttr); try { XMLSignatureInput refData = ResourceResolver.getInstance(refAttr, "", true).resolve(refAttr, "", true); // This has to be a NodeSet data because it is a same-document reference. Node refNode = refData.getSubNode(); if (refNode.getNodeType() != Node.ELEMENT_NODE) return null; // May return null. return mapper.get((Element)refNode); } catch (ResourceResolverException ex) { // Maybe an exception should be thrown... return null; } }
Example #21
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
private void processElement(Attr uri, String baseURI, Node selectedElem, String id) throws ResourceResolverException { if (selectedElem == null) { Object[] exArgs = new Object[]{id}; throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri.getBaseURI(), baseURI); } }
Example #22
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
private void processElement(Attr uri, String baseURI, Node selectedElem, String id) throws ResourceResolverException { if (selectedElem == null) { Object[] exArgs = new Object[]{id}; throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri.getBaseURI(), baseURI); } }
Example #23
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
private void processElement(Attr uri, String baseURI, Node selectedElem, String id) throws ResourceResolverException { if (selectedElem == null) { Object[] exArgs = new Object[]{id}; throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri.getBaseURI(), baseURI); } }
Example #24
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
private void processElement(Attr uri, String baseURI, Node selectedElem, String id) throws ResourceResolverException { if (selectedElem == null) { Object[] exArgs = new Object[]{id}; throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri.getBaseURI(), baseURI); } }
Example #25
Source File: DocumentResolver.java From freehealth-connector with GNU Affero General Public License v3.0 | 4 votes |
private void processElement(Attr uri, String baseURI, Node selectedElem, String id) throws ResourceResolverException { if (selectedElem == null) { Object[] exArgs = new Object[]{id}; throw new ResourceResolverException("signature.Verification.MissingID", exArgs, uri.getBaseURI(), baseURI); } }