Search in sources :

Example 6 with SecurityContext

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());
}
Also used : SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext)

Example 7 with SecurityContext

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

Example 8 with SecurityContext

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

Example 9 with SecurityContext

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");
}
Also used : SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) OperationSecurityContext(org.apache.ignite.internal.processors.security.OperationSecurityContext)

Example 10 with SecurityContext

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SecurityContext(org.apache.ignite.internal.processors.security.SecurityContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

SecurityContext (org.apache.ignite.internal.processors.security.SecurityContext)32 OperationSecurityContext (org.apache.ignite.internal.processors.security.OperationSecurityContext)15 Test (org.junit.Test)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)14 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 IgniteException (org.apache.ignite.IgniteException)6 SecurityCredentials (org.apache.ignite.plugin.security.SecurityCredentials)4 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 GridComponent (org.apache.ignite.internal.GridComponent)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2