use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SecurityTest method testUserCannotCreateUser.
/**
* Test user cannot create user.
*/
@Test
public void testUserCannotCreateUser() throws Exception {
final String USER = "joe";
final String PWD = "password";
try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName(USER).setUserPassword(PWD))) {
Exception authError = null;
try {
client.query(new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", "joe2", "password"))).getAll();
} catch (Exception e) {
authError = e;
}
assertNotNull("User created another user", authError);
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SecurityTest method testEncryption.
/**
* Test SSL/TLS encryption.
*/
@Test
public void testEncryption() throws Exception {
// Server-side security configuration
IgniteConfiguration srvCfg = Config.getServerConfiguration();
SslContextFactory sslCfg = new SslContextFactory();
Function<String, String> rsrcPath = rsrc -> Paths.get(IGNITE_HOME == null ? "." : IGNITE_HOME, "modules", "core", "src", "test", "resources", rsrc).toString();
sslCfg.setKeyStoreFilePath(rsrcPath.apply("/server.jks"));
sslCfg.setKeyStorePassword("123456".toCharArray());
sslCfg.setTrustStoreFilePath(rsrcPath.apply("/trust.jks"));
sslCfg.setTrustStorePassword("123456".toCharArray());
srvCfg.setClientConnectorConfiguration(new ClientConnectorConfiguration().setSslEnabled(true).setSslClientAuth(true));
srvCfg.setSslContextFactory(sslCfg);
// Client-side security configuration
ClientConfiguration clientCfg = new ClientConfiguration().setAddresses(Config.SERVER);
try (Ignite ignored = Ignition.start(srvCfg)) {
boolean failed;
try (IgniteClient client = Ignition.startClient(clientCfg)) {
client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
failed = false;
} catch (Exception ex) {
failed = true;
}
assertTrue("Client connection without SSL must fail", failed);
// Not using user-supplied SSL Context Factory:
try (IgniteClient client = Ignition.startClient(clientCfg.setSslMode(SslMode.REQUIRED).setSslClientCertificateKeyStorePath(rsrcPath.apply("/client.jks")).setSslClientCertificateKeyStoreType(DFLT_STORE_TYPE).setSslClientCertificateKeyStorePassword("123456").setSslTrustCertificateKeyStorePath(rsrcPath.apply("/trust.jks")).setSslTrustCertificateKeyStoreType(DFLT_STORE_TYPE).setSslTrustCertificateKeyStorePassword("123456").setSslKeyAlgorithm(DFLT_KEY_ALGORITHM).setSslTrustAll(false).setSslProtocol(SslProtocol.TLS))) {
client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
}
// Using user-supplied SSL Context Factory
try (IgniteClient client = Ignition.startClient(clientCfg.setSslMode(SslMode.REQUIRED).setSslContextFactory(sslCfg))) {
client.<Integer, String>cache(Config.DEFAULT_CACHE_NAME).put(1, "1");
}
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class SecurityTest method testValidUserAuthentication.
/**
* Test valid user authentication.
*/
@Test
public void testValidUserAuthentication() throws Exception {
final String USER = "joe";
final String PWD = "password";
try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER).setUserName(USER).setUserPassword(PWD))) {
client.getOrCreateCache("testAuthentication");
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class IgniteBinaryQueryTest method testBinaryQueries.
/**
* Test queries in Ignite binary.
*/
@Test
public void testBinaryQueries() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
final String TYPE_NAME = "Person";
QueryEntity qryPerson = new QueryEntity().setKeyType(Integer.class.getName()).setValueType(TYPE_NAME).setFields(Stream.of(new SimpleEntry<>("id", Integer.class.getName()), new SimpleEntry<>("name", String.class.getName())).collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue, (a, b) -> a, LinkedHashMap::new))).setIndexes(Collections.singletonList(new QueryIndex("id")));
ClientCacheConfiguration cacheCfg = new ClientCacheConfiguration().setName("testBinaryQueries").setQueryEntities(qryPerson);
ClientCache<Integer, BinaryObject> cache = client.getOrCreateCache(cacheCfg).withKeepBinary();
final IgniteBinary binary = client.binary();
Map<Integer, BinaryObject> data = IntStream.range(0, 100).boxed().collect(Collectors.toMap(i -> i, i -> binary.builder(TYPE_NAME).setField("id", i, int.class).setField("name", String.format("Person %s", i), String.class).build()));
cache.putAll(data);
Cache.Entry<Integer, BinaryObject> p1 = cache.query(new SqlQuery<Integer, BinaryObject>(TYPE_NAME, "id = 1")).getAll().iterator().next();
assertEquals(Integer.valueOf(1), p1.getKey());
assertBinaryObjectsEqual(data.get(1), p1.getValue());
}
}
use of org.apache.ignite.configuration.ClientConfiguration in project ignite by apache.
the class PerformanceStatisticsQueryTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
stopAllGrids();
cleanPersistenceDir();
srv = startGrids(2);
thinClient = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER));
client = startClientGrid("client");
client.cluster().state(ACTIVE);
cache = client.getOrCreateCache(new CacheConfiguration<Integer, Integer>().setName(DEFAULT_CACHE_NAME).setSqlSchema(DFLT_SCHEMA).setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Integer.class).setTableName(DEFAULT_CACHE_NAME))));
IgniteCache<Object, Object> cache2 = client.getOrCreateCache(new CacheConfiguration<>().setName(CACHE_2).setSqlSchema(DFLT_SCHEMA).setQueryEntities(Collections.singletonList(new QueryEntity(Long.class, Long.class).setTableName(CACHE_2))));
for (int i = 0; i < ENTRY_COUNT; i++) {
cache.put(i, i);
cache2.put(i, i * 2);
}
}
Aggregations