use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.
the class AbstractAuthorization method testExecScripts.
@Test
public void testExecScripts() {
SkipJunit.skipSinceJDK(16);
InfinispanServerTestMethodRule serverTest = getServerTest();
RemoteCache cache = serverTest.hotrod().withClientConfiguration(hotRodBuilders.get(TestUser.ADMIN)).create();
String scriptName = serverTest.addScript(cache.getRemoteCacheManager(), "scripts/test.js");
Map params = new HashMap<>();
params.put("key", "k");
params.put("value", "v");
for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.APPLICATION, TestUser.DEPLOYER)) {
RemoteCache cacheExec = serverTest.hotrod().withClientConfiguration(hotRodBuilders.get(user)).get();
cacheExec.execute(scriptName, params);
}
for (TestUser user : EnumSet.of(TestUser.MONITOR, TestUser.OBSERVER, TestUser.WRITER)) {
RemoteCache cacheExec = serverTest.hotrod().withClientConfiguration(hotRodBuilders.get(user)).get();
Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> {
cacheExec.execute(scriptName, params);
});
}
}
use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.
the class AbstractAuthorization method testHotRodAdminAndDeployerCanDoEverything.
@Test
public void testHotRodAdminAndDeployerCanDoEverything() {
for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER)) {
RemoteCache<String, String> cache = getServerTest().hotrod().withClientConfiguration(hotRodBuilders.get(user)).withCacheMode(CacheMode.DIST_SYNC).create();
cache.put("k", "v");
assertEquals("v", cache.get("k"));
cache.putAll(bulkData);
assertEquals(11, cache.size());
cache.getRemoteCacheManager().administration().removeCache(cache.getName());
}
}
use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.
the class AbstractAuthorization method testRestNonAdminsMustNotAccessBackupsAndRestores.
@Test
public void testRestNonAdminsMustNotAccessBackupsAndRestores() {
for (TestUser user : TestUser.NON_ADMINS) {
RestClusterClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cluster();
assertStatus(FORBIDDEN, client.createBackup("backup"));
assertStatus(FORBIDDEN, client.getBackup("backup", true));
assertStatus(FORBIDDEN, client.getBackupNames());
assertStatus(FORBIDDEN, client.deleteBackup("backup"));
assertStatus(FORBIDDEN, client.restore("restore", "somewhere"));
assertStatus(FORBIDDEN, client.getRestoreNames());
assertStatus(FORBIDDEN, client.getRestore("restore"));
assertStatus(FORBIDDEN, client.deleteRestore("restore"));
}
}
use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.
the class SecurityRealmServerListener method before.
@Override
public void before(InfinispanServerDriver driver) {
UserTool userTool = new UserTool(driver.getRootDir().getAbsolutePath(), realm + "-users.properties", realm + "-groups.properties");
// Create users and groups for individual permissions
for (AuthorizationPermission permission : AuthorizationPermission.values()) {
String name = permission.name().toLowerCase();
userTool.createUser(username(name + "_user"), name, realm, UserTool.Encryption.DEFAULT, Collections.singletonList(name), null);
}
// Create users with composite roles
for (TestUser user : TestUser.values()) {
if (user != TestUser.ANONYMOUS) {
userTool.createUser(username(user.getUser()), user.getPassword(), realm, UserTool.Encryption.DEFAULT, user.getRoles(), null);
}
}
}
use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.
the class AbstractAuthorization method testBulkReadUsersCanQuery.
@Test
public void testBulkReadUsersCanQuery() {
org.infinispan.configuration.cache.ConfigurationBuilder builder = prepareIndexedCache();
for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
RemoteCache<Integer, User> userCache = getServerTest().hotrod().withClientConfiguration(clientConfigurationWithProtostreamMarshaller(user)).withServerConfiguration(builder).get();
User fromCache = userCache.get(1);
HotRodCacheQueries.assertUser1(fromCache);
QueryFactory qf = Search.getQueryFactory(userCache);
Query<User> query = qf.create("FROM sample_bank_account.User WHERE name = 'Tom'");
List<User> list = query.execute().list();
assertNotNull(list);
assertEquals(1, list.size());
assertEquals(User.class, list.get(0).getClass());
HotRodCacheQueries.assertUser1(list.get(0));
}
for (TestUser user : EnumSet.of(TestUser.ADMIN, TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.OBSERVER)) {
RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
assertStatus(OK, userCache.query("FROM sample_bank_account.User WHERE name = 'Tom'"));
assertStatus(OK, userCache.searchStats());
assertStatus(OK, userCache.indexStats());
assertStatus(OK, userCache.queryStats());
}
}
Aggregations