/** * @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()); } }
/** * @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()); } }
/** * @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"); }
/** * @throws Exception If failed. */ @Test public void testDefaultUserPersistence() throws Exception { AuthorizationContext.context(actxDflt); try { grid(CLI_NODE).context().authentication().addUser("test", "passwd"); stopAllGrids(); U.sleep(500); 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()); actx = grid(i).context().authentication() .authenticate("test", "passwd"); assertNotNull(actx); assertEquals("test", actx.userName()); } } finally { AuthorizationContext.clear(); } }
/** * @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); } }
/** * @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(); } }
/** * @throws Exception If failed. */ @Test public void testUserPersistence() throws Exception { AuthorizationContext.context(actxDflt); try { for (int i = 0; i < NODES_COUNT; ++i) grid(i).context().authentication().addUser("test" + i , "passwd" + i); grid(CLI_NODE).context().authentication().updateUser("ignite", "new_passwd"); stopAllGrids(); startGrids(NODES_COUNT); for (int i = 0; i < NODES_COUNT; ++i) { for (int usrIdx = 0; usrIdx < NODES_COUNT; ++usrIdx) { AuthorizationContext actx0 = grid(i).context().authentication() .authenticate("test" + usrIdx, "passwd" + usrIdx); assertNotNull(actx0); assertEquals("test" + usrIdx, actx0.userName()); } AuthorizationContext actx = grid(i).context().authentication() .authenticate("ignite", "new_passwd"); assertNotNull(actx); assertEquals("ignite", actx.userName()); } } finally { AuthorizationContext.clear(); } }