use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class RestAuthentication method testMalformedDigestHeader.
@Test
public void testMalformedDigestHeader() throws Exception {
assumeTrue(mechanism.startsWith("DIGEST"));
InfinispanServerDriver serverDriver = SERVERS.getServerDriver();
InetSocketAddress serverAddress = serverDriver.getServerSocket(0, 11222);
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder().followRedirects(false);
builder.addServer().host(serverAddress.getHostName()).port(serverAddress.getPort());
RestClient restClient = RestClient.forConfiguration(builder.build());
RestResponse response = sync(restClient.raw().get("/rest/v2/caches"));
assertEquals(401, response.getStatus());
String auth = response.headers().get("Www-Authenticate").stream().filter(h -> h.startsWith("Digest")).findFirst().get();
HashMap<String, byte[]> parameters = DigestUtil.parseResponse(auth.substring(7).getBytes(UTF_8), UTF_8, false, httpDigest);
final String realm = new String(parameters.get("realm"), UTF_8);
final String nonce = new String(parameters.get("nonce"), UTF_8);
final String opaque = new String(parameters.get("opaque"), UTF_8);
final String algorithm = new String(parameters.get("algorithm"), UTF_8);
final String charset = StandardCharsets.ISO_8859_1.name();
final MessageDigest digester = MessageDigest.getInstance(algorithm);
final String nc = "00000001";
final String cnonce = "00000000";
final String username = "h4ck0rz";
final String password = "letmein";
final String uri = "/backdoor";
final String s1 = username + ':' + realm + ':' + password;
final String s2 = "GET:" + uri;
final String hasha1 = toHexString(digester.digest(s1.getBytes(charset)));
final String h2 = toHexString(digester.digest(s2.getBytes(charset)));
final String digestValue = hasha1 + ':' + nonce + ':' + nc + ':' + cnonce + ":auth:" + h2;
final String digest = toHexString(digester.digest(digestValue.getBytes(StandardCharsets.US_ASCII.toString())));
String authz = String.format("Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", response=\"%s\", qop=auth, nc=%s, cnonce=%s, algorithm=%s, opaque=\"%s\"", username, realm, nonce, uri, digest, nc, cnonce, algorithm, opaque);
response = sync(restClient.raw().get("/rest/v2/caches", Collections.singletonMap("Authorization", authz)));
assertEquals(400, response.getStatus());
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class AbstractAuthorization method assertXSiteOps.
private void assertXSiteOps(TestUser user, int status, int noContentStatus, int notModifiedStatus) {
RestClientConfigurationBuilder userConfig = restBuilders.get(user);
RestClient client = getServerTest().rest().withClientConfiguration(userConfig).get();
RestCacheClient xsiteCache = client.cache("xsite");
assertStatus(status, xsiteCache.takeSiteOffline("NYC"));
assertStatus(status, xsiteCache.bringSiteOnline("NYC"));
assertStatus(status, xsiteCache.cancelPushState("NYC"));
assertStatus(status, xsiteCache.cancelReceiveState("NYC"));
assertStatus(status, xsiteCache.clearPushStateStatus());
assertStatus(status, xsiteCache.pushSiteState("NYC"));
assertStatus(status, xsiteCache.pushStateStatus());
assertStatus(status, xsiteCache.xsiteBackups());
assertStatus(status, xsiteCache.backupStatus("NYC"));
assertStatus(status, xsiteCache.getXSiteTakeOfflineConfig("NYC"));
assertStatus(noContentStatus, xsiteCache.updateXSiteTakeOfflineConfig("NYC", 10, 1000));
assertStatus(status, xsiteCache.xSiteStateTransferMode("NYC"));
assertStatus(notModifiedStatus, xsiteCache.xSiteStateTransferMode("NYC", XSiteStateTransferMode.MANUAL));
RestCacheManagerClient xsiteCacheManager = client.cacheManager("default");
assertStatus(status, xsiteCacheManager.bringBackupOnline("NYC"));
assertStatus(status, xsiteCacheManager.takeOffline("NYC"));
assertStatus(status, xsiteCacheManager.backupStatuses());
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class AuthorizationKerberosIT method addClientBuilders.
@Override
protected void addClientBuilders(TestUser user) {
ConfigurationBuilder hotRodBuilder = new ConfigurationBuilder();
RestClientConfigurationBuilder restBuilder = new RestClientConfigurationBuilder();
if (user != TestUser.ANONYMOUS) {
Subject subject = Common.createSubject(user.getUser(), "INFINISPAN.ORG", user.getPassword().toCharArray());
hotRodBuilder.security().authentication().saslMechanism("GSSAPI").serverName("datagrid").realm("default").callbackHandler(new VoidCallbackHandler()).clientSubject(subject);
restBuilder.security().authentication().mechanism("SPNEGO").clientSubject(subject);
}
hotRodBuilders.put(user, hotRodBuilder);
restBuilders.put(user, restBuilder);
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class AbstractAuthenticationKeyCloak method testRestReadWrite.
@Test
public void testRestReadWrite() {
String token = getToken();
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
builder.security().authentication().mechanism("BEARER_TOKEN").username(token);
RestClient client = getServerTest().rest().withClientConfiguration(builder).create();
RestResponse response = sync(client.cache(getServerTest().getMethodName()).post("k1", "v1"));
assertEquals(204, response.getStatus());
response = sync(client.cache(getServerTest().getMethodName()).get("k1"));
assertEquals(200, response.getStatus());
assertEquals("v1", response.getBody());
}
use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.
the class AuthenticationImplicitIT method testRest.
public void testRest(Protocol protocol) {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
if (!mechanism.isEmpty()) {
builder.protocol(protocol).security().authentication().mechanism(mechanism).realm("default").username("all_user").password("all");
}
if (mechanism.isEmpty() || "BASIC".equals(mechanism)) {
Exceptions.expectException(SecurityException.class, () -> SERVER_TEST.rest().withClientConfiguration(builder).create());
} else {
RestClient client = SERVER_TEST.rest().withClientConfiguration(builder).create();
RestResponse response = sync(client.cache(SERVER_TEST.getMethodName()).post("k1", "v1"));
assertEquals(204, response.getStatus());
assertEquals(protocol, response.getProtocol());
response = sync(client.cache(SERVER_TEST.getMethodName()).get("k1"));
assertEquals(200, response.getStatus());
assertEquals(protocol, response.getProtocol());
assertEquals("v1", response.getBody());
}
}
Aggregations