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); }
protected SAMLMessageDecoder samlMessageDecoder() { final BasicParserPool basicParserPool = new BasicParserPool(); basicParserPool.setMaxPoolSize(maxParserPoolSize); return new HTTPPostSimpleSignDecoder(basicParserPool); }
@Before public void setUp() throws Exception { binding = new SamlAssertionBinding(new BasicParserPool()); }
BasicParserPool parserPool = new BasicParserPool(); parserPool.setNamespaceAware(true);
/** * Constructor. * * @param retainXML whether to retain the XML configuration elements within the {@link Configuration}. * * @throws ConfigurationException thrown if the validation schema for configuration files can not be created * * @deprecated this method will be removed once {@link Configuration} no longer has the option to store the XML configuration fragements */ public XMLConfigurator(boolean retainXML) throws ConfigurationException { retainXMLConfiguration = retainXML; parserPool = new BasicParserPool(); SchemaFactory factory = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Source schemaSource = new StreamSource(XMLConfigurator.class .getResourceAsStream(XMLConstants.XMLTOOLING_SCHEMA_LOCATION)); try { configurationSchema = factory.newSchema(schemaSource); parserPool.setIgnoreComments(true); parserPool.setIgnoreElementContentWhitespace(true); parserPool.setSchema(configurationSchema); } catch (SAXException e) { throw new ConfigurationException("Unable to read XMLTooling configuration schema", e); } }
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; } }
/** {@inheritDoc} */ public Document newDocument() throws XMLParserException { DocumentBuilder builder = getBuilder(); Document document = builder.newDocument(); returnBuilder(builder); return document; }
/** {@inheritDoc} */ public synchronized void setSchema(Schema newSchema) { schema = newSchema; if (schema != null) { setNamespaceAware(true); builderAttributes.remove("http://java.sun.com/xml/jaxp/properties/schemaSource"); builderAttributes.remove("http://java.sun.com/xml/jaxp/properties/schemaLanguage"); } dirtyBuilderConfiguration = true; }
private Response parseResponse(String authnResponse) throws SAMLException { try { final Document doc = parsers.getBuilder() .parse(new InputSource(new StringReader(authnResponse))); final Element root = doc.getDocumentElement(); return (Response) Configuration.getUnmarshallerFactory() .getUnmarshaller(root) .unmarshall(root); } catch (org.opensaml.xml.parse.XMLParserException | org.opensaml.xml.io.UnmarshallingException | org.xml.sax.SAXException | java.io.IOException e) { throw new SAMLException(e); } }
/** Constructor. */ public BasicParserPool() { maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); try { dirtyBuilderConfiguration = true; initializePool(); } catch (XMLParserException e) { // default settings, no parsing exception } }
@Test public void testDoGetMetadata() throws Exception { String metadataString = new Scanner(new File("../uaa/src/main/resources/idp.xml")).useDelimiter("\\Z").next(); ConfigMetadataProvider provider = new ConfigMetadataProvider(IdentityZone.getUaa().getId(), "testalias", metadataString); ConfigMetadataProvider provider2 = new ConfigMetadataProvider(IdentityZone.getUaa().getId(), "testalias", metadataString); DefaultBootstrap.bootstrap(); provider.setParserPool(new BasicParserPool()); XMLObject xmlObject = provider.doGetMetadata(); assertNotNull(xmlObject); assertEquals("http://openam.example.com:8181/openam", ((EntityDescriptorImpl) xmlObject).getEntityID()); assertEquals(provider, provider2); } }
/** * Create a new SAMLClient, using the IdPConfig for * endpoints and validation. */ public SAMLClient(SPConfig spConfig, IdPConfig idpConfig) throws SAMLException { this.spConfig = spConfig; this.idpConfig = idpConfig; BasicCredential cred = new BasicCredential(); cred.setEntityId(idpConfig.getEntityId()); cred.setPublicKey(idpConfig.getCert().getPublicKey()); sigValidator = new SignatureValidator(cred); // create xml parsers parsers = new BasicParserPool(); parsers.setNamespaceAware(true); }
/** * Constructor. * * @param retainXML whether to retain the XML configuration elements within the {@link Configuration}. * * @throws ConfigurationException thrown if the validation schema for configuration files can not be created * * @deprecated this method will be removed once {@link Configuration} no longer has the option to store the XML configuration fragements */ public XMLConfigurator(boolean retainXML) throws ConfigurationException { retainXMLConfiguration = retainXML; parserPool = new BasicParserPool(); SchemaFactory factory = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Source schemaSource = new StreamSource(XMLConfigurator.class .getResourceAsStream(XMLConstants.XMLTOOLING_SCHEMA_LOCATION)); try { configurationSchema = factory.newSchema(schemaSource); parserPool.setIgnoreComments(true); parserPool.setIgnoreElementContentWhitespace(true); parserPool.setSchema(configurationSchema); } catch (SAXException e) { throw new ConfigurationException("Unable to read XMLTooling configuration schema", e); } }
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{
/** {@inheritDoc} */ public Document newDocument() throws XMLParserException { DocumentBuilder builder = getBuilder(); Document document = builder.newDocument(); returnBuilder(builder); return document; }
/** {@inheritDoc} */ public synchronized void setSchema(Schema newSchema) { schema = newSchema; if (schema != null) { setNamespaceAware(true); builderAttributes.remove("http://java.sun.com/xml/jaxp/properties/schemaSource"); builderAttributes.remove("http://java.sun.com/xml/jaxp/properties/schemaLanguage"); } dirtyBuilderConfiguration = true; }
private Response parseResponse(String authnResponse) throws SAMLException { try { Document doc = parsers.getBuilder() .parse(new InputSource(new StringReader(authnResponse))); Element root = doc.getDocumentElement(); return (Response) Configuration.getUnmarshallerFactory() .getUnmarshaller(root) .unmarshall(root); } catch (org.opensaml.xml.parse.XMLParserException e) { throw new SAMLException(e); } catch (org.opensaml.xml.io.UnmarshallingException e) { throw new SAMLException(e); } catch (org.xml.sax.SAXException e) { throw new SAMLException(e); } catch (java.io.IOException e) { throw new SAMLException(e); } }
/** Constructor. */ public BasicParserPool() { maxPoolSize = 5; builderPool = new Stack<SoftReference<DocumentBuilder>>(); builderAttributes = new LazyMap<String, Object>(); coalescing = true; expandEntityReferences = false; builderFeatures = buildDefaultFeatures(); ignoreComments = true; ignoreElementContentWhitespace = true; namespaceAware = true; schema = null; dtdValidating = false; xincludeAware = false; errorHandler = new LoggingErrorHandler(log); try { dirtyBuilderConfiguration = true; initializePool(); } catch (XMLParserException e) { // default settings, no parsing exception } }
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);
@Before public void setupSamlSpConfAndSlowHttpServer() throws Exception { samlTestUtils.initialize(); conf = new SamlServiceProviderConfigurator(); providerProvisioning = mock(SamlServiceProviderProvisioning.class); conf.setProviderProvisioning(providerProvisioning); conf.setParserPool(new BasicParserPool()); slowHttpServer = new SlowHttpServer(); TimeService mockTimeService = mock(TimeService.class); when(mockTimeService.getCurrentTimeMillis()).thenAnswer(e -> System.currentTimeMillis()); RestTemplateConfig restTemplateConfig = new RestTemplateConfig(); restTemplateConfig.timeout = 120; FixedHttpMetaDataProvider fixedHttpMetaDataProvider = new FixedHttpMetaDataProvider(); fixedHttpMetaDataProvider.setNonTrustingRestTemplate(restTemplateConfig.nonTrustingRestTemplate()); fixedHttpMetaDataProvider.setTrustingRestTemplate(restTemplateConfig.trustingRestTemplate()); fixedHttpMetaDataProvider.setCache(new ExpiringUrlCache(Duration.ofMinutes(10), mockTimeService, 2)); conf.setFixedHttpMetaDataProvider(fixedHttpMetaDataProvider); }