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