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;
}
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());
}
}
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();
}
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");
}
}
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);
}
}
Aggregations