Search in sources :

Example 1 with IgniteSecurity

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);
    }
}
Also used : RestUserActionRequest(org.apache.ignite.internal.processors.rest.request.RestUserActionRequest) GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) GridRestResponse(org.apache.ignite.internal.processors.rest.GridRestResponse) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 2 with IgniteSecurity

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());
        }
    }
}
Also used : SecuritySubject(org.apache.ignite.plugin.security.SecuritySubject) IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with IgniteSecurity

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");
}
Also used : IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) IgniteException(org.apache.ignite.IgniteException) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) IgniteException(org.apache.ignite.IgniteException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with IgniteSecurity

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSecurity(org.apache.ignite.internal.processors.security.IgniteSecurity) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)

Aggregations

IgniteSecurity (org.apache.ignite.internal.processors.security.IgniteSecurity)4 IgniteException (org.apache.ignite.IgniteException)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 GridRestCommand (org.apache.ignite.internal.processors.rest.GridRestCommand)1 GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)1 RestUserActionRequest (org.apache.ignite.internal.processors.rest.request.RestUserActionRequest)1 OperationSecurityContext (org.apache.ignite.internal.processors.security.OperationSecurityContext)1 SecurityContext (org.apache.ignite.internal.processors.security.SecurityContext)1 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)1 IgniteFuture (org.apache.ignite.lang.IgniteFuture)1 SecuritySubject (org.apache.ignite.plugin.security.SecuritySubject)1