/** * Resolve metadata from resource. * * @param service the service * @param metadataResolvers the metadata resolvers * @throws Exception the io exception */ protected void resolveMetadataFromResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers) throws Exception { final String metadataLocation = service.getMetadataLocation(); LOGGER.info("Loading SAML metadata from [{}]", metadataLocation); final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation); if (metadataResource instanceof FileSystemResource) { resolveFileSystemBasedMetadataResource(service, metadataResolvers, metadataResource); } if (metadataResource instanceof UrlResource) { resolveUrlBasedMetadataResource(service, metadataResolvers, metadataResource); } if (metadataResource instanceof ClassPathResource) { resolveClasspathBasedMetadataResource(service, metadataResolvers, metadataLocation, metadataResource); } }
private void resolveClasspathBasedMetadataResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers, final String metadataLocation, final AbstractResource metadataResource) { try (InputStream in = metadataResource.getInputStream()) { LOGGER.debug("Parsing metadata from [{}]", metadataLocation); final Document document = this.configBean.getParserPool().parse(in); final Element metadataRoot = document.getDocumentElement(); final DOMMetadataResolver metadataProvider = new DOMMetadataResolver(metadataRoot); buildSingleMetadataResolver(metadataProvider, service); metadataResolvers.add(metadataProvider); } catch (final Exception e) { throw Throwables.propagate(e); } }
private void resolveUrlBasedMetadataResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers, final AbstractResource metadataResource) throws Exception { final SamlIdPProperties.Metadata md = casProperties.getAuthn().getSamlIdp().getMetadata(); final File backupDirectory = new File(md.getLocation().getFile(), "metadata-backups"); final File backupFile = new File(backupDirectory, metadataResource.getFilename()); LOGGER.debug("Metadata backup directory is designated to be [{}]", backupDirectory.getCanonicalPath()); FileUtils.forceMkdir(backupDirectory); LOGGER.debug("Metadata backup file will be at [{}]", backupFile.getCanonicalPath()); FileUtils.forceMkdirParent(backupFile); final HttpClientMultithreadedDownloader downloader = new HttpClientMultithreadedDownloader(metadataResource, backupFile); final FileBackedHTTPMetadataResolver metadataProvider = new FileBackedHTTPMetadataResolver( this.httpClient.getWrappedHttpClient(), metadataResource.getURL().toExternalForm(), backupFile.getCanonicalPath()); buildSingleMetadataResolver(metadataProvider, service); metadataResolvers.add(metadataProvider); }
@Test public void testFirstFound() throws Exception { this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND); this.factory.setResources(new AbstractResource() { @Override public String getDescription() { return "non-existent"; } @Override public InputStream getInputStream() throws IOException { throw new IOException("planned"); } }, new ByteArrayResource("foo:\n spam: bar".getBytes())); assertEquals(1, this.factory.getObject().size()); }
public AuthenticationManager(AbstractResource properties, AbstractResource configuration) throws RemoteException { try { BeanUtils utils = new BeanUtils(configuration, properties); this.auth = utils.getAuthenticationProvider(); Set<QName> set = this.auth.getSupportedAuthenticationProfiles(); if ((set == null) || (set.size() < 1)) { throw new Exception( "The authentication provider must support at least 1 valid authentication profile."); } else if (!AuthenticationProfile.isValid(set)) { throw new Exception( "The authentication provider supports an unknown authentication profile."); } } catch (Exception ex) { throw new RemoteException( "Error instantiating AuthenticationProvider: " + ex.getMessage(), ex); } }
private void resolveFileSystemBasedMetadataResource(final SamlRegisteredService service, final List<MetadataResolver> metadataResolvers, final AbstractResource metadataResource) throws Exception { final File metadataFile = metadataResource.getFile(); final AbstractMetadataResolver metadataResolver; if (metadataFile.isDirectory()) { metadataResolver = new LocalDynamicMetadataResolver(new FilesystemLoadSaveManager<>(metadataFile, configBean.getParserPool())); } else { metadataResolver = new ResourceBackedMetadataResolver(ResourceHelper.of(metadataResource)); } buildSingleMetadataResolver(metadataResolver, service); metadataResolvers.add(metadataResolver); }
/** * Gets resource from a String location. * * @param location the metadata location * @return the resource from * @throws IOException the exception */ public static AbstractResource getResourceFrom(final String location) throws IOException { final AbstractResource metadataLocationResource = getRawResourceFrom(location); if (!metadataLocationResource.exists() || !metadataLocationResource.isReadable()) { throw new FileNotFoundException("Resource " + location + " does not exist or is unreadable"); } return metadataLocationResource; }
public CompensablePropertySource(String name, EncodedResource source) { super(name, source); EncodedResource encoded = (EncodedResource) this.getSource(); AbstractResource resource = (AbstractResource) encoded.getResource(); String path = resource.getFilename(); if (StringUtils.isBlank(path)) { return; } String[] values = path.split(":"); if (values.length != 2) { return; } String protocol = values[0]; String resName = values[1]; if ("bytetcc".equalsIgnoreCase(protocol) == false) { return; } else if ("loadbalancer.config".equalsIgnoreCase(resName) == false) { return; } this.enabled = true; }
/** * Intelligently sets the property to the merged set of properties. * <p> * The key "MANAGER.PROPERTIES" can be used in a properties file to refer to * the entire set of merged properties. This is normally what you want to pass * into other systems (such as Spring) that need a set of properties. * * @param bean the bean, not null * @param mp the property, not null * @throws Exception allowing throwing of a checked exception */ protected void setPropertyMergedProperties(Bean bean, MetaProperty<?> mp) throws Exception { final String desc = MANAGER_PROPERTIES + " for " + mp; final ByteArrayOutputStream out = new ByteArrayOutputStream(1024); Properties props = new Properties(); props.putAll(getProperties().toMap()); props.store(out, desc); out.close(); Resource resource = new AbstractResource() { @Override public String getDescription() { return MANAGER_PROPERTIES; } @Override public String getFilename() throws IllegalStateException { return MANAGER_PROPERTIES + ".properties"; } @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(out.toByteArray()); } @Override public String toString() { return desc; } }; mp.set(bean, resource); }
public TransactionPropertySource(String name, EncodedResource source) { super(name, source); EncodedResource encoded = (EncodedResource) this.getSource(); AbstractResource resource = (AbstractResource) encoded.getResource(); String path = resource.getFilename(); if (StringUtils.isBlank(path)) { return; } String[] values = path.split(":"); if (values.length != 2) { return; } String protocol = values[0]; String resName = values[1]; if ("bytejta".equalsIgnoreCase(protocol) == false) { return; } else if ("loadbalancer.config".equalsIgnoreCase(resName) == false) { return; } this.enabled = true; }
private void addFile(int executionId, String uid, AbstractResource resource) { LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("file", resource); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>( map, headers); template.exchange(base.toString() + "executions/" + executionId + "/details/" + uid + "/file/", HttpMethod.POST, requestEntity, Void.class); }
private String render(AbstractResource resource, Map<String, Object> model, Locale locale, TemplateOutput templateOutput) { try { ModelAndView mv = new ModelAndView((String) null, model); mv.addObject("format-date", MustacheCustomTagInterceptor.FORMAT_DATE); mv.addObject(MustacheLocalizationMessageInterceptor.DEFAULT_MODEL_KEY, new CustomLocalizationMessageInterceptor(locale, messageSource).createTranslator()); return compile(resource, templateOutput).execute(mv.getModel()); } catch (Exception e) { throw new IllegalStateException(e); } }
private Template compile(AbstractResource resource, TemplateOutput templateOutput) { try (InputStreamReader tmpl = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) { return compilers.get(templateOutput).compile(tmpl); } catch (IOException ioe) { throw new IllegalStateException(ioe); } }
/** * Use this if the keystore also contains keys. Left side is the alias, right side is the key password. The key * password can be the same as that of the keystore itself. */ @SafeVarargs public Keystore(AbstractResource keystore, String keystorePassword, Pair<String, String>... keyAliasPasswords) { this.keystore = keystore; this.keystorePassword = keystorePassword; this.keyAliasPasswords = Arrays.asList(keyAliasPasswords); }
public BeanUtils(AbstractResource conf, AbstractResource properties) throws Exception { this.factory = new XmlBeanFactory(conf); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(properties); cfg.postProcessBeanFactory(factory); }
public SpringUtils(AbstractResource conf, Properties properties) { this.context = new XmlBeanFactory(conf); if (properties != null) { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setProperties(properties); cfg.postProcessBeanFactory(context); } }
public SpringUtils(AbstractResource conf, AbstractResource properties) { this.context = new XmlBeanFactory(conf); if (properties != null) { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(properties); cfg.postProcessBeanFactory(context); } }
public static AbstractApplicationContext loadContext(String contextKey, String contextConfigurationPath) throws IOException { StaticApplicationContext context = new StaticApplicationContext(); AbstractResource contextConfigurationResource = (AbstractResource) getAndPruneResource( context, contextKey, contextConfigurationPath); context.close(); AbstractApplicationContext applicationContext = new FileSystemXmlApplicationContext( contextConfigurationResource.getURL().toString()); return applicationContext; }
public AbstractResource getTrustStoreResource() { return new ClassPathResource(TRUSTSTORE_PATH); }
/** * Use this if the keystore contains only certificates */ public Keystore(AbstractResource keystore, String keystorePassword) { this.keystore = keystore; this.keystorePassword = keystorePassword; }
public AbstractResource getKeystore() { return keystore; }
public BeanUtils(AbstractResource dorianConf, AbstractResource dorianProperties) throws DorianInternalFault { this.factory = new XmlBeanFactory(dorianConf); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(dorianProperties); cfg.postProcessBeanFactory(factory); }
public UpgradeBeanUtils(AbstractResource upgraderConf) throws DorianInternalFault { this.factory = new XmlBeanFactory(upgraderConf); }
public static BeanUtils getBeanUtils(AbstractResource properties) throws Exception { ClassPathResource cpr = new ClassPathResource(Constants.DORIAN_CONFIGURATION); return new BeanUtils(cpr, properties); }
public BeanUtils(AbstractResource dorianConf, AbstractResource dorianProperties) throws Exception { this.factory = new XmlBeanFactory(dorianConf); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.setLocation(dorianProperties); cfg.postProcessBeanFactory(factory); }
public UpgradeBeanUtils(AbstractResource upgraderConf) throws DorianInternalException { this.factory = new XmlBeanFactory(upgraderConf); }
/** * Build signature validation filter if needed. * * @param signatureResourceLocation the signature resource location * @return the metadata filter * @throws Exception the exception */ public static SignatureValidationFilter buildSignatureValidationFilter(final String signatureResourceLocation) throws Exception { final AbstractResource resource = ResourceUtils.getResourceFrom(signatureResourceLocation); return buildSignatureValidationFilter(resource); }