use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class StaticFieldsResource method create.
@POST
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a static field to an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 400, message = "Field/Key is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.STATIC_FIELD_CREATE)
public Response create(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateStaticFieldRequest csfr) throws NotFoundException, ValidationException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
final MessageInput input = persistedInputs.get(inputId);
if (input == null) {
final String msg = "Input <" + inputId + "> not found.";
LOG.error(msg);
throw new javax.ws.rs.NotFoundException(msg);
}
// Check if key is a valid message key.
if (!Message.validKey(csfr.key())) {
final String msg = "Invalid key: [" + csfr.key() + "]";
LOG.error(msg);
throw new BadRequestException(msg);
}
if (Message.RESERVED_FIELDS.contains(csfr.key()) && !Message.RESERVED_SETTABLE_FIELDS.contains(csfr.key())) {
final String message = "Cannot add static field. Field [" + csfr.key() + "] is reserved.";
LOG.error(message);
throw new BadRequestException(message);
}
input.addStaticField(csfr.key(), csfr.value());
final Input mongoInput = inputService.find(input.getPersistId());
inputService.addStaticField(mongoInput, csfr.key(), csfr.value());
final String msg = "Added static field [" + csfr.key() + "] to input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, StaticFieldsResource.class));
final URI inputUri = getUriBuilderToSelf().path(InputsResource.class).path("{inputId}").build(mongoInput.getId());
return Response.created(inputUri).build();
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class LdapResource method readGroups.
@GET
@ApiOperation(value = "Get the available LDAP groups", notes = "")
@RequiresPermissions(RestPermissions.LDAPGROUPS_READ)
@Path("/groups")
@Produces(MediaType.APPLICATION_JSON)
public Set<String> readGroups() {
final LdapSettings ldapSettings = firstNonNull(ldapSettingsService.load(), ldapSettingsFactory.createEmpty());
if (!ldapSettings.isEnabled()) {
throw new BadRequestException("LDAP is disabled.");
}
if (isNullOrEmpty(ldapSettings.getGroupSearchBase()) || isNullOrEmpty(ldapSettings.getGroupIdAttribute())) {
throw new BadRequestException("LDAP group configuration settings are not set.");
}
final LdapConnectionConfig config = new LdapConnectionConfig();
final URI ldapUri = ldapSettings.getUri();
config.setLdapHost(ldapUri.getHost());
config.setLdapPort(ldapUri.getPort());
config.setUseSsl(ldapUri.getScheme().startsWith("ldaps"));
config.setUseTls(ldapSettings.isUseStartTls());
if (ldapSettings.isTrustAllCertificates()) {
config.setTrustManagers(new TrustAllX509TrustManager());
}
if (!isNullOrEmpty(ldapSettings.getSystemUserName()) && !isNullOrEmpty(ldapSettings.getSystemPassword())) {
config.setName(ldapSettings.getSystemUserName());
config.setCredentials(ldapSettings.getSystemPassword());
}
try (LdapNetworkConnection connection = ldapConnector.connect(config)) {
return ldapConnector.listGroups(connection, ldapSettings.getGroupSearchBase(), ldapSettings.getGroupSearchPattern(), ldapSettings.getGroupIdAttribute());
} catch (IOException | LdapException e) {
LOG.error("Unable to retrieve available LDAP groups", e);
throw new InternalServerErrorException("Unable to retrieve available LDAP groups", e);
}
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class LdapResource method updateLdapSettings.
@PUT
@Timed
@RequiresPermissions(RestPermissions.LDAP_EDIT)
@ApiOperation("Update the LDAP configuration")
@Path("/settings")
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.LDAP_CONFIGURATION_UPDATE)
public void updateLdapSettings(@ApiParam(name = "JSON body", required = true) @Valid @NotNull LdapSettingsRequest request) throws ValidationException {
// load the existing config, or create a new one. we only support having one, currently
final LdapSettings ldapSettings = firstNonNull(ldapSettingsService.load(), ldapSettingsFactory.createEmpty());
ldapSettings.setSystemUsername(request.systemUsername());
ldapSettings.setSystemPassword(request.systemPassword());
ldapSettings.setUri(request.ldapUri());
ldapSettings.setUseStartTls(request.useStartTls());
ldapSettings.setTrustAllCertificates(request.trustAllCertificates());
ldapSettings.setActiveDirectory(request.activeDirectory());
ldapSettings.setSearchPattern(request.searchPattern());
ldapSettings.setSearchBase(request.searchBase());
ldapSettings.setEnabled(request.enabled());
ldapSettings.setDisplayNameAttribute(request.displayNameAttribute());
ldapSettings.setDefaultGroup(request.defaultGroup());
ldapSettings.setGroupMapping(request.groupMapping());
ldapSettings.setGroupSearchBase(request.groupSearchBase());
ldapSettings.setGroupIdAttribute(request.groupIdAttribute());
ldapSettings.setGroupSearchPattern(request.groupSearchPattern());
ldapSettings.setAdditionalDefaultGroups(request.additionalDefaultGroups());
ldapSettingsService.save(ldapSettings);
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class MessageProcessorsResource method updateConfig.
@PUT
@Timed
@ApiOperation(value = "Update message processor configuration")
@Path("config")
@AuditEvent(type = AuditEventTypes.MESSAGE_PROCESSOR_CONFIGURATION_UPDATE)
public MessageProcessorsConfigWithDescriptors updateConfig(@ApiParam(name = "config", required = true) final MessageProcessorsConfigWithDescriptors configWithDescriptors) {
checkPermission(RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT);
final MessageProcessorsConfig config = configWithDescriptors.toConfig();
clusterConfigService.write(config.withProcessors(processorClassNames));
return configWithDescriptors;
}
use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.
the class ClusterConfigResource method update.
@PUT
@Timed
@Path("{configClass}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update configuration in database")
@RequiresPermissions({ RestPermissions.CLUSTER_CONFIG_ENTRY_CREATE, RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT })
@AuditEvent(type = AuditEventTypes.CLUSTER_CONFIGURATION_UPDATE)
public Response update(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass, @ApiParam(name = "body", value = "The payload of the cluster configuration", required = true) @NotNull InputStream body) throws IOException {
final Class<?> cls = classFromName(configClass);
if (cls == null) {
throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
}
final Object o;
try {
o = objectMapper.readValue(body, cls);
} catch (Exception e) {
final String msg = "Couldn't parse cluster configuration \"" + configClass + "\".";
LOG.error(msg, e);
throw new BadRequestException(msg);
}
try {
clusterConfigService.write(o);
} catch (Exception e) {
final String msg = "Couldn't write cluster config \"" + configClass + "\".";
LOG.error(msg, e);
throw new InternalServerErrorException(msg, e);
}
return Response.accepted(o).build();
}
Aggregations