Search in sources :

Example 11 with TestUser

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);
        });
    }
}
Also used : InfinispanServerTestMethodRule(org.infinispan.server.test.junit4.InfinispanServerTestMethodRule) HashMap(java.util.HashMap) RemoteCache(org.infinispan.client.hotrod.RemoteCache) Map(java.util.Map) HashMap(java.util.HashMap) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 12 with TestUser

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());
    }
}
Also used : TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 13 with TestUser

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"));
    }
}
Also used : TestUser(org.infinispan.server.test.api.TestUser) RestClusterClient(org.infinispan.client.rest.RestClusterClient) Test(org.junit.Test)

Example 14 with TestUser

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);
        }
    }
}
Also used : AuthorizationPermission(org.infinispan.security.AuthorizationPermission) UserTool(org.infinispan.cli.user.UserTool) TestUser(org.infinispan.server.test.api.TestUser)

Example 15 with TestUser

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());
    }
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) User(org.infinispan.protostream.sampledomain.User) TestUser(org.infinispan.server.test.api.TestUser) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Aggregations

TestUser (org.infinispan.server.test.api.TestUser)19 Test (org.junit.Test)12 RestCacheClient (org.infinispan.client.rest.RestCacheClient)5 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)3 RestClient (org.infinispan.client.rest.RestClient)3 UserTool (org.infinispan.cli.user.UserTool)2 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)2 User (org.infinispan.protostream.sampledomain.User)2 QueryFactory (org.infinispan.query.dsl.QueryFactory)2 AuthorizationPermission (org.infinispan.security.AuthorizationPermission)2 InfinispanServerTestMethodRule (org.infinispan.server.test.junit4.InfinispanServerTestMethodRule)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 CertificateException (java.security.cert.CertificateException)1