@OnOpen public void onOpen(Session session) { LOG.debug("@OnOpen: " + session.getId()); thisSession = session; if (thisSession.getUserPrincipal() != null) { authToken = (UsernamePasswordAuthenticationToken) thisSession.getUserPrincipal(); if (authToken.isAuthenticated()) { isHttpSessionValid = true; httpSession = (HttpSession) thisSession.getUserProperties().get("httpSession"); httpSessionId = httpSession.getId(); LOG.debug("HTTP Session id: " + httpSessionId); if (httpSession.getAttribute("CHAT_OPEN") != null) { activeClose(new CloseReason(CloseReason.CloseCodes.VIOLATED_POLICY, "ALREADY_OPEN")); } else { httpSession.setAttribute("CHAT_OPEN", true); } return; } } activeClose(new CloseReason(CloseReason.CloseCodes.VIOLATED_POLICY, "Unauthorized")); }
@BeforeClass public static void init() { Mockito.when(master.getUserPrincipal()).thenReturn(principalMaster); Mockito.when(slave1.getUserPrincipal()).thenReturn(principal1); Mockito.when(slave2.getUserPrincipal()).thenReturn(principal2); Mockito.when(master.getUserPrincipal().getName()).thenReturn("master1"); Mockito.when(slave1.getUserPrincipal().getName()).thenReturn("slave1"); Mockito.when(slave2.getUserPrincipal().getName()).thenReturn("slave2"); }