/** * Compose connection description string. * @param ses client NIO session. * @param ctx client connection context. * @return connection description */ @SuppressWarnings("StringConcatenationInsideStringBufferAppend") private String clientConnectionDescription(GridNioSession ses, ClientListenerConnectionContext ctx) { AuthorizationContext authCtx = ctx.authorizationContext(); StringBuilder sb = new StringBuilder(); if(ctx instanceof JdbcConnectionContext) sb.append("JdbcClient ["); else if (ctx instanceof OdbcConnectionContext) sb.append("OdbcClient ["); else sb.append("ThinClient ["); InetSocketAddress rmtAddr = ses.remoteAddress(); InetSocketAddress locAddr = ses.localAddress(); assert rmtAddr != null; assert locAddr != null; String rmtAddrStr = rmtAddr.getHostString() + ":" + rmtAddr.getPort(); String locAddrStr = locAddr.getHostString() + ":" + locAddr.getPort(); sb.append("id=" + ctx.connectionId()); sb.append(", user=").append(authCtx == null ? "<anonymous>" : authCtx.userName()); sb.append(", rmtAddr=" + rmtAddrStr); sb.append(", locAddr=" + locAddrStr); return sb.append(']').toString(); } }
/** * @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()); } }
/** * @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"); } }
/** * @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"); }
/** * @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()); }
/** * @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(); } }
assertEquals("test" + usrCnt, actx.userName());
/** * Compose connection description string. * @param ses client NIO session. * @param ctx client connection context. * @return connection description */ @SuppressWarnings("StringConcatenationInsideStringBufferAppend") private String clientConnectionDescription(GridNioSession ses, ClientListenerConnectionContext ctx) { AuthorizationContext authCtx = ctx.authorizationContext(); StringBuilder sb = new StringBuilder(); if(ctx instanceof JdbcConnectionContext) sb.append("JdbcClient ["); else if (ctx instanceof OdbcConnectionContext) sb.append("OdbcClient ["); else sb.append("ThinClient ["); InetSocketAddress rmtAddr = ses.remoteAddress(); InetSocketAddress locAddr = ses.localAddress(); assert rmtAddr != null; assert locAddr != null; String rmtAddrStr = rmtAddr.getHostString() + ":" + rmtAddr.getPort(); String locAddrStr = locAddr.getHostString() + ":" + locAddr.getPort(); sb.append("id=" + ctx.connectionId()); sb.append(", user=").append(authCtx == null ? "<anonymous>" : authCtx.userName()); sb.append(", rmtAddr=" + rmtAddrStr); sb.append(", locAddr=" + locAddrStr); return sb.append(']').toString(); } }