Java Code Examples for org.wildfly.security.manager.WildFlySecurityManager#getClassLoaderPrivileged()

The following examples show how to use org.wildfly.security.manager.WildFlySecurityManager#getClassLoaderPrivileged() . 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: CliExtCommandHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void printHelp(CommandContext ctx) throws CommandLineException {
    String filename = "help/" + NAME + ".txt";
    ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(CliExtCommandHandler.class);
    InputStream helpInput = cl.getResourceAsStream(filename);
    if (helpInput != null) {
        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(helpInput, StandardCharsets.UTF_8))) {
            HelpFormatter.format(ctx, reader);
        } catch (java.io.IOException e) {
            throw new CommandFormatException("Failed to read help/help.txt: " + e.getLocalizedMessage());
        }
    } else {
        throw new CommandFormatException("Failed to locate command description " + filename);
    }
}
 
Example 2
Source File: ConnectorChildResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Perform remoting specific validation.
 * @param operation
 */
private void validateProperty(ModelNode operation) throws OperationFailedException {
    ModelNode addressModelNode = operation.get(ModelDescriptionConstants.ADDRESS);
    final ClassLoader loader = WildFlySecurityManager.getClassLoaderPrivileged(ConnectorChildResource.class);
    if (addressModelNode.isDefined()) {
        List<Property> propertyListModelNode = addressModelNode.asPropertyList();
        for (Property property : propertyListModelNode) {
            if (property.getName().equals(CommonAttributes.PROPERTY)) {
                ConnectorUtils.getAndValidateOption(loader, property.getValue().asString());
            }
        }
    }
}
 
Example 3
Source File: ConnectorUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void addOptions(OperationContext context, ModelNode properties, OptionMap.Builder builder) throws OperationFailedException {
    final ClassLoader loader = WildFlySecurityManager.getClassLoaderPrivileged(ConnectorUtils.class);
    for (Property property : properties.asPropertyList()) {
        final Option option = getAndValidateOption(loader, property.getName());
        String value = PropertyResource.VALUE.resolveModelAttribute(context, property.getValue()).asString();
        builder.set(option, option.parseValue(value, loader));
    }
}
 
Example 4
Source File: TemporaryModuleLayer.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static TemporaryModuleLayer create(PathFilter filter) {
    // We are running in a proper server, load the invoker normally
    final ModuleClassLoader classLoader =
            (ModuleClassLoader) WildFlySecurityManager.getClassLoaderPrivileged(TemporaryModuleLayer.class);
    final ModuleLoader systemLoader = classLoader.getModule().getModuleLoader();

    File[] roots = InternalLayeredModulePathFactory.resolveLayeredModulePath(getModulePathFiles());
    LocalModuleFinder cliModuleFinder = new LocalModuleFinder(roots, filter);
    DelegatingModuleLoader cliLoader = new DelegatingModuleLoader(systemLoader, cliModuleFinder);
    return new TemporaryModuleLayer(cliLoader, cliModuleFinder);
}
 
Example 5
Source File: SecurityManagerSubsystemAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method retrieves all security permissions contained within the specified node.
 *
 * @param context the {@link OperationContext} used to resolve the permission attributes.
 * @param node the {@link ModelNode} that might contain security permissions metadata.
 * @return a {@link List} containing the retrieved permissions. They are wrapped as {@link PermissionFactory} instances.
 * @throws OperationFailedException if an error occurs while retrieving the security permissions.
 */
private List<PermissionFactory> retrievePermissionSet(final OperationContext context, final ModelNode node) throws OperationFailedException {

    final List<PermissionFactory> permissions = new ArrayList<>();

    if (node != null && node.isDefined()) {
        for (ModelNode permissionNode : node.asList()) {
            String permissionClass = CLASS.resolveModelAttribute(context, permissionNode).asString();
            String permissionName = null;
            if (permissionNode.hasDefined(PERMISSION_NAME))
                permissionName = NAME.resolveModelAttribute(context, permissionNode).asString();
            String permissionActions = null;
            if (permissionNode.hasDefined(PERMISSION_ACTIONS))
                permissionActions = ACTIONS.resolveModelAttribute(context, permissionNode).asString();
            String moduleName = null;
            if(permissionNode.hasDefined(PERMISSION_MODULE)) {
                moduleName =  MODULE.resolveModelAttribute(context, permissionNode).asString();
            }
            ClassLoader cl = WildFlySecurityManager.getClassLoaderPrivileged(this.getClass());
            if(moduleName != null) {
                try {
                    cl = Module.getBootModuleLoader().loadModule(ModuleIdentifier.fromString(moduleName)).getClassLoader();
                } catch (ModuleLoadException e) {
                    throw new OperationFailedException(e);
                }
            }

            permissions.add(new LoadedPermissionFactory(cl,
                    permissionClass, permissionName, permissionActions));
        }
    }
    return permissions;
}