Search in sources :

Example 1 with LocalModuleLoader

use of org.jboss.modules.LocalModuleLoader in project wildfly by wildfly.

the class HostExcludesTestCase method retrieveAvailableExtensions.

/**
 * Retrieve the list of all modules which export locally a resource that implements a org.jboss.as.controller.Extension.
 * This list is considered the list of all available extensions that can be added to a server.
 *
 * It is assumed that the module which is added as an extension has the org.jboss.as.controller.Extension service as
 * a local resource.
 */
private Set<String> retrieveAvailableExtensions() throws IOException {
    final Set<String> result = new HashSet<>();
    LocalModuleLoader ml = new LocalModuleLoader(getModuleRoots());
    Iterator<String> moduleNames = ml.iterateModules((String) null, true);
    while (moduleNames.hasNext()) {
        String moduleName = moduleNames.next();
        Module module;
        try {
            module = ml.loadModule(moduleName);
            List<Resource> resources = module.getClassLoader().loadResourceLocal("META-INF/services/org.jboss.as.controller.Extension");
            if (!resources.isEmpty()) {
                result.add(moduleName);
            }
        } catch (ModuleLoadException e) {
            Logger.getLogger(HostExcludesTestCase.class).warn("Failed to load module " + moduleName + " to check if it is an extension", e);
        }
    }
    return result;
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) Resource(org.jboss.modules.Resource) Module(org.jboss.modules.Module) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) HashSet(java.util.HashSet)

Example 2 with LocalModuleLoader

use of org.jboss.modules.LocalModuleLoader in project wildfly by wildfly.

the class PermissionParserExpressionsTestCase method test.

@Test
public void test() throws DeploymentUnitProcessingException {
    System.setProperty("CLASS_NAME", "java.io.FilePermission");
    System.setProperty("NAME_A", "A");
    System.setProperty("NAME_B", "B");
    System.setProperty("NAME_C", "C");
    System.setProperty("ACTION_READ", "read");
    File[] modulePaths = getModulePaths();
    LocalModuleLoader ml = new LocalModuleLoader(modulePaths);
    List<PermissionFactory> permissionFactories = parsePermissions(fileUnderTest, ml, identifier, functionExpand);
    Assert.assertEquals("Unexpected number of permissions", 3, permissionFactories.size());
    Permission permission = permissionFactories.get(0).construct();
    Assert.assertNotNull(permission);
    Assert.assertTrue("Unexpected permission class", permission instanceof FilePermission);
    Assert.assertEquals("Unexpected permission name", permission.getName(), "A");
    Assert.assertEquals("Unexpected permission action", permission.getActions(), "read");
    permission = permissionFactories.get(1).construct();
    Assert.assertNotNull(permission);
    Assert.assertTrue("Unexpected permission class", permission instanceof FilePermission);
    Assert.assertEquals("Unexpected permission name", permission.getName(), "B");
    Assert.assertEquals("Unexpected permission action", permission.getActions(), "read");
    permission = permissionFactories.get(2).construct();
    Assert.assertNotNull(permission);
    Assert.assertTrue("Unexpected permission class", permission instanceof FilePermission);
    Assert.assertEquals("Unexpected permission name", permission.getName(), "C");
    Assert.assertEquals("Unexpected permission action", permission.getActions(), "write");
}
Also used : PermissionFactory(org.jboss.modules.security.PermissionFactory) FilePermission(java.io.FilePermission) Permission(java.security.Permission) File(java.io.File) FilePermission(java.io.FilePermission) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) Test(org.junit.Test)

Example 3 with LocalModuleLoader

use of org.jboss.modules.LocalModuleLoader in project jboss-modules by jboss-modules.

the class PermissionsTest method setupModuleLoader.

@Before
public void setupModuleLoader() throws Exception {
    System.setProperty("jboss.home.dir", JBOSS_HOME_DIR_VALUE);
    final File repoRoot = getResource("test/repo");
    moduleLoader = new LocalModuleLoader(new File[] { repoRoot });
}
Also used : File(java.io.File) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) Before(org.junit.Before)

Aggregations

LocalModuleLoader (org.jboss.modules.LocalModuleLoader)3 File (java.io.File)2 FilePermission (java.io.FilePermission)1 Permission (java.security.Permission)1 HashSet (java.util.HashSet)1 Module (org.jboss.modules.Module)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 Resource (org.jboss.modules.Resource)1 PermissionFactory (org.jboss.modules.security.PermissionFactory)1 Before (org.junit.Before)1 Test (org.junit.Test)1