use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method checkUpdateUser.
/**
* @param secCtx Security context.
* @param updNode Node to execute update operation.
* @param authNode Node to execute authentication.
* @throws Exception On error.
*/
private void checkUpdateUser(SecurityContext secCtx, IgniteEx updNode, IgniteEx authNode) throws Exception {
String newPasswd = randomString(16);
updNode.context().security().alterUser("test", newPasswd.toCharArray());
SecurityContext secCtxNew = authenticate(authNode, "test", newPasswd);
assertNotNull(secCtxNew);
assertEquals("test", secCtxNew.subject().login());
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testDefaultUserPersistence.
/**
* @throws Exception If failed.
*/
@Test
public void testDefaultUserPersistence() throws Exception {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
grid(CLI_NODE).context().security().createUser("test", "passwd".toCharArray());
stopAllGrids();
U.sleep(500);
startGrids(NODES_COUNT - 1);
startClientGrid(CLI_NODE);
for (int i = 0; i < NODES_COUNT; ++i) {
SecurityContext secCtx = authenticate(grid(i), "ignite", "ignite");
assertNotNull(secCtx);
assertEquals("ignite", secCtx.subject().login());
secCtx = authenticate(grid(i), "test", "passwd");
assertNotNull(secCtx);
assertEquals("test", secCtx.subject().login());
}
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testUpdateUser.
/**
* @throws Exception If failed.
*/
@Test
public void testUpdateUser() throws Exception {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
grid(0).context().security().createUser("test", "test".toCharArray());
SecurityContext secCtx = authenticate(grid(0), "test", "test");
for (int i = 0; i < NODES_COUNT; ++i) {
for (int j = 0; j < NODES_COUNT; ++j) checkUpdateUser(secCtx, grid(i), grid(j));
}
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method checkAddUpdateRemoveUser.
/**
* @param createNode Node to execute create operation.
* @param authNode Node to execute authentication.
* @throws Exception On error.
*/
private void checkAddUpdateRemoveUser(IgniteEx createNode, IgniteEx authNode) throws Exception {
createNode.context().security().createUser("test", "test".toCharArray());
SecurityContext newSecCtx = authenticate(authNode, "test", "test");
assertNotNull(newSecCtx);
assertEquals("test", newSecCtx.subject().login());
createNode.context().security().alterUser("test", "newpasswd".toCharArray());
newSecCtx = authenticate(authNode, "test", "newpasswd");
assertNotNull(newSecCtx);
assertEquals("test", newSecCtx.subject().login());
createNode.context().security().dropUser("test");
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorNodeRestartTest method testConcurrentAuthorize.
/**
* @throws Exception If failed.
*/
@Test
public void testConcurrentAuthorize() throws Exception {
final int testUsersCnt = 10;
withSecurityContextOnAllNodes(secCtxDflt);
for (int i = 0; i < testUsersCnt; ++i) grid(CLI_NODE).context().security().createUser("test" + i, ("passwd_test" + i).toCharArray());
final IgniteInternalFuture restartFut = GridTestUtils.runAsync(() -> {
try {
for (int i = 0; i < RESTARTS; ++i) {
int nodeIdx = RND.nextInt(NODES_COUNT - 1);
stopGrid(nodeIdx);
U.sleep(500);
startGrid(nodeIdx);
U.sleep(500);
}
} catch (Exception e) {
log.error("Unexpected exception.", e);
fail("Unexpected exception on server restart: " + e.getMessage());
}
});
final AtomicInteger usrCnt = new AtomicInteger();
GridTestUtils.runMultiThreaded(() -> {
String user = "test" + usrCnt.getAndIncrement();
try {
while (!restartFut.isDone()) {
SecurityContext secCtx = authenticate(grid(CLI_NODE), user, "passwd_" + user);
assertNotNull(secCtx);
}
} catch (ClusterTopologyCheckedException ignored) {
// No-op.
} catch (Exception e) {
log.error("Unexpected exception.", e);
fail("Unexpected exception: " + e.getMessage());
}
}, testUsersCnt, "user-op");
restartFut.get();
}
Aggregations