use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class TestCertificateSecurityProcessor method authenticateNode.
/**
* {@inheritDoc}
*/
@Override
public SecurityContext authenticateNode(ClusterNode node, SecurityCredentials cred) {
SecurityContext res = new TestSecurityContext(new TestSecuritySubject().setType(REMOTE_NODE).setId(node.id()).setAddr(new InetSocketAddress(F.first(node.addresses()), 0)).setLogin("").setPerms(ALLOW_ALL));
secCtxs.put(res.subject().id(), res);
return res;
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class TestCertificateSecurityProcessor method authenticate.
/**
* {@inheritDoc}
*/
@Override
public SecurityContext authenticate(AuthenticationContext ctx) {
Certificate[] certs = ctx.certificates();
assertNotNull(certs);
assertEquals(2, certs.length);
assertTrue(((X509Certificate) certs[0]).getSubjectDN().getName().matches("^CN=[a-z0-9]+$"));
assertTrue(((X509Certificate) certs[0]).getIssuerDN().getName().startsWith("C=RU, ST=SPb, L=SPb, O=Ignite, OU=Dev"));
String cn = ((X509Certificate) certs[0]).getSubjectDN().getName().substring(3);
if (!PERMS.containsKey(cn))
return null;
SecurityContext res = new TestSecurityContext(new TestSecuritySubject().setType(ctx.subjectType()).setId(ctx.subjectId()).setAddr(ctx.address()).setLogin(cn).setPerms(PERMS.get(cn)).setCerts(ctx.certificates()));
secCtxs.put(res.subject().id(), res);
return res;
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class GridRestProcessor method handleRequest.
/**
* @param req Request.
* @return Future.
*/
private IgniteInternalFuture<GridRestResponse> handleRequest(final GridRestRequest req) {
if (req instanceof GridRestNodeStateBeforeStartRequest) {
if (startLatch.getCount() == 0)
return new GridFinishedFuture<>(new IgniteCheckedException("Node has already started."));
} else if (!(req instanceof GridRestAuthenticationRequest) && startLatch.getCount() > 0) {
try {
startLatch.await();
} catch (InterruptedException e) {
return new GridFinishedFuture<>(new IgniteCheckedException("Failed to handle request " + "(protocol handler was interrupted when awaiting grid start).", e));
}
}
if (log.isDebugEnabled())
log.debug("Received request from client: " + req);
if (securityEnabled) {
Session ses;
try {
ses = session(req);
} catch (IgniteAuthenticationException e) {
return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(new GridRestResponse(STATUS_FAILED, e.getMessage()));
}
assert ses != null;
req.clientId(ses.clientId);
req.sessionToken(U.uuidToBytes(ses.sesId));
if (log.isDebugEnabled())
log.debug("Next clientId and sessionToken were extracted according to request: " + "[clientId=" + req.clientId() + ", sesTok=" + Arrays.toString(req.sessionToken()) + "]");
SecurityContext secCtx0 = ses.secCtx;
try {
if (secCtx0 == null || ses.isTokenExpired(sesTokTtl))
ses.secCtx = secCtx0 = authenticate(req, ses);
try (OperationSecurityContext s = ctx.security().withContext(secCtx0)) {
authorize(req);
return handleRequest0(req);
}
} catch (SecurityException e) {
assert secCtx0 != null;
return new GridFinishedFuture<>(new GridRestResponse(STATUS_SECURITY_CHECK_FAILED, e.getMessage()));
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(new GridRestResponse(STATUS_AUTH_FAILED, e.getMessage()));
}
} else
return handleRequest0(req);
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationOnNotActiveClusterTest method testDefaultUser.
/**
* @throws Exception If failed.
*/
@Test
public void testDefaultUser() throws Exception {
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());
}
}
use of org.apache.ignite.internal.processors.security.SecurityContext in project ignite by apache.
the class AuthenticationOnNotActiveClusterTest method testNotDefaultUser.
/**
* @throws Exception If failed.
*/
@Test
public void testNotDefaultUser() throws Exception {
startGrids(NODES_COUNT - 1);
startClientGrid(CLI_NODE);
startGrid(NODES_COUNT);
grid(0).cluster().active(true);
SecurityContext secCtxDflt = authenticate(grid(0), User.DFAULT_USER_NAME, "ignite");
withSecurityContextOnAllNodes(secCtxDflt);
for (int i = 0; i < 10; ++i) grid(0).context().security().createUser("test" + i, "passwd".toCharArray());
stopAllGrids();
U.sleep(500);
startGrids(NODES_COUNT - 1);
startClientGrid(CLI_NODE);
for (int i = 0; i < NODES_COUNT; ++i) {
for (int usrCnt = 0; usrCnt < 10; ++usrCnt) {
SecurityContext secCtx = authenticate(grid(i), "test" + usrCnt, "passwd");
assertNotNull(secCtx);
assertEquals("test" + usrCnt, secCtx.subject().login());
}
}
}
Aggregations