Java Code Examples for org.springframework.util.ResourceUtils#getURL()

The following examples show how to use org.springframework.util.ResourceUtils#getURL() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuditMethodInterceptorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    auditComponent = (AuditComponent) ctx.getBean("auditComponent");
    auditService = serviceRegistry.getAuditService();
    transactionService = serviceRegistry.getTransactionService();
    transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
    nodeService = serviceRegistry.getNodeService();
    searchService = serviceRegistry.getSearchService();

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

    // Register the models
    URL modelUrlMnt11072 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-11072.xml");
    URL modelUrlMnt16748 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-16748.xml");
    auditModelRegistry.registerModel(modelUrlMnt11072);
    auditModelRegistry.registerModel(modelUrlMnt16748);
    auditModelRegistry.loadAuditModels();
}
 
Example 2
Source File: AuditAppTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setup() throws Exception 
{
    super.setup();

    permissionService = applicationContext.getBean("permissionService", PermissionService.class);
    authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
    auditService = applicationContext.getBean("AuditService", AuditService.class);

    AuditModelRegistryImpl auditModelRegistry = (AuditModelRegistryImpl) applicationContext.getBean("auditModel.modelRegistry");

    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-access.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
}
 
Example 3
Source File: HttpClientProperties.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
public X509Certificate[] getTrustedX509CertificatesForTrustManager() {
	try {
		CertificateFactory certificateFactory = CertificateFactory
				.getInstance("X.509");
		ArrayList<Certificate> allCerts = new ArrayList<>();
		for (String trustedCert : getTrustedX509Certificates()) {
			try {
				URL url = ResourceUtils.getURL(trustedCert);
				Collection<? extends Certificate> certs = certificateFactory
						.generateCertificates(url.openStream());
				allCerts.addAll(certs);
			}
			catch (IOException e) {
				throw new WebServerException(
						"Could not load certificate '" + trustedCert + "'", e);
			}
		}
		return allCerts.toArray(new X509Certificate[allCerts.size()]);
	}
	catch (CertificateException e1) {
		throw new WebServerException("Could not load CertificateFactory X.509",
				e1);
	}
}
 
Example 4
Source File: HttpServletProtocolSpringAdapter.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
/**
 * Load key
 * @param type type
 * @param provider provider
 * @param resource resource
 * @param password password
 * @return KeyStore
 * @throws Exception Exception
 */
protected KeyStore loadKeyStore(String type, String provider, String resource,String password) throws Exception {
    if (resource == null) {
        return null;
    }
    type = (type != null) ? type : "JKS";
    KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type);
    URL url = ResourceUtils.getURL(resource);
    store.load(url.openStream(), (password == null) ? null : password.toCharArray());
    return store;
}
 
Example 5
Source File: UserAuditFilterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    auditComponent = (AuditComponent) ctx.getBean("auditComponent");
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionService = serviceRegistry.getTransactionService();
    
    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
}
 
Example 6
Source File: AuditBootstrapTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    auditModelRegistry.setProperty(AuditModelRegistryImpl.PROPERTY_AUDIT_CONFIG_STRICT, Boolean.TRUE.toString());
    
    // Register a new model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
}
 
Example 7
Source File: AuditBootstrapTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void loadBadModel(String url) throws Exception
{
    try
    {
        URL testModelUrl = ResourceUtils.getURL(url);
        auditModelRegistry.registerModel(testModelUrl);
        auditModelRegistry.loadAuditModels();
        fail("Expected model loading to fail.");
    }
    catch (AuditModelException e)
    {
        // Expected
        logger.error("Expected AuditModelException: " + e.getMessage());
    }
}
 
Example 8
Source File: ClassPathRule.java    From logback-access-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the class loader.
 *
 * @throws FileNotFoundException if the location is not found.
 */
private void setClassLoader() throws FileNotFoundException {
    URL[] urls = new URL[] { ResourceUtils.getURL(location) };
    classLoader = URLClassLoader.newInstance(urls, getDefaultClassLoader());
    originalClassLoader = overrideThreadContextClassLoader(classLoader);
    log.debug("Set the class loader: location=[{}], classLoader=[{}]", location);
}
 
Example 9
Source File: ArmeriaConfigurationUtil.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Nullable
private static KeyStore loadKeyStore(
        @Nullable String type,
        @Nullable String resource,
        @Nullable String password) throws IOException, GeneralSecurityException {
    if (resource == null) {
        return null;
    }
    final KeyStore store = KeyStore.getInstance(firstNonNull(type, "JKS"));
    final URL url = ResourceUtils.getURL(resource);
    store.load(url.openStream(), password != null ? password.toCharArray()
                                                  : null);
    return store;
}
 
Example 10
Source File: DataFileParserTest.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
static DataFileParser getDataFileParser(String fileName) throws Exception {
    URL testFile = ResourceUtils.getURL("classpath:" + fileName);
    return new DataFileParser(new File(testFile.toURI()));
}
 
Example 11
Source File: AuditComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    //MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
    UserAuditFilter userAuditFilter = new UserAuditFilter();
    userAuditFilter.setUserFilterPattern("~System;~null;.*");
    userAuditFilter.afterPropertiesSet();
    auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");
    auditComponent.setUserAuditFilter(userAuditFilter);
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    auditService = serviceRegistry.getAuditService();
    transactionService = serviceRegistry.getTransactionService();
    transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    
    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
    
    RunAsWork<NodeRef> testRunAs = new RunAsWork<NodeRef>()
    {
        public NodeRef doWork() throws Exception
        {
            return nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
        }
    };
    nodeRef = AuthenticationUtil.runAs(testRunAs, AuthenticationUtil.getSystemUserName());

    // Authenticate
    user = "User-" + getName();
    AuthenticationUtil.setFullyAuthenticatedUser(user);

    final RetryingTransactionCallback<Void> resetDisabledPathsCallback = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            auditComponent.resetDisabledPaths(APPLICATION_TEST);
            auditComponent.resetDisabledPaths(APPLICATION_ACTIONS_TEST);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(resetDisabledPathsCallback);
}
 
Example 12
Source File: AuditComponentTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test for MNT-10070 and MNT-14136
 */
public void testApplication() throws Exception
{
    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-10070.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
    
    auditModelRegistry.setProperty("audit.enabled", "true");

    auditModelRegistry.setProperty("audit.app1.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app1.default.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app1.login.user", "~System;~null;.*");

    auditModelRegistry.setProperty("audit.app2.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app2.default.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app2.login.user", "~System;~null;~admin;.*");

    auditModelRegistry.setProperty("audit.app3.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app3.default.enabled", "true");
    auditModelRegistry.setProperty("audit.filter.app3.login.user", "~System;~null;.*");
    
    auditModelRegistry.afterPropertiesSet();  
    
    AuthenticationUtil.setRunAsUserSystem();
    AuditApplication applicationOne = auditModelRegistry.getAuditApplicationByName(APPLICATION_ONE);
    assertNotNull("Application 'app1' dosn't exist", applicationOne);
    AuditApplication applicationTwo = auditModelRegistry.getAuditApplicationByName(APPLICATION_TWO);
    assertNotNull("Application 'app2' dosn't exist", applicationTwo);
    AuditApplication applicationThree = auditModelRegistry.getAuditApplicationByName(APPLICATION_THREE);
    assertNotNull("Application 'app3' dosn't exist", applicationThree);

    // auditComponent
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    PropertyAuditFilter filter = new PropertyAuditFilter();
    Properties properties = new Properties();
    properties.put("audit.enabled", "true");

    properties.put("audit.app1.enabled", "true");
    properties.put("audit.filter.app1.default.enabled", "true");
    properties.put("audit.filter.app1.default.user", "~System;~null;.*");

    properties.put("audit.app2.enabled", "true");
    properties.put("audit.filter.app2.default.enabled", "true");
    properties.put("audit.filter.app2.default.user", "~System;~null;~admin;.*");

    properties.put("audit.app3.enabled", "true");
    properties.put("audit.filter.app3.default.enabled", "true");
    properties.put("audit.filter.app3.default.user", "~System;~null;.*");

    filter.setProperties(properties);
    auditComponent.setAuditFilter(filter);

    Map<String, Serializable> auditMap = new HashMap<String, Serializable>();
    auditMap.put("/transaction/user", AuthenticationUtil.getFullyAuthenticatedUser());
    auditMap.put("/transaction/action", "CREATE");
    auditMap.put("/transaction/type", "cm:content");

    Map<String, Serializable> recordedAuditMap = auditComponent.recordAuditValues("/alfresco-access", auditMap);

    assertFalse("Audit values is empty.", recordedAuditMap.isEmpty());

    Map<String, Serializable> expected = new HashMap<String, Serializable>();
    // There should not be app2
    expected.put("/" + APPLICATION_ONE + "/transaction/action", "CREATE");
    expected.put("/" + APPLICATION_THREE + "/transaction/type", "cm:content");

    String failure = EqualsHelper.getMapDifferenceReport(recordedAuditMap, expected);
    if (failure != null)
    {
        fail(failure);
    }
}
 
Example 13
Source File: AuditWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ctx = getServer().getApplicationContext();
    //MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
    UserAuditFilter userAuditFilter = new UserAuditFilter();
    userAuditFilter.setUserFilterPattern("System;.*");
    userAuditFilter.afterPropertiesSet();
    AuditComponent auditComponent = (AuditComponent) ctx.getBean("auditComponent");
    auditComponent.setUserAuditFilter(userAuditFilter);
    AuditServiceImpl auditServiceImpl = (AuditServiceImpl) ctx.getBean("auditService");
    auditServiceImpl.setAuditComponent(auditComponent);
    authenticationService = (AuthenticationService) ctx.getBean("AuthenticationService");
    auditService = (AuditService) ctx.getBean("AuditService");
    searchService = (SearchService) ctx.getBean("SearchService");
    repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
    fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");
    admin = AuthenticationUtil.getAdminUserName();

    // Register the test models
    AuditModelRegistryImpl auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-repository.xml");
    URL testModelUrl1 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-16748.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.registerModel(testModelUrl1);
    auditModelRegistry.loadAuditModels();
    
    AuthenticationUtil.setFullyAuthenticatedUser(admin);
    
    wasGloballyEnabled = auditService.isAuditEnabled();
    wasRepoEnabled = auditService.isAuditEnabled(APP_REPOTEST_NAME, APP_REPOTEST_PATH);
    wasSearchEnabled = auditService.isAuditEnabled(APP_SEARCHTEST_NAME, APP_SEARCHTEST_PATH);
    // Only enable if required
    if (!wasGloballyEnabled)
    {
        auditService.setAuditEnabled(true);
        wasGloballyEnabled = auditService.isAuditEnabled();
        if (!wasGloballyEnabled)
        {
            fail("Failed to enable global audit for test");
        }
    }
    if (!wasRepoEnabled)
    {
        auditService.enableAudit(APP_REPOTEST_NAME, APP_REPOTEST_PATH);
        wasRepoEnabled = auditService.isAuditEnabled(APP_REPOTEST_NAME, APP_REPOTEST_PATH);
        if (!wasRepoEnabled)
        {
            fail("Failed to enable repo audit for test");
        }
    }
    if (!wasSearchEnabled)
    {
        auditService.enableAudit(APP_SEARCHTEST_NAME, APP_SEARCHTEST_PATH);
        wasSearchEnabled = auditService.isAuditEnabled(APP_SEARCHTEST_NAME, APP_SEARCHTEST_PATH);
        if (!wasSearchEnabled)
        {
            fail("Failed to enable search audit for test");
        }
    }
}
 
Example 14
Source File: RecoveryServiceTest.java    From halo with GNU General Public License v3.0 3 votes vote down vote up
private String getMigrationContent() throws IOException, URISyntaxException {
    URL migrationUrl = ResourceUtils.getURL(ResourceUtils.CLASSPATH_URL_PREFIX + "migration-test.json");

    Path path = Paths.get(migrationUrl.toURI());

    return new String(Files.readAllBytes(path));
}
 
Example 15
Source File: LogbackAccessContext.java    From logback-access-spring-boot-starter with Apache License 2.0 3 votes vote down vote up
/**
 * Configures by the configuration file.
 * Cause exceptions is not wrapped with {@link LogbackAccessConfigurationException}.
 * If configuration file is absent, throws an exception ({@link FileNotFoundException}).
 *
 * @param config the location of the configuration file.
 * @throws IOException if an I/O exception occurs.
 * @throws JoranException if a {@link JoranConfigurator} exception occurs.
 */
private void configureWithCauseThrowing(String config) throws IOException, JoranException {
    URL url = ResourceUtils.getURL(config);
    @Cleanup InputStream stream = url.openStream();
    LogbackAccessJoranConfigurator configurator = new LogbackAccessJoranConfigurator(environment);
    configurator.setContext(this);
    configurator.doConfigure(stream);
    log.info("Configured the Logback-access: context=[{}], config=[{}]", this, config);
}