@Override public Object call() throws Exception { grid(nodeIdx).context().authentication().authenticate("test", "invalid_password"); return null; } }, IgniteAccessControlException.class, "The user name or password is incorrect");
@Override public Object call() throws Exception { grid(0).context().authentication().authenticate("test", "test"); return null; } }, IgniteException.class,
@Override public Object call() throws Exception { grid(0).context().authentication().authenticate("user1", "password1"); return null; } }, IgniteAccessControlException.class, "The user name or password is incorrect");
@Override public Object call() throws Exception { grid(nodeIdx).context().authentication().authenticate("invalid_name", "test"); return null; } }, IgniteAccessControlException.class, "The user name or password is incorrect");
@Override public Object call() throws Exception { while (!stopServersFut.isDone()) { AuthorizationContext actx = grid(CLI_NODE).context().authentication() .authenticate("test", "test"); assertNotNull(actx); } return null; } },
/** * Perform authentication. * * @return Auth context. * @throws IgniteCheckedException If failed. */ protected AuthorizationContext authenticate(String user, String pwd) throws IgniteCheckedException { if (ctx.security().enabled()) authCtx = authenticateExternal(user, pwd).authorizationContext(); else if (ctx.authentication().enabled()) { if (F.isEmpty(user)) throw new IgniteAccessControlException("Unauthenticated sessions are prohibited."); authCtx = ctx.authentication().authenticate(user, pwd); if (authCtx == null) throw new IgniteAccessControlException("Unknown authentication error."); } else authCtx = null; return authCtx; }
/** * @throws Exception If failed. */ @Test public void testDefaultUser() throws Exception { for (int i = 0; i < NODES_COUNT; ++i) { AuthorizationContext actx = grid(i).context().authentication().authenticate("ignite", "ignite"); assertNotNull(actx); assertEquals("ignite", actx.userName()); } }
/** * @throws Exception If failed. */ @Test public void testDefaultUser() throws Exception { startGrids(NODES_COUNT); for (int i = 0; i < NODES_COUNT; ++i) { AuthorizationContext actx = grid(i).context().authentication().authenticate("ignite", "ignite"); assertNotNull(actx); assertEquals("ignite", actx.userName()); } }
/** * @param actx Authorization context. * @param updNode Node to execute update operation. * @param authNode Node to execute authentication. * @throws Exception On error. */ private void checkUpdateUser(AuthorizationContext actx, IgniteEx updNode, IgniteEx authNode) throws Exception { String newPasswd = randomString(16); updNode.context().authentication().updateUser("test", newPasswd); AuthorizationContext actxNew = authNode.context().authentication().authenticate("test", newPasswd); assertNotNull(actxNew); assertEquals("test", actxNew.userName()); } }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); startGrids(NODES_COUNT); grid(0).cluster().active(true); actxDflt = grid(0).context().authentication().authenticate(User.DFAULT_USER_NAME, "ignite"); assertNotNull(actxDflt); }
/** * @throws Exception If failed. */ @Test public void testCreateUpdateDropUser() throws Exception { AuthorizationContext.context(actxDflt); for (int i = 0; i < NODES_COUNT; ++i) { userSql(i, "CREATE USER test WITH PASSWORD 'test'"); AuthorizationContext actx = grid(i).context().authentication() .authenticate("TEST", "test"); assertNotNull(actx); assertEquals("TEST", actx.userName()); userSql(i, "ALTER USER test WITH PASSWORD 'newpasswd'"); actx = grid(i).context().authentication() .authenticate("TEST", "newpasswd"); assertNotNull(actx); assertEquals("TEST", actx.userName()); userSql(i, "DROP USER test"); } }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); startGrids(NODES_COUNT); grid(0).cluster().active(true); actxDflt = grid(0).context().authentication().authenticate(User.DFAULT_USER_NAME, "ignite"); assertNotNull(actxDflt); }
/** * @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().authentication().addUser("test", "test"); AuthorizationContext newActx = authNode.context().authentication().authenticate("test", "test"); assertNotNull(newActx); assertEquals("test", newActx.userName()); createNode.context().authentication().updateUser("test", "newpasswd"); newActx = authNode.context().authentication().authenticate("test", "newpasswd"); assertNotNull(newActx); assertEquals("test", newActx.userName()); createNode.context().authentication().removeUser("test"); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); startGrids(NODES_COUNT); grid(0).cluster().active(true); actxDflt = grid(0).context().authentication().authenticate(User.DFAULT_USER_NAME, "ignite"); assertNotNull(actxDflt); }
/** * @param client Is joining node client. * @throws Exception If failed. */ private void checkNodeJoinDisabled(boolean client) throws Exception { startGrid(configuration(0, true, false)); startGrid(configuration(1, false, client)); grid(0).cluster().active(true); AuthorizationContext actx = grid(1).context().authentication().authenticate("ignite", "ignite"); assertNotNull(actx); assertEquals("ignite", actx.userName()); }
AuthorizationContext actxDflt = grid(0).context().authentication().authenticate(User.DFAULT_USER_NAME, "ignite"); AuthorizationContext actx = grid(i).context().authentication().authenticate("test" + usrCnt, "passwd");
/** * @throws Exception If failed. */ @Test public void testUpdateUser() throws Exception { AuthorizationContext.context(actxDflt); try { grid(0).context().authentication().addUser("test", "test"); AuthorizationContext actx = grid(0).context().authentication().authenticate("test", "test"); for (int i = 0; i < NODES_COUNT; ++i) { for (int j = 0; j < NODES_COUNT; ++j) checkUpdateUser(actx, grid(i), grid(j)); } } finally { AuthorizationContext.context(null); } }
/** * @throws Exception If failed. */ @Test public void testProceedUsersOnJoinNode() throws Exception { AuthorizationContext.context(actxDflt); try { grid(0).context().authentication().addUser("test0", "test"); grid(0).context().authentication().addUser("test1", "test"); int nodeIdx = NODES_COUNT; startGrid(nodeIdx); AuthorizationContext actx0 = grid(nodeIdx).context().authentication().authenticate("test0", "test"); AuthorizationContext actx1 = grid(nodeIdx).context().authentication().authenticate("test1", "test"); assertNotNull(actx0); assertEquals("test0", actx0.userName()); assertNotNull(actx1); assertEquals("test1", actx1.userName()); } finally { AuthorizationContext.context(null); } }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true); startGrids(2); grid(0).cluster().active(true); AuthorizationContext.context(grid(0).context().authentication().authenticate("ignite", "ignite")); grid(0).context().authentication().addUser("another_user", "passwd"); AuthorizationContext.clear(); }
/** * @throws Exception If failed. */ @Test public void testDefaultUserUpdate() throws Exception { AuthorizationContext.context(actxDflt); try { // Change from all nodes for (int nodeIdx = 0; nodeIdx < NODES_COUNT; ++nodeIdx) { grid(nodeIdx).context().authentication().updateUser("ignite", "ignite" + nodeIdx); // Check each change from all nodes for (int i = 0; i < NODES_COUNT; ++i) { AuthorizationContext actx = grid(i).context().authentication().authenticate("ignite", "ignite" + nodeIdx); assertNotNull(actx); assertEquals("ignite", actx.userName()); } } } finally { AuthorizationContext.clear(); } }