use of org.apache.ignite.internal.processors.security.IgniteSecurity in project ignite by apache.
the class UserActionCommandHandler method handleAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
assert req != null;
if (log.isDebugEnabled())
log.debug("Handling topology REST request: " + req);
RestUserActionRequest req0 = (RestUserActionRequest) req;
try {
GridRestCommand cmd = req.command();
IgniteSecurity security = ctx.security();
switch(cmd) {
case ADD_USER:
security.createUser(req0.user(), req0.password().toCharArray());
break;
case REMOVE_USER:
security.dropUser(req0.user());
break;
case UPDATE_USER:
security.alterUser(req0.user(), req0.password().toCharArray());
break;
}
if (log.isDebugEnabled())
log.debug("Handled topology REST request [req=" + req + ']');
return new GridFinishedFuture<>(new GridRestResponse(true));
} catch (Throwable e) {
log.error("Failed to handle REST request [req=" + req + ']', e);
return new GridFinishedFuture<>(e);
}
}
use of org.apache.ignite.internal.processors.security.IgniteSecurity in project ignite by apache.
the class AuthenticationProcessorSelfTest method testRemoteNodeSecurityContext.
/**
* Test the ability to obtain the security context ot an authenticated user on the remote server node.
*/
@Test
public void testRemoteNodeSecurityContext() throws Exception {
try (OperationSecurityContext ignored = grid(CLI_NODE).context().security().withContext(secCtxDflt)) {
grid(CLI_NODE).context().security().createUser("test", "pwd".toCharArray());
}
SecuritySubject subj = authenticate(grid(0), "test", "pwd").subject();
for (int i = 1; i < NODES_COUNT; i++) {
IgniteSecurity security = ignite(i).context().security();
try (OperationSecurityContext ignored = security.withContext(subj.id())) {
SecuritySubject rmtSubj = security.securityContext().subject();
assertEquals(subj.id(), rmtSubj.id());
assertEquals(i != CLI_NODE ? subj.login() : null, rmtSubj.login());
assertEquals(subj.type(), rmtSubj.type());
}
}
}
use of org.apache.ignite.internal.processors.security.IgniteSecurity in project ignite by apache.
the class Authentication1kUsersNodeRestartTest method test1kUsersNodeRestartServer.
/**
* @throws Exception If failed.
*/
@Test
public void test1kUsersNodeRestartServer() throws Exception {
startGrid(0);
grid(0).cluster().active(true);
IgniteSecurity sec = grid(0).context().security();
SecurityContext secCtxDflt = authenticate(grid(0), User.DFAULT_USER_NAME, "ignite");
withSecurityContextOnAllNodes(secCtxDflt);
IntStream.range(0, USERS_COUNT).parallel().forEach(i -> {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
sec.createUser("test" + i, "init".toCharArray());
} catch (Exception e) {
throw new IgniteException(e);
}
});
IntStream.range(0, USERS_COUNT).parallel().forEach(i -> {
try (AutoCloseable ignored = withSecurityContextOnAllNodes(secCtxDflt)) {
sec.alterUser("test" + i, ("passwd_" + i).toCharArray());
} catch (Exception e) {
throw new IgniteException(e);
}
});
stopGrid(0);
startGrid(0);
authenticate(grid(0), "ignite", "ignite");
}
use of org.apache.ignite.internal.processors.security.IgniteSecurity in project ignite by apache.
the class GridDiscoveryManager method sendCustomEvent.
/**
* @param msg Custom message.
* @throws IgniteCheckedException If failed.
*/
public void sendCustomEvent(DiscoveryCustomMessage msg) throws IgniteCheckedException {
try {
IgniteSecurity security = ctx.security();
getSpi().sendCustomEvent(security.enabled() ? new SecurityAwareCustomMessageWrapper(msg, security.securityContext().subject().id()) : new CustomMessageWrapper(msg));
} catch (IgniteClientDisconnectedException e) {
IgniteFuture<?> reconnectFut = ctx.cluster().clientReconnectFuture();
throw new IgniteClientDisconnectedCheckedException(reconnectFut, e.getMessage());
} catch (IgniteException e) {
throw new IgniteCheckedException(e);
}
}
Aggregations