@Before public void setUp() throws Exception { binding = new SamlAssertionBinding(new BasicParserPool()); }
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); }
@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); } }
@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); }
@Before public void setup() throws Exception { samlTestUtils.initialize(); configurator = new SamlServiceProviderConfigurator(); configurator.setParserPool(new BasicParserPool()); generator = samlTestUtils.mockIdpMetadataGenerator(); providerProvisioning = mock(SamlServiceProviderProvisioning.class); configurator.setProviderProvisioning(providerProvisioning); metadataManager = new NonSnarlIdpMetadataManager(configurator); metadataManager.setGenerator(generator); metadataManager.setKeyManager(new ZoneAwareKeyManager()); }
protected SAMLMessageDecoder samlMessageDecoder() { final BasicParserPool basicParserPool = new BasicParserPool(); basicParserPool.setMaxPoolSize(maxParserPoolSize); return new HTTPPostSimpleSignDecoder(basicParserPool); }
DefaultBootstrap.bootstrap(); HTTPRedirectDeflateDecoder decode = new HTTPRedirectDeflateDecoder(new BasicParserPool()); BasicSAMLMessageContext<LogoutRequest, ?, ?> messageContext = new BasicSAMLMessageContext<LogoutRequest, SAMLObject, SAMLObject>(); messageContext.setInboundMessageTransport(new HttpServletRequestAdapter(request)); decode.decode(messageContext); XMLObjectBuilderFactory builderFactory = org.opensaml.Configuration.getBuilderFactory(); LogoutRequestBuilder logoutRequestBuilder = (LogoutRequestBuilder) builderFactory.getBuilder(LogoutRequest.DEFAULT_ELEMENT_NAME); LogoutRequest logoutRequest = logoutRequestBuilder.buildObject(); logoutRequest = (LogoutRequest) messageContext.getInboundMessage();
@BeforeEach public void setUp() throws Exception { bootstrap = new BootstrapSamlIdentityProviderData(); configurator = new SamlIdentityProviderConfigurator(); configurator.setParserPool(new BasicParserPool()); singleAdd = new SamlIdentityProviderDefinition() .setMetaDataLocation(String.format(BootstrapSamlIdentityProviderDataTests.xmlWithoutID, new RandomValueStringGenerator().generate())) .setIdpEntityAlias(singleAddAlias) .setNameID("sample-nameID") .setAssertionConsumerIndex(1) .setMetadataTrustCheck(true) .setLinkText("sample-link-test") .setIconUrl("sample-icon-url") .setZoneId("uaa"); singleAddWithoutHeader = new SamlIdentityProviderDefinition() .setMetaDataLocation(String.format(xmlWithoutHeader, new RandomValueStringGenerator().generate())) .setIdpEntityAlias(singleAddAlias) .setNameID("sample-nameID") .setAssertionConsumerIndex(1) .setMetadataTrustCheck(true) .setLinkText("sample-link-test") .setIconUrl("sample-icon-url") .setZoneId("uaa"); configurator.setIdentityProviderProvisioning(provisioning); fixedHttpMetaDataProvider = mock(FixedHttpMetaDataProvider.class); configurator.setFixedHttpMetaDataProvider(fixedHttpMetaDataProvider); }
_idpMetaDataProvider.setParserPool(new BasicParserPool()); _idpMetaDataProvider.initialize(); _timer.scheduleAtFixedRate(new MetadataRefreshTask(), 0, _refreshInterval * 1000);
/** Constructor. */ public BaseMessageDecoder() { parserPool = new BasicParserPool(); }
/** * @return parserPool or create a default one if none was provided */ public synchronized static ParserPool getPool() { if (pool == null) { setPool(new BasicParserPool()); } return pool; }
// 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);
/** * Generate metadata object from string * * @param metadataString * @return samlssoServiceProviderDO */ private EntityDescriptor generateMetadataObjectFromString(String metadataString) { EntityDescriptor entityDescriptor = null; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(metadataString.getBytes())); Element node = document.getDocumentElement(); DOMMetadataProvider idpMetaDataProvider = new DOMMetadataProvider(node); idpMetaDataProvider.setRequireValidMetadata(true); idpMetaDataProvider.setParserPool(new BasicParserPool()); idpMetaDataProvider.initialize(); XMLObject xmlObject = idpMetaDataProvider.getMetadata(); entityDescriptor = (EntityDescriptor) xmlObject; } catch (MetadataProviderException | SAXException | ParserConfigurationException | IOException e) { log.error("Error While reading Service Provider metadata xml", e); } return entityDescriptor; } }
/** * 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); } }
/** * 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); } }
/** * Generate metadata object from string * * @param metadataString * @return samlssoServiceProviderDO */ private EntityDescriptor generateMetadataObjectFromString(String metadataString) { EntityDescriptor entityDescriptor = null; try { DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(metadataString.getBytes())); Element node = document.getDocumentElement(); DOMMetadataProvider idpMetaDataProvider = new DOMMetadataProvider(node); idpMetaDataProvider.setRequireValidMetadata(true); idpMetaDataProvider.setParserPool(new BasicParserPool()); idpMetaDataProvider.initialize(); XMLObject xmlObject = idpMetaDataProvider.getMetadata(); entityDescriptor = (EntityDescriptor) xmlObject; } catch (MetadataProviderException | SAXException | ParserConfigurationException | IOException e) { log.error("Error While reading Service Provider metadata xml", e); } return entityDescriptor; } }
/** * Convert metadata String to entityDescriptor * * @param metadataString * @return EntityDescriptor */ private static EntityDescriptor generateMetadataObjectFromString(String metadataString) throws IdentityApplicationManagementException { EntityDescriptor entityDescriptor = null; try { DocumentBuilderFactory factory = IdentityUtil.getSecuredDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(metadataString.getBytes())); Element node = document.getDocumentElement(); DOMMetadataProvider idpMetaDataProvider = new DOMMetadataProvider(node); idpMetaDataProvider.setRequireValidMetadata(true); idpMetaDataProvider.setParserPool(new BasicParserPool()); idpMetaDataProvider.initialize(); XMLObject xmlObject = idpMetaDataProvider.getMetadata(); entityDescriptor = (EntityDescriptor) xmlObject; } catch (MetadataProviderException | SAXException | ParserConfigurationException | IOException e) { throw new IdentityApplicationManagementException("Error while converting file content to entity descriptor"); } return entityDescriptor; }
/** * 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); }
/** * Create a new SAMLClient, using the IdPConfig for endpoints and * validation. * * @param config * @throws org.adeptnet.auth.saml.SAMLException */ public SAMLClient(final SAMLConfig config) throws SAMLException { SAMLInit.initialize(); this.config = config; final BasicCredential _cred = new BasicCredential(); _cred.setEntityId(config.getIdPConfig().getEntityId()); _cred.setPublicKey(config.getIdPConfig().getCert().getPublicKey()); cred = _cred; sigValidator = new SignatureValidator(cred); // create xml parsers parsers = new BasicParserPool(); parsers.setNamespaceAware(true); }