Search in sources :

Example 16 with Configuration

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

the class LdapUserAuthenticator method updateFromLdap.

private void updateFromLdap(User user, LdapEntry userEntry, LdapSettings ldapSettings, String username) {
    final String displayNameAttribute = ldapSettings.getDisplayNameAttribute();
    final String fullName = firstNonNull(userEntry.get(displayNameAttribute), username);
    user.setName(username);
    user.setFullName(fullName);
    user.setExternal(true);
    if (user.getTimeZone() == null) {
        user.setTimeZone(rootTimeZone);
    }
    final String email = userEntry.getEmail();
    if (isNullOrEmpty(email)) {
        LOG.debug("No email address found for user {} in LDAP. Using {}@localhost", username, username);
        user.setEmail(username + "@localhost");
    } else {
        user.setEmail(email);
    }
    // TODO This is a crude hack until we have a proper way to distinguish LDAP users from normal users
    if (isNullOrEmpty(user.getHashedPassword())) {
        ((UserImpl) user).setHashedPassword("User synced from LDAP.");
    }
    // map ldap groups to user roles, if the mapping is present
    final Set<String> translatedRoleIds = Sets.newHashSet(Sets.union(Sets.newHashSet(ldapSettings.getDefaultGroupId()), ldapSettings.getAdditionalDefaultGroupIds()));
    if (!userEntry.getGroups().isEmpty()) {
        // ldap search returned groups, these always override the ones set on the user
        try {
            final Map<String, Role> roleNameToRole = roleService.loadAllLowercaseNameMap();
            for (String ldapGroupName : userEntry.getGroups()) {
                final String roleName = ldapSettings.getGroupMapping().get(ldapGroupName);
                if (roleName == null) {
                    LOG.debug("User {}: No group mapping for ldap group <{}>", username, ldapGroupName);
                    continue;
                }
                final Role role = roleNameToRole.get(roleName.toLowerCase(Locale.ENGLISH));
                if (role != null) {
                    LOG.debug("User {}: Mapping ldap group <{}> to role <{}>", username, ldapGroupName, role.getName());
                    translatedRoleIds.add(role.getId());
                } else {
                    LOG.warn("User {}: No role found for ldap group <{}>", username, ldapGroupName);
                }
            }
        } catch (NotFoundException e) {
            LOG.error("Unable to load user roles", e);
        }
    } else if (ldapSettings.getGroupMapping().isEmpty() || ldapSettings.getGroupSearchBase().isEmpty() || ldapSettings.getGroupSearchPattern().isEmpty() || ldapSettings.getGroupIdAttribute().isEmpty()) {
        // no group mapping or configuration set, we'll leave the previously set groups alone on sync
        // when first creating the user these will be empty
        translatedRoleIds.addAll(user.getRoleIds());
    }
    user.setRoleIds(translatedRoleIds);
    // preserve the raw permissions (the ones without the synthetic self-edit permissions or the "*" admin one)
    user.setPermissions(user.getPermissions());
}
Also used : Role(org.graylog2.shared.users.Role) UserImpl(org.graylog2.users.UserImpl) NotFoundException(org.graylog2.database.NotFoundException)

Example 17 with Configuration

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

the class TimeBasedRotationStrategy method shouldRotate.

@Nullable
@Override
protected Result shouldRotate(String index, IndexSet indexSet) {
    final IndexSetConfig indexSetConfig = requireNonNull(indexSet.getConfig(), "Index set configuration must not be null");
    final String indexSetId = indexSetConfig.id();
    checkState(!isNullOrEmpty(index), "Index name must not be null or empty");
    checkState(!isNullOrEmpty(indexSetId), "Index set ID must not be null or empty");
    checkState(indexSetConfig.rotationStrategy() instanceof TimeBasedRotationStrategyConfig, "Invalid rotation strategy config <" + indexSetConfig.rotationStrategy().getClass().getCanonicalName() + "> for index set <" + indexSetId + ">");
    final TimeBasedRotationStrategyConfig config = (TimeBasedRotationStrategyConfig) indexSetConfig.rotationStrategy();
    final Period rotationPeriod = config.rotationPeriod().normalizedStandard();
    final DateTime now = Tools.nowUTC();
    // when first started, we might not know the last rotation time, look up the creation time of the index instead.
    if (!lastRotation.containsKey(indexSetId)) {
        final DateTime creationDate = indices.indexCreationDate(index);
        if (creationDate != null) {
            final DateTime currentAnchor = determineRotationPeriodAnchor(creationDate, rotationPeriod);
            anchor.put(indexSetId, currentAnchor);
            lastRotation.put(indexSetId, creationDate);
        }
        // still not able to figure out the last rotation time, we'll rotate forcibly
        if (!lastRotation.containsKey(indexSetId)) {
            return new SimpleResult(true, "No known previous rotation time, forcing index rotation now.");
        }
    }
    final DateTime currentAnchor = anchor.get(indexSetId);
    final DateTime nextRotation = currentAnchor.plus(rotationPeriod);
    if (nextRotation.isAfter(now)) {
        final String message = new MessageFormat("Next rotation at {0}", Locale.ENGLISH).format(new Object[] { nextRotation });
        return new SimpleResult(false, message);
    }
    // determine new anchor (push it to within less then one period before now) in case we missed one or more periods
    DateTime tmpAnchor;
    int multiplicator = 0;
    do {
        tmpAnchor = currentAnchor.withPeriodAdded(rotationPeriod, ++multiplicator);
    } while (tmpAnchor.isBefore(now));
    final DateTime nextAnchor = currentAnchor.withPeriodAdded(rotationPeriod, multiplicator - 1);
    anchor.put(indexSetId, nextAnchor);
    lastRotation.put(indexSetId, now);
    final String message = new MessageFormat("Rotation period {0} elapsed, next rotation at {1}", Locale.ENGLISH).format(new Object[] { now, nextAnchor });
    return new SimpleResult(true, message);
}
Also used : MessageFormat(java.text.MessageFormat) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) Nullable(javax.annotation.Nullable)

Example 18 with Configuration

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

the class AbstractIndexCountBasedRetentionStrategy method retain.

@Override
public void retain(IndexSet indexSet) {
    final Map<String, Set<String>> deflectorIndices = indexSet.getAllIndexAliases();
    final int indexCount = (int) deflectorIndices.keySet().stream().filter(indexName -> !indices.isReopened(indexName)).count();
    final Optional<Integer> maxIndices = getMaxNumberOfIndices(indexSet);
    if (!maxIndices.isPresent()) {
        LOG.warn("No retention strategy configuration found, not running index retention!");
        return;
    }
    // Do we have more indices than the configured maximum?
    if (indexCount <= maxIndices.get()) {
        LOG.debug("Number of indices ({}) lower than limit ({}). Not performing any retention actions.", indexCount, maxIndices.get());
        return;
    }
    // We have more indices than the configured maximum! Remove as many as needed.
    final int removeCount = indexCount - maxIndices.get();
    final String msg = "Number of indices (" + indexCount + ") higher than limit (" + maxIndices.get() + "). " + "Running retention for " + removeCount + " indices.";
    LOG.info(msg);
    activityWriter.write(new Activity(msg, IndexRetentionThread.class));
    runRetention(indexSet, deflectorIndices, removeCount);
}
Also used : Set(java.util.Set) IndexSet(org.graylog2.indexer.IndexSet) LinkedHashSet(java.util.LinkedHashSet) IndexRetentionThread(org.graylog2.periodical.IndexRetentionThread) Activity(org.graylog2.shared.system.activities.Activity)

Example 19 with Configuration

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

the class Server method getCommandBindings.

@Override
protected List<Module> getCommandBindings() {
    final ImmutableList.Builder<Module> modules = ImmutableList.builder();
    modules.add(new ConfigurationModule(configuration), new ServerBindings(configuration), new PersistenceServicesBindings(), new MessageFilterBindings(), new MessageProcessorModule(), new AlarmCallbackBindings(), new InitializerBindings(), new MessageOutputBindings(configuration, chainingClassLoader), new RotationStrategyBindings(), new RetentionStrategyBindings(), new PeriodicalBindings(), new ObjectMapperModule(chainingClassLoader), new RestApiBindings(), new PasswordAlgorithmBindings(), new WidgetStrategyBindings(), new DashboardBindings(), new DecoratorBindings(), new AuditBindings(), new AlertConditionBindings(), new IndexerBindings(), new MigrationsModule());
    return modules.build();
}
Also used : IndexerBindings(org.graylog2.indexer.IndexerBindings) PersistenceServicesBindings(org.graylog2.bindings.PersistenceServicesBindings) ImmutableList(com.google.common.collect.ImmutableList) ServerBindings(org.graylog2.bindings.ServerBindings) DecoratorBindings(org.graylog2.decorators.DecoratorBindings) ConfigurationModule(org.graylog2.bindings.ConfigurationModule) AlarmCallbackBindings(org.graylog2.bindings.AlarmCallbackBindings) ObjectMapperModule(org.graylog2.shared.bindings.ObjectMapperModule) MessageFilterBindings(org.graylog2.bindings.MessageFilterBindings) MessageProcessorModule(org.graylog2.messageprocessors.MessageProcessorModule) MessageOutputBindings(org.graylog2.bindings.MessageOutputBindings) AlertConditionBindings(org.graylog2.alerts.AlertConditionBindings) InitializerBindings(org.graylog2.bindings.InitializerBindings) WidgetStrategyBindings(org.graylog2.bindings.WidgetStrategyBindings) RotationStrategyBindings(org.graylog2.indexer.rotation.RotationStrategyBindings) AuditBindings(org.graylog2.audit.AuditBindings) DashboardBindings(org.graylog2.dashboards.DashboardBindings) Module(com.google.inject.Module) ConfigurationModule(org.graylog2.bindings.ConfigurationModule) MessageProcessorModule(org.graylog2.messageprocessors.MessageProcessorModule) ObjectMapperModule(org.graylog2.shared.bindings.ObjectMapperModule) MigrationsModule(org.graylog2.migrations.MigrationsModule) RetentionStrategyBindings(org.graylog2.indexer.retention.RetentionStrategyBindings) MigrationsModule(org.graylog2.migrations.MigrationsModule) PasswordAlgorithmBindings(org.graylog2.bindings.PasswordAlgorithmBindings) PeriodicalBindings(org.graylog2.bindings.PeriodicalBindings) RestApiBindings(org.graylog2.shared.bindings.RestApiBindings)

Example 20 with Configuration

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

the class ExposedConfigurationTest method testCreateWithConfiguration.

@Test
public void testCreateWithConfiguration() throws Exception {
    final Configuration configuration = new Configuration();
    final ExposedConfiguration c = ExposedConfiguration.create(configuration);
    assertThat(c.inputBufferProcessors()).isEqualTo(configuration.getInputbufferProcessors());
    assertThat(c.processBufferProcessors()).isEqualTo(configuration.getProcessBufferProcessors());
    assertThat(c.outputBufferProcessors()).isEqualTo(configuration.getOutputBufferProcessors());
    assertThat(c.processorWaitStrategy()).isEqualTo(configuration.getProcessorWaitStrategy().getClass().getName());
    assertThat(c.inputBufferWaitStrategy()).isEqualTo(configuration.getInputBufferWaitStrategy().getClass().getName());
    assertThat(c.inputBufferRingSize()).isEqualTo(configuration.getInputBufferRingSize());
    assertThat(c.ringSize()).isEqualTo(configuration.getRingSize());
    assertThat(c.pluginDir()).isEqualTo(configuration.getPluginDir());
    assertThat(c.nodeIdFile()).isEqualTo(configuration.getNodeIdFile());
    assertThat(c.allowHighlighting()).isEqualTo(configuration.isAllowHighlighting());
    assertThat(c.allowLeadingWildcardSearches()).isEqualTo(configuration.isAllowLeadingWildcardSearches());
    assertThat(c.streamProcessingTimeout()).isEqualTo(configuration.getStreamProcessingTimeout());
    assertThat(c.streamProcessingMaxFaults()).isEqualTo(configuration.getStreamProcessingMaxFaults());
    assertThat(c.outputModuleTimeout()).isEqualTo(configuration.getOutputModuleTimeout());
    assertThat(c.staleMasterTimeout()).isEqualTo(configuration.getStaleMasterTimeout());
    assertThat(c.gcWarningThreshold()).isEqualTo(configuration.getGcWarningThreshold().toString());
}
Also used : Configuration(org.graylog2.Configuration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8