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