SessionManager { @Nonnull public String startWebSession(@Nonnull final Principal principal) { assert principal != null; return startSession(principal, AUTHENTICATION_SCHEME_USERNAME); } SessionManager();   SessionManager(@Nonnull final HttpServletRequest httpServletRequest); @Nonnull String startWebSession(@Nonnull final Principal principal); @Nonnull String startAppSession(@Nonnull final Principal principal); void terminateSession(); @Nullable String getCurrentSessionId(); @Nullable static SecurityContext createSecurityContextForSession(@Nonnull final HttpServletRequest httpServletRequest); static final String AUTHENTICATION_SCHEME_USERNAME; static final String AUTHENTICATION_SCHEME_APPTOKEN; }
@Test public void testStartWebSession() { LOG.info("testStartWebSession"); Mockito.when(httpServletRequest.getSession()).thenReturn(httpSession); Mockito.when(httpServletRequest.getSession(false)).thenReturn(httpSession); Mockito.doNothing().when(httpSession).invalidate(); assertThat(impl.startWebSession(principal), is(REFERENCE_SESSION_ID)); verify(httpSession).setAttribute(eq(SESSION_DATA_KEY), anyObject()); verify(httpSession).invalidate(); @Nullable final SecurityContext securityContext = SessionManager.createSecurityContextForSession(httpServletRequest); assert securityContext != null; assertThat(securityContext.getAuthenticationScheme(), is(SessionManager.AUTHENTICATION_SCHEME_USERNAME)); @Nullable final Principal principal = securityContext.getUserPrincipal(); assertThat(principal, is(notNullValue())); assertThat(principal.getName(), is(REFERENCE_PERSON_ID)); }