use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class ServerImpl method localAuthentication.
/**
* Authenticate local node.
*
* @param locCred Local security credentials for authentication.
* @throws IgniteSpiException If any error occurs.
*/
private void localAuthentication(SecurityCredentials locCred) {
assert spi.nodeAuth != null;
assert locCred != null;
try {
SecurityContext subj = spi.nodeAuth.authenticateNode(locNode, locCred);
if (subj == null)
throw new IgniteSpiException("Authentication failed for local node: " + locNode.id());
Map<String, Object> attrs = new HashMap<>(locNode.attributes());
attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT_V2, U.marshal(spi.marshaller(), subj));
attrs.put(IgniteNodeAttributes.ATTR_SECURITY_SUBJECT, marshalWithSecurityVersion(subj, 1));
locNode.setAttributes(attrs);
} catch (IgniteException | IgniteCheckedException e) {
throw new IgniteSpiException("Failed to authenticate local node (will shutdown local node).", e);
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testDefaultUserUpdate.
/**
* @throws Exception If failed.
*/
@Test
public void testDefaultUserUpdate() throws Exception {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
// Change from all nodes
for (int nodeIdx = 0; nodeIdx < NODES_COUNT; ++nodeIdx) {
grid(nodeIdx).context().security().alterUser("ignite", ("ignite" + nodeIdx).toCharArray());
// Check each change from all nodes
for (int i = 0; i < NODES_COUNT; ++i) {
SecurityContext secCtx = authenticate(grid(i), "ignite", "ignite" + nodeIdx);
assertNotNull(secCtx);
assertEquals("ignite", secCtx.subject().login());
}
}
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testAuthorizeOnClientDisconnect.
/**
* @throws Exception If failed.
*/
@Test
public void testAuthorizeOnClientDisconnect() throws Exception {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
grid(CLI_NODE).context().security().createUser("test", "test".toCharArray());
}
final IgniteInternalFuture stopServersFut = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
for (int i = 0; i < CLI_NODE; ++i) {
Thread.sleep(500);
stopGrid(i);
}
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception");
}
}
});
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stopServersFut.isDone()) {
SecurityContext secCtx = authenticate(grid(CLI_NODE), "test", "test");
assertNotNull(secCtx);
}
return null;
}
}, IgniteCheckedException.class, "Client node was disconnected from topology (operation result is unknown)");
stopServersFut.get();
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testDefaultUser.
/**
* @throws Exception If failed.
*/
@Test
public void testDefaultUser() throws Exception {
for (int i = 0; i < NODES_COUNT; ++i) {
SecurityContext secCtx = authenticate(grid(i), "ignite", "ignite");
assertNotNull(secCtx);
assertEquals("ignite", secCtx.subject().login());
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationProcessorSelfTest method testUserPersistence.
/**
* @throws Exception If failed.
*/
@Test
public void testUserPersistence() throws Exception {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
for (int i = 0; i < NODES_COUNT; ++i) grid(i).context().security().createUser("test" + i, ("passwd" + i).toCharArray());
grid(CLI_NODE).context().security().alterUser("ignite", "new_passwd".toCharArray());
stopAllGrids();
startGrids(NODES_COUNT - 1);
startClientGrid(CLI_NODE);
for (int i = 0; i < NODES_COUNT; ++i) {
for (int usrIdx = 0; usrIdx < NODES_COUNT; ++usrIdx) {
SecurityContext secCtx0 = authenticate(grid(i), "test" + usrIdx, "passwd" + usrIdx);
assertNotNull(secCtx0);
assertEquals("test" + usrIdx, secCtx0.subject().login());
}
SecurityContext secCtx = authenticate(grid(i), "ignite", "new_passwd");
assertNotNull(secCtx);
assertEquals("ignite", secCtx.subject().login());
}
}
}
Aggregations