Search in sources :

Example 21 with Configuration

use of org.apache.commons.configuration2.Configuration in project hadoop by apache.

the class AzureBlobStorageTestAccount method createAnonymous.

public static AzureBlobStorageTestAccount createAnonymous(final String blobName, final int fileSize) throws Exception {
    NativeAzureFileSystem fs = null;
    CloudBlobContainer container = null;
    Configuration conf = createTestConfiguration(), noTestAccountConf = new Configuration();
    // Set up a session with the cloud blob client to generate SAS and check the
    // existence of a container and capture the container object.
    CloudStorageAccount account = createTestAccount(conf);
    if (account == null) {
        return null;
    }
    CloudBlobClient blobClient = account.createCloudBlobClient();
    // Capture the account URL and the account name.
    String accountName = conf.get(TEST_ACCOUNT_NAME_PROPERTY_NAME);
    configureSecureModeTestSettings(conf);
    // Generate a container name and create a shared access signature string for
    // it.
    //
    String containerName = generateContainerName();
    // Set up public container with the specified blob name.
    primePublicContainer(blobClient, accountName, containerName, blobName, fileSize);
    // Capture the blob container object. It should exist after generating the
    // shared access signature.
    container = blobClient.getContainerReference(containerName);
    if (null == container || !container.exists()) {
        final String errMsg = String.format("Container '%s' expected but not found while creating SAS account.");
        throw new Exception(errMsg);
    }
    // Set the account URI.
    URI accountUri = createAccountUri(accountName, containerName);
    // Initialize the Native Azure file system with anonymous credentials.
    fs = new NativeAzureFileSystem();
    fs.initialize(accountUri, noTestAccountConf);
    // Create test account initializing the appropriate member variables.
    AzureBlobStorageTestAccount testAcct = new AzureBlobStorageTestAccount(fs, account, container);
    // Return to caller with test account.
    return testAcct;
}
Also used : SubsetConfiguration(org.apache.commons.configuration2.SubsetConfiguration) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 22 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetPermissionsForUser.

@Test
public void testGetPermissionsForUser() throws Exception {
    final InMemoryRolePermissionResolver permissionResolver = mock(InMemoryRolePermissionResolver.class);
    final UserService userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionResolver);
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    user.setName("user");
    final Role role = createRole("Foo");
    user.setRoleIds(Collections.singleton(role.getId()));
    user.setPermissions(Collections.singletonList("hello:world"));
    when(permissionResolver.resolveStringPermission(role.getId())).thenReturn(Collections.singleton("foo:bar"));
    assertThat(userService.getPermissionsForUser(user)).containsOnly("users:passwordchange:user", "users:edit:user", "foo:bar", "hello:world");
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) UserService(org.graylog2.shared.users.UserService) InMemoryRolePermissionResolver(org.graylog2.security.InMemoryRolePermissionResolver) Test(org.junit.Test)

Example 23 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetRoleNames.

@Test
public void testGetRoleNames() throws Exception {
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    final Role role = createRole("Foo");
    final ImmutableMap<String, Role> map = ImmutableMap.<String, Role>builder().put(role.getId(), role).build();
    when(roleService.loadAllIdMap()).thenReturn(map);
    assertThat(userService.getRoleNames(user)).isEmpty();
    user.setRoleIds(Sets.newHashSet(role.getId()));
    assertThat(userService.getRoleNames(user)).containsOnly("Foo");
    when(roleService.loadAllIdMap()).thenReturn(new HashMap<>());
    assertThat(userService.getRoleNames(user)).isEmpty();
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) Test(org.junit.Test)

Example 24 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class BlockingBatchedESOutputTest method setUp.

@Before
public void setUp() throws Exception {
    this.metricRegistry = new MetricRegistry();
    this.journal = new NoopJournal();
    this.config = new Configuration() {

        @Override
        public int getOutputBatchSize() {
            return 3;
        }
    };
}
Also used : Configuration(org.graylog2.Configuration) NoopJournal(org.graylog2.shared.journal.NoopJournal) MetricRegistry(com.codahale.metrics.MetricRegistry) Before(org.junit.Before)

Example 25 with Configuration

use of org.apache.commons.configuration2.Configuration in project graylog2-server by Graylog2.

the class LdapUserAuthenticatorTest method setUp.

@Before
public void setUp() throws Exception {
    server = getLdapServer();
    final LdapConnectionConfig ldapConfig = new LdapConnectionConfig();
    ldapConfig.setLdapHost("localHost");
    ldapConfig.setLdapPort(server.getPort());
    ldapConfig.setName(ADMIN_DN);
    ldapConfig.setCredentials(ADMIN_PASSWORD);
    configuration = mock(Configuration.class);
    when(configuration.getPasswordSecret()).thenReturn(PASSWORD_SECRET);
    ldapConnector = new LdapConnector(10000);
    ldapSettingsService = mock(LdapSettingsService.class);
    userService = mock(UserService.class);
    ldapSettings = new LdapSettingsImpl(configuration, mock(RoleService.class));
    ldapSettings.setEnabled(true);
    ldapSettings.setUri(URI.create("ldap://localhost:" + server.getPort()));
    ldapSettings.setUseStartTls(false);
    ldapSettings.setSystemUsername(ADMIN_DN);
    ldapSettings.setSystemPassword(ADMIN_PASSWORD);
    ldapSettings.setSearchBase("ou=users,dc=example,dc=com");
    ldapSettings.setSearchPattern("(&(objectClass=posixAccount)(uid={0}))");
    ldapSettings.setDisplayNameAttribute("cn");
    ldapSettings.setActiveDirectory(false);
    ldapSettings.setGroupSearchBase("ou=groups,dc=example,dc=com");
    ldapSettings.setGroupIdAttribute("cn");
    ldapSettings.setGroupSearchPattern("(|(objectClass=groupOfNames)(objectClass=posixGroup))");
}
Also used : LdapSettingsService(org.graylog2.security.ldap.LdapSettingsService) Configuration(org.graylog2.Configuration) UserService(org.graylog2.shared.users.UserService) LdapSettingsImpl(org.graylog2.security.ldap.LdapSettingsImpl) LdapConnectionConfig(org.apache.directory.ldap.client.api.LdapConnectionConfig) LdapConnector(org.graylog2.security.ldap.LdapConnector) Before(org.junit.Before)

Aggregations

SubsetConfiguration (org.apache.commons.configuration2.SubsetConfiguration)10 Configuration (org.graylog2.Configuration)10 Test (org.junit.Test)9 Configuration (org.apache.hadoop.conf.Configuration)8 URI (java.net.URI)7 Configuration (org.apache.commons.configuration2.Configuration)5 Before (org.junit.Before)5 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)4 MetricRegistry (com.codahale.metrics.MetricRegistry)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)2 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 Role (org.graylog2.shared.users.Role)2 UserService (org.graylog2.shared.users.UserService)2 EventBus (com.google.common.eventbus.EventBus)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1