Search in sources :

Example 16 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testRestReaderCannotWrite.

private void testRestReaderCannotWrite(String... explicitRoles) {
    restCreateAuthzCache(explicitRoles);
    RestCacheClient readerCache = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.OBSERVER)).get().cache(getServerTest().getMethodName());
    assertStatus(FORBIDDEN, readerCache.put("k1", "v1"));
    for (TestUser user : EnumSet.of(TestUser.APPLICATION, TestUser.DEPLOYER)) {
        RestCacheClient userCache = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cache(getServerTest().getMethodName());
        assertStatus(NO_CONTENT, userCache.put(user.name(), user.name()));
    }
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser)

Example 17 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testHotRodObserverCannotWrite.

private void testHotRodObserverCannotWrite(String... explicitRoles) {
    hotRodCreateAuthzCache(explicitRoles);
    RemoteCache<String, String> readerCache = getServerTest().hotrod().withClientConfiguration(hotRodBuilders.get(TestUser.OBSERVER)).get();
    Exceptions.expectException(HotRodClientException.class, "(?s).*ISPN000287.*", () -> readerCache.put("k1", "v1"));
    for (TestUser user : EnumSet.of(TestUser.DEPLOYER, TestUser.APPLICATION, TestUser.WRITER)) {
        RemoteCache<String, String> userCache = getServerTest().hotrod().withClientConfiguration(hotRodBuilders.get(user)).get();
        userCache.put(user.name(), user.name());
    }
}
Also used : TestUser(org.infinispan.server.test.api.TestUser)

Example 18 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractAuthorization method testRestNonAdminsMustNotPerformSearchActions.

@Test
public void testRestNonAdminsMustNotPerformSearchActions() {
    String schema = Exceptions.unchecked(() -> Util.getResourceAsString("/sample_bank_account/bank.proto", this.getClass().getClassLoader()));
    assertStatus(OK, getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).get().schemas().put(BANK_PROTO, schema));
    org.infinispan.configuration.cache.ConfigurationBuilder builder = new org.infinispan.configuration.cache.ConfigurationBuilder();
    builder.clustering().cacheMode(CacheMode.DIST_SYNC);
    builder.indexing().enable().addIndexedEntity("sample_bank_account.User").statistics().enable();
    RestClient restClient = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).withServerConfiguration(builder).create();
    String indexedCache = getServerTest().getMethodName();
    RestCacheClient cache = restClient.cache(indexedCache);
    for (TestUser user : TestUser.NON_ADMINS) {
        searchActions(user, indexedCache, FORBIDDEN, FORBIDDEN);
    }
    searchActions(TestUser.ADMIN, indexedCache, OK, NO_CONTENT);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) AuthorizationConfigurationBuilder(org.infinispan.configuration.cache.AuthorizationConfigurationBuilder) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) RestClient(org.infinispan.client.rest.RestClient) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestUser(org.infinispan.server.test.api.TestUser) Test(org.junit.Test)

Example 19 with TestUser

use of org.infinispan.server.test.api.TestUser in project infinispan by infinispan.

the class AbstractInfinispanServerDriver method createKeyStores.

/**
 * Creates a number of certificates in PKCS#12 format:
 * <ul>
 * <li><b>ca.pfx</b> A self-signed CA used as the main trust</li>
 * <li><b>server.pfx</b> A server certificate signed by the CA</li>
 * <li><b>user1.pfx</b> A client certificate signed by the CA</li>
 * <li><b>user2.pfx</b> A client certificate signed by the CA</li>
 * </ul>
 */
protected void createKeyStores() {
    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        PrivateKey signingKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();
        X500Principal CA_DN = dn("CA");
        KeyStore trustStore = KeyStore.getInstance(KEYSTORE_TYPE);
        trustStore.load(null);
        SelfSignedX509CertificateAndSigningKey ca = createSelfSignedCertificate(CA_DN, true, "ca");
        trustStore.setCertificateEntry("ca", ca.getSelfSignedCertificate());
        createSignedCertificate(signingKey, publicKey, ca, CA_DN, "server", trustStore);
        for (TestUser user : TestUser.values()) {
            if (user != TestUser.ANONYMOUS) {
                createSignedCertificate(signingKey, publicKey, ca, CA_DN, user.getUser(), trustStore);
            }
        }
        createSignedCertificate(signingKey, publicKey, ca, CA_DN, "supervisor", trustStore);
        try (FileOutputStream os = new FileOutputStream(getCertificateFile("trust"))) {
            trustStore.store(os, KEY_PASSWORD.toCharArray());
        }
        createSelfSignedCertificate(CA_DN, true, "untrusted");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : KeyPair(java.security.KeyPair) PrivateKey(java.security.PrivateKey) SelfSignedX509CertificateAndSigningKey(org.wildfly.security.x500.cert.SelfSignedX509CertificateAndSigningKey) PublicKey(java.security.PublicKey) FileOutputStream(java.io.FileOutputStream) X500Principal(javax.security.auth.x500.X500Principal) KeyPairGenerator(java.security.KeyPairGenerator) KeyStore(java.security.KeyStore) TestUser(org.infinispan.server.test.api.TestUser) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

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