本文整理汇总了Java中org.opensaml.xml.parse.XMLParserException类的典型用法代码示例。如果您正苦于以下问题:Java XMLParserException类的具体用法?Java XMLParserException怎么用?Java XMLParserException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XMLParserException类属于org.opensaml.xml.parse包,在下文中一共展示了XMLParserException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseInputStream
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Parse the specified input stream in a DOM DocumentFragment, owned by the specified Document.
*
* @param input the InputStream to parse
* @param owningDocument the Document which will own the returned DocumentFragment
* @return a DocumentFragment
* @throws DecryptionException thrown if there is an error parsing the input stream
*/
private DocumentFragment parseInputStream(InputStream input, Document owningDocument) throws DecryptionException {
// Since Xerces currently seems not to handle parsing into a DocumentFragment
// without a bit hackery, use this to simulate, so we can keep the API
// the way it hopefully will look in the future. Obviously this only works for
// input streams containing valid XML instances, not fragments.
Document newDocument = null;
try {
newDocument = parserPool.parse(input);
} catch (XMLParserException e) {
log.error("Error parsing decrypted input stream", e);
throw new DecryptionException("Error parsing input stream", e);
}
Element element = newDocument.getDocumentElement();
owningDocument.adoptNode(element);
DocumentFragment container = owningDocument.createDocumentFragment();
container.appendChild(element);
return container;
}
示例2: prepareForAdoption
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Prepares the given DOM caching XMLObject for adoption into another document. If the XMLObject has a parent then
* all visible namespaces used by the given XMLObject and its descendants are declared within that subtree and the
* parent's DOM is invalidated.
*
* @param domCachingObject the XMLObject to prepare for adoption
*
* @throws MarshallingException thrown if a namespace within the XMLObject's DOM subtree can not be resolved.
*/
private void prepareForAdoption(XMLObject domCachingObject) throws MarshallingException {
if (domCachingObject.getParent() != null) {
log.trace("Rooting all visible namespaces of XMLObject {} before adding it to new parent Element",
domCachingObject.getElementQName());
try {
XMLHelper.rootNamespaces(domCachingObject.getDOM());
} catch (XMLParserException e) {
String errorMsg =
"Unable to root namespaces of cached DOM element, " + domCachingObject.getElementQName();
log.error(errorMsg, e);
throw new MarshallingException(errorMsg, e);
}
log.trace("Release DOM of XMLObject parent");
domCachingObject.releaseParentDOM(true);
}
}
示例3: testResponseUnmarshall
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Tests unmarshalling a full response message.
*/
public void testResponseUnmarshall(){
try {
InputStream in = ResponseTest.class.getResourceAsStream(fullResponsePath);
Document responseDoc = parser.parse(in);
Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(
responseDoc.getDocumentElement());
Response response = (Response) unmarshaller.unmarshall(responseDoc.getDocumentElement());
assertEquals("First element of response data was not expected Response", "Response",
response.getElementQName().getLocalPart());
} catch (XMLParserException xe) {
fail("Unable to parse XML file: " + xe);
} catch (UnmarshallingException ue) {
fail("Unable to unmarshall XML: " + ue);
}
}
示例4: populateRequest
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Populate the HTTP servlet request object with the parameter info. Would be nice if Spring mock object
* actually did this for you from populating the content string.... Oh well.
*
* @param request
* @param htmlContentString
* @throws XMLParserException
*/
private void populateRequest(MockHttpServletRequest request, String htmlContentString) throws XMLParserException {
request.setContent( htmlContentString.getBytes() );
Document doc = parser.parse( new ByteArrayInputStream(htmlContentString.getBytes()) );
// html
Element current = doc.getDocumentElement();
// body
current = XMLHelper.getFirstChildElement(current);
// form
current = XMLHelper.getFirstChildElement(current); current = XMLHelper.getNextSiblingElement(current);
// div
current = XMLHelper.getFirstChildElement(current);
// list of form input fields
List<Element> inputs = XMLHelper.getChildElementsByTagNameNS(current, "http://www.w3.org/1999/xhtml", "input");
for (Element element : inputs) {
String name = element.getAttributeNS(null, "name");
String value = element.getAttributeNS(null, "value");
//System.out.println("Processing input field: " + name);
request.setParameter(name, value);
}
}
示例5: testInCommonUnmarshall
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Tests unmarshalling an InCommon metadata document.
*
* @throws XMLParserException
* @throws UnmarshallingException
*/
public void testInCommonUnmarshall() throws XMLParserException, UnmarshallingException {
String inCommonMDFile = "/data/org/opensaml/saml2/metadata/InCommon-metadata.xml";
try {
InputStream in = MetadataTest.class.getResourceAsStream(inCommonMDFile);
Document inCommonMDDoc = parser.parse(in);
Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(
inCommonMDDoc.getDocumentElement());
XMLObject inCommonMD = unmarshaller.unmarshall(inCommonMDDoc.getDocumentElement());
assertEquals("First element of InCommon data was not expected EntitiesDescriptor", "EntitiesDescriptor",
inCommonMD.getElementQName().getLocalPart());
} catch (XMLParserException xe) {
fail("Unable to parse XML file: " + xe);
} catch (UnmarshallingException ue) {
fail("Unable to unmarshall XML: " + ue);
}
}
示例6: testSWITCHUnmarshall
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Tests unmarshalling an SWITCH metadata document.
*
* @throws XMLParserException
* @throws UnmarshallingException
*/
public void testSWITCHUnmarshall() {
String switchMDFile = "/data/org/opensaml/saml2/metadata/metadata.switchaai_signed.xml";
try {
InputStream in = MetadataTest.class.getResourceAsStream(switchMDFile);
Document switchMDDoc = parser.parse(in);
Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(
switchMDDoc.getDocumentElement());
XMLObject switchMD = unmarshaller.unmarshall(switchMDDoc.getDocumentElement());
assertEquals("First element of SWITCH data was not expected EntitiesDescriptor", "EntitiesDescriptor",
switchMD.getElementQName().getLocalPart());
} catch (XMLParserException xe) {
fail("Unable to parse XML file: " + xe);
} catch (UnmarshallingException ue) {
fail("Unable to unmarshall XML: " + ue);
}
}
示例7: testEntityDescriptor
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
public void testEntityDescriptor() throws UnmarshallingException, CertificateException, XMLParserException {
X509Certificate cert = SecurityTestHelper.buildJavaX509Cert(openIDCertBase64);
X509Credential cred = SecurityHelper.getSimpleCredential(cert, null);
StaticCredentialResolver credResolver = new StaticCredentialResolver(cred);
SignatureTrustEngine trustEngine = new ExplicitKeySignatureTrustEngine(credResolver,
Configuration.getGlobalSecurityConfiguration().getDefaultKeyInfoCredentialResolver());
Document mdDoc = parser.parse(SignatureValidationFilterTest.class.getResourceAsStream(openIDFileValid));
XMLObject xmlObject =
unmarshallerFactory.getUnmarshaller(mdDoc.getDocumentElement()).unmarshall(mdDoc.getDocumentElement());
assertTrue(xmlObject instanceof EntityDescriptor);
EntityDescriptor ed = (EntityDescriptor) xmlObject;
assertTrue(ed.isSigned());
assertNotNull("Signature was null", ed.getSignature());
SignatureValidationFilter filter = new SignatureValidationFilter(trustEngine);
try {
filter.doFilter(ed);
} catch (FilterException e) {
fail("Filter failed validation, should have succeeded: " + e.getMessage());
}
}
示例8: testEntityDescriptorInvalid
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
public void testEntityDescriptorInvalid() throws UnmarshallingException, CertificateException, XMLParserException {
X509Certificate cert = SecurityTestHelper.buildJavaX509Cert(openIDCertBase64);
X509Credential cred = SecurityHelper.getSimpleCredential(cert, null);
StaticCredentialResolver credResolver = new StaticCredentialResolver(cred);
SignatureTrustEngine trustEngine = new ExplicitKeySignatureTrustEngine(credResolver,
Configuration.getGlobalSecurityConfiguration().getDefaultKeyInfoCredentialResolver());
Document mdDoc = parser.parse(SignatureValidationFilterTest.class.getResourceAsStream(openIDFileInvalid));
XMLObject xmlObject =
unmarshallerFactory.getUnmarshaller(mdDoc.getDocumentElement()).unmarshall(mdDoc.getDocumentElement());
assertTrue(xmlObject instanceof EntityDescriptor);
EntityDescriptor ed = (EntityDescriptor) xmlObject;
assertTrue(ed.isSigned());
assertNotNull("Signature was null", ed.getSignature());
SignatureValidationFilter filter = new SignatureValidationFilter(trustEngine);
try {
filter.doFilter(xmlObject);
fail("Filter passed validation, should have failed");
} catch (FilterException e) {
// do nothing, should fail
}
}
示例9: testEncryptedAssertion
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test decryption of an EncryptedAssertion.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedAssertion() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
Assertion target = (Assertion) unmarshallElement(filename);
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof Assertion);
assertEquals(targetDOM, decryptedTarget);
}
示例10: testEncryptedAssertionAsID
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test decryption of an Assertion as an EncryptedID.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedAssertionAsID() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/Assertion.xml";
Document targetDOM = getDOM(filename);
Assertion target = (Assertion) unmarshallElement(filename);
EncryptedID encryptedTarget = encrypter.encryptAsID(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof Assertion);
assertEquals(targetDOM, decryptedTarget);
}
示例11: testEncryptedNameID
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test decryption of an NameID as an EncryptedID.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedNameID() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/NameID.xml";
Document targetDOM = getDOM(filename);
NameID target = (NameID) unmarshallElement(filename);
EncryptedID encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof NameID);
assertEquals(targetDOM, decryptedTarget);
}
示例12: testEncryptedNewID
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test decryption of an NewID as an NewEncryptedID.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedNewID() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/NewID.xml";
Document targetDOM = getDOM(filename);
NewID target = (NewID) unmarshallElement(filename);
NewEncryptedID encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof NewID);
assertEquals(targetDOM, decryptedTarget);
}
示例13: testEncryptedAttribute
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test decryption of an EncryptedAttribute.
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
*/
public void testEncryptedAttribute() throws XMLParserException, EncryptionException {
String filename = "/data/org/opensaml/saml2/encryption/Attribute.xml";
Document targetDOM = getDOM(filename);
Attribute target = (Attribute) unmarshallElement(filename);
EncryptedAttribute encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(keyResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
} catch (DecryptionException e) {
fail("Error on decryption of encrypted SAML 2 type to element: " + e);
}
assertNotNull("Decrypted target was null", decryptedTarget);
assertTrue("Decrypted target was not the expected type", decryptedTarget instanceof Attribute);
assertEquals(targetDOM, decryptedTarget);
}
示例14: testErrorInvalidDataDecryptionKey
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
/**
* Test error condition of invalid data decryption key.
* @throws EncryptionException
*
* @throws XMLParserException thrown if there is an error parsing the control XML file
* @throws EncryptionException thrown if there is an error encrypting the control XML
* @throws NoSuchProviderException security provider was invalid
* @throws NoSuchAlgorithmException security/key algorithm was invalid
*/
public void testErrorInvalidDataDecryptionKey()
throws XMLParserException, EncryptionException, NoSuchAlgorithmException, NoSuchProviderException {
Key badKey = SecurityTestHelper.generateKeyFromURI(encURI);
BasicCredential encCred = new BasicCredential();
encCred.setSecretKey((SecretKey) badKey);
KeyInfoCredentialResolver badEncResolver = new StaticKeyInfoCredentialResolver(encCred);
String filename = "/data/org/opensaml/saml2/encryption/Assertion.xml";
Assertion target = (Assertion) unmarshallElement(filename);
EncryptedAssertion encryptedTarget = encrypter.encrypt(target);
Decrypter decrypter = new Decrypter(badEncResolver, null, null);
SAMLObject decryptedTarget = null;
try {
decryptedTarget = decrypter.decrypt(encryptedTarget);
fail("Decryption should have failed due to bad decryption key");
} catch (DecryptionException e) {
// do nothing, should faile
}
}
示例15: parseSamlObject
import org.opensaml.xml.parse.XMLParserException; //导入依赖的package包/类
public static XMLObject parseSamlObject(String xmlInput)
throws XMLParserException, UnmarshallingException {
LOGGER.entering(SamlTool.class.getName(), "parseSamlObject", xmlInput);
StringReader reader = new StringReader(xmlInput);
// Parse metadata file
Document inCommonMDDoc = basicParserPool.parse(reader);
Element metadataRoot = inCommonMDDoc.getDocumentElement();
// Get apropriate unmarshaller
UnmarshallerFactory unmarshallerFactory = Configuration
.getUnmarshallerFactory();
Unmarshaller unmarshaller = unmarshallerFactory
.getUnmarshaller(metadataRoot);
// Unmarshall using the document root element, an EntitiesDescriptor in
// this case
XMLObject result = unmarshaller.unmarshall(metadataRoot);
LOGGER.exiting(SamlTool.class.getName(), "parseSamlObject", result);
return result;
}