Search in sources :

Example 1 with Plugin

use of org.graylog2.plugin.Plugin in project graylog2-server by Graylog2.

the class CmdLineTool method loadPlugins.

protected Set<Plugin> loadPlugins(String pluginPath, ChainingClassLoader chainingClassLoader) {
    final File pluginDir = new File(pluginPath);
    final Set<Plugin> plugins = new HashSet<>();
    final PluginLoader pluginLoader = new PluginLoader(pluginDir, chainingClassLoader);
    for (Plugin plugin : pluginLoader.loadPlugins()) {
        final PluginMetaData metadata = plugin.metadata();
        if (capabilities().containsAll(metadata.getRequiredCapabilities())) {
            if (version.sameOrHigher(metadata.getRequiredVersion())) {
                LOG.info("Loaded plugin: {}", plugin);
                plugins.add(plugin);
            } else {
                LOG.error("Plugin \"" + metadata.getName() + "\" requires version " + metadata.getRequiredVersion() + " - not loading!");
            }
        } else {
            LOG.debug("Skipping plugin \"{}\" because some capabilities are missing ({}).", metadata.getName(), Sets.difference(plugin.metadata().getRequiredCapabilities(), capabilities()));
        }
    }
    return plugins;
}
Also used : PluginMetaData(org.graylog2.plugin.PluginMetaData) File(java.io.File) PluginLoader(org.graylog2.shared.plugins.PluginLoader) HashSet(java.util.HashSet) Plugin(org.graylog2.plugin.Plugin)

Example 2 with Plugin

use of org.graylog2.plugin.Plugin in project graylog2-server by Graylog2.

the class PluginBindings method configure.

@Override
protected void configure() {
    final Multibinder<Plugin> pluginbinder = Multibinder.newSetBinder(binder(), Plugin.class);
    final Multibinder<PluginMetaData> pluginMetaDataBinder = Multibinder.newSetBinder(binder(), PluginMetaData.class);
    // Make sure there is a binding for the plugin rest resource classes to avoid binding errors when running
    // without plugins.
    MapBinder.newMapBinder(binder(), new TypeLiteral<String>() {
    }, new TypeLiteral<Class<? extends PluginRestResource>>() {
    }).permitDuplicates();
    // Make sure there is a binding for the PluginUISettingsProvider classes to avoid binding errors when running
    // without plugins
    MapBinder.newMapBinder(binder(), String.class, PluginUISettingsProvider.class).permitDuplicates();
    for (final Plugin plugin : plugins) {
        pluginbinder.addBinding().toInstance(plugin);
        for (final PluginModule pluginModule : plugin.modules()) {
            binder().install(pluginModule);
        }
        pluginMetaDataBinder.addBinding().toInstance(plugin.metadata());
    }
}
Also used : TypeLiteral(com.google.inject.TypeLiteral) PluginUISettingsProvider(org.graylog2.web.PluginUISettingsProvider) PluginMetaData(org.graylog2.plugin.PluginMetaData) PluginModule(org.graylog2.plugin.PluginModule) Plugin(org.graylog2.plugin.Plugin)

Example 3 with Plugin

use of org.graylog2.plugin.Plugin in project graylog2-server by Graylog2.

the class ServerBootstrap method runPreFlightChecks.

private void runPreFlightChecks(Set<Plugin> plugins) {
    final List<PreflightCheckModule> preflightCheckModules = plugins.stream().map(Plugin::preflightCheckModules).flatMap(Collection::stream).collect(Collectors.toList());
    final Injector injector = getPreflightInjector(preflightCheckModules);
    injector.getInstance(PreflightCheckService.class).runChecks();
}
Also used : Injector(com.google.inject.Injector) PreflightCheckService(org.graylog2.bootstrap.preflight.PreflightCheckService) PreflightCheckModule(org.graylog2.plugin.PreflightCheckModule) Plugin(org.graylog2.plugin.Plugin)

Example 4 with Plugin

use of org.graylog2.plugin.Plugin in project graylog2-server by Graylog2.

the class SessionsResource method newSession.

@POST
@ApiOperation(value = "Create a new session", notes = "This request creates a new session for a user or " + "reactivates an existing session: the equivalent of logging in.")
@NoAuditEvent("dispatches audit events in the method body")
public JsonNode newSession(@Context ContainerRequestContext requestContext, @ApiParam(name = "Login request", value = "Credentials. The default " + "implementation requires presence of two properties: 'username' and " + "'password'. However a plugin may customize which kind of credentials " + "are accepted and therefore expect different properties.", required = true) @NotNull JsonNode createRequest) {
    final SecurityContext securityContext = requestContext.getSecurityContext();
    if (!(securityContext instanceof ShiroSecurityContext)) {
        throw new InternalServerErrorException("Unsupported SecurityContext class, this is a bug!");
    }
    final ShiroSecurityContext shiroSecurityContext = (ShiroSecurityContext) securityContext;
    final ActorAwareAuthenticationToken authToken;
    try {
        authToken = tokenFactory.forRequestBody(createRequest);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage());
    }
    // we treat the BASIC auth username as the sessionid
    final String sessionId = shiroSecurityContext.getUsername();
    final String host = RestTools.getRemoteAddrFromRequest(grizzlyRequest, trustedSubnets);
    try {
        Optional<Session> session = sessionCreator.create(sessionId, host, authToken);
        if (session.isPresent()) {
            return sessionResponseFactory.forSession(session.get());
        } else {
            throw new NotAuthorizedException("Invalid credentials.", "Basic realm=\"Graylog Server session\"");
        }
    } catch (AuthenticationServiceUnavailableException e) {
        throw new ServiceUnavailableException("Authentication service unavailable");
    }
}
Also used : SecurityContext(javax.ws.rs.core.SecurityContext) ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext) ActorAwareAuthenticationToken(org.graylog2.shared.security.ActorAwareAuthenticationToken) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) AuthenticationServiceUnavailableException(org.graylog2.shared.security.AuthenticationServiceUnavailableException) AuthenticationServiceUnavailableException(org.graylog2.shared.security.AuthenticationServiceUnavailableException) ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext) Session(org.apache.shiro.session.Session) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 5 with Plugin

use of org.graylog2.plugin.Plugin in project graylog2-server by Graylog2.

the class ClusterSystemPluginResource method list.

@GET
@Timed
@ApiOperation(value = "List all installed plugins on the given node")
public PluginList list(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException {
    final Node targetNode = nodeService.byNodeId(nodeId);
    final RemoteSystemPluginResource remoteSystemPluginResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemPluginResource.class);
    final Response<PluginList> response = remoteSystemPluginResource.list().execute();
    if (response.isSuccessful()) {
        return response.body();
    } else {
        LOG.warn("Unable to get plugin list on node {}: {}", nodeId, response.message());
        throw new WebApplicationException(response.message(), BAD_GATEWAY);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Node(org.graylog2.cluster.Node) PluginList(org.graylog2.rest.models.system.plugins.responses.PluginList) RemoteSystemPluginResource(org.graylog2.shared.rest.resources.system.RemoteSystemPluginResource) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Plugin (org.graylog2.plugin.Plugin)6 PluginMetaData (org.graylog2.plugin.PluginMetaData)4 HashSet (java.util.HashSet)3 PluginLoader (org.graylog2.shared.plugins.PluginLoader)3 Injector (com.google.inject.Injector)2 ApiOperation (io.swagger.annotations.ApiOperation)2 PluginBindings (org.graylog2.shared.bindings.PluginBindings)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 Timed (com.codahale.metrics.annotation.Timed)1 JmxReporter (com.codahale.metrics.jmx.JmxReporter)1 InstrumentedAppender (com.codahale.metrics.log4j2.InstrumentedAppender)1 JadConfig (com.github.joschi.jadconfig.JadConfig)1 ParameterException (com.github.joschi.jadconfig.ParameterException)1 Repository (com.github.joschi.jadconfig.Repository)1 RepositoryException (com.github.joschi.jadconfig.RepositoryException)1 ValidationException (com.github.joschi.jadconfig.ValidationException)1 GuavaConverterFactory (com.github.joschi.jadconfig.guava.GuavaConverterFactory)1 NamedConfigParametersModule (com.github.joschi.jadconfig.guice.NamedConfigParametersModule)1 JodaTimeConverterFactory (com.github.joschi.jadconfig.jodatime.JodaTimeConverterFactory)1 EnvironmentRepository (com.github.joschi.jadconfig.repositories.EnvironmentRepository)1