private XMLObject unmarshallObject(String xmlString) throws UnmarshallingException, XMLParserException, UnsupportedEncodingException { BasicParserPool parser = new BasicParserPool(); parser.setNamespaceAware(true); /* Base64URL encoded */ byte bytes[] = xmlString.getBytes("utf-8"); if (bytes == null || bytes.length == 0) throw new InsufficientAuthenticationException("Invalid assertion encoding"); Reader reader = new InputStreamReader(new ByteArrayInputStream(bytes)); Document doc = parser.parse(reader); Element samlElement = doc.getDocumentElement(); UnmarshallerFactory unmarshallerFactory = Configuration.getUnmarshallerFactory(); Unmarshaller unmarshaller = unmarshallerFactory.getUnmarshaller(samlElement); if (unmarshaller == null) { throw new InsufficientAuthenticationException("Unsuccessful to unmarshal assertion string"); } return unmarshaller.unmarshall(samlElement); }
public Document parseString(String xmls) throws Exception{ try { InputStream in = new ByteArrayInputStream(xmls.getBytes()); document = parser.parse(in); } catch (XMLParserException e) { String mess = "XMLParser of string failed"; logger.error(mess,e); throw new Exception(mess); } return document; } }
public Document parseFile(File xmlf){ try { FileReader fileReader = new FileReader(xmlf); document = parser.parse(fileReader); } catch (FileNotFoundException e) { String mess = "Error reading file"; logger.error(mess,e); } catch (XMLParserException e) { String mess = "XMLParser of file failed"; logger.error(mess,e); } return document; } public Document parseString(String xmls) throws Exception{
// Initialize the library DefaultBootstrap.bootstrap(); // Get parser pool manager BasicParserPool ppMgr = new BasicParserPool(); ppMgr.setNamespaceAware(true); // Get org.w3c.dom.Document Object from response HttpURLConnection req = (HttpURLConnection) new URL("<saml-xml-url>").openConnection(); // Add some necessary headers for the request // req.addRequestProperty("...", "..."); // ... InputStream in = req.getInputStream(); Document inCommonMDDoc = ppMgr.parse(in); // Get the DOMSource from org.w3c.dom.Document Object DOMSource domSource=new DOMSource(document); //Add an extension schema via the code SAMLSchemaBuilder.addExtensionSchema(String schema) if necessary Schema schema = SAMLSchemaBuilder.getSAML11Schema(); // Get a Validator instance. Validator validator = schema.newValidator(); try { validator.validate(domSource); System.out.println("Result : Valid!"); } catch(Exception e) { System.out.println("Result : Invalid!"); }
String inCommonMDFile = "/data/org/opensaml/saml2/metadata/InCommon-metadata.xml"; // Initialize the library DefaultBootstrap.bootstrap(); // Get parser pool manager BasicParserPool ppMgr = new BasicParserPool(); ppMgr.setNamespaceAware(true); // Parse metadata file InputStream in = MetadataTest.class.getResourceAsStream(inCommonMDFile); Document inCommonMDDoc = ppMgr.parse(in); 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 EntitiesDescriptor inCommonMD = (EntitiesDescriptor) unmarshaller.unmarshall(metadataRoot);
assertionDocument = parser.parse(stringReader); }catch(XMLParserException e){ String message ="readSAML2AssertionFromString(String), Parsing failed";
/** * Loads a configuration file from an input stream. * * @param configurationStream configuration stream * * @throws ConfigurationException thrown if the given configuration is invalid or can not be read */ public void load(InputStream configurationStream) throws ConfigurationException { try { Document configuration = parserPool.parse(configurationStream); load(configuration); } catch (XMLParserException e) { log.error("Invalid configuration file", e); throw new ConfigurationException("Unable to create DocumentBuilder", e); } }
/** * Loads a configuration file from an input stream. * * @param configurationStream configuration stream * * @throws ConfigurationException thrown if the given configuration is invalid or can not be read */ public void load(InputStream configurationStream) throws ConfigurationException { try { Document configuration = parserPool.parse(configurationStream); load(configuration); } catch (XMLParserException e) { log.error("Invalid configuration file", e); throw new ConfigurationException("Unable to create DocumentBuilder", e); } }
assertionDocument = parser.parse(fileReader); }catch(XMLParserException e){ String message ="readSAML2AssertionFromFile(String), Parsing failed";
responseDocument = parser.parse(stringReader); }catch(XMLParserException e){ String message ="readSAML2ResponseFromString(String), Parsing failed";
saml2ResponseDocument = parser.parse(fileReader); }catch(XMLParserException e){ String message ="readSAML2ResponseFromFile(String), Parsing failed";
final Document doc = parsers.parse(new FileInputStream(metadataFile)); final Element root = doc.getDocumentElement();
Document doc = parsers.parse(inputStream); Element root = doc.getDocumentElement();
final Document doc = parsers.parse(new FileInputStream(metadataFile)); final Element root = doc.getDocumentElement();
Document doc = parsers.parse(inputStream); Element root = doc.getDocumentElement();