LoginContext loginContext = token.getLoginContext(); boolean debug = this.log.isDebugEnabled(); if (loginContext != null) { if (debug) { this.log.debug("Logging principal: [" + token.getPrincipal() + "] out of LoginContext"); this.log.debug("Cannot logout principal: [" + token.getPrincipal() + "] from LoginContext. " + "The LoginContext is unavailable");
JaasAuthenticationToken result = new JaasAuthenticationToken( request.getPrincipal(), request.getCredentials(), new ArrayList<>(authorities), loginContext);
@Test // http@jaas-api-provision public void configureWhenJaasApiIntegrationFilterAddedThenJaasSubjectObtained() throws Exception { LoginContext loginContext = mock(LoginContext.class); when(loginContext.getSubject()).thenReturn(new Subject()); JaasAuthenticationToken authenticationToken = mock(JaasAuthenticationToken.class); when(authenticationToken.isAuthenticated()).thenReturn(true); when(authenticationToken.getLoginContext()).thenReturn(loginContext); this.spring.register(JaasApiProvisionConfig.class).autowire(); this.mockMvc.perform(get("/").with(authentication(authenticationToken))); verify(loginContext, times(1)).getSubject(); }
@Test public void logoutNullLoginContext() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verifyNoMoreInteractions(event, securityContext, token); }
@Test public void logout() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); LoginContext context = mock(LoginContext.class); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); when(token.getLoginContext()).thenReturn(context); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verify(context).logout(); verifyNoMoreInteractions(event, securityContext, token, context); }
LoginContext loginContext = token.getLoginContext(); boolean debug = this.log.isDebugEnabled(); if (loginContext != null) { if (debug) { this.log.debug("Logging principal: [" + token.getPrincipal() + "] out of LoginContext"); this.log.debug("Cannot logout principal: [" + token.getPrincipal() + "] from LoginContext. " + "The LoginContext is unavailable");
@Test public void logoutLoginException() throws Exception { SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); SecurityContext securityContext = mock(SecurityContext.class); JaasAuthenticationToken token = mock(JaasAuthenticationToken.class); LoginContext context = mock(LoginContext.class); LoginException loginException = new LoginException("Failed Login"); when(event.getSecurityContexts()).thenReturn(Arrays.asList(securityContext)); when(securityContext.getAuthentication()).thenReturn(token); when(token.getLoginContext()).thenReturn(context); doThrow(loginException).when(context).logout(); provider.onApplicationEvent(event); verify(event).getSecurityContexts(); verify(securityContext).getAuthentication(); verify(token).getLoginContext(); verify(context).logout(); verify(log).warn(anyString(), eq(loginException)); verifyNoMoreInteractions(event, securityContext, token, context); }
@Test public void testLogout() throws Exception { MockLoginContext loginContext = new MockLoginContext( jaasProvider.getLoginContextName()); JaasAuthenticationToken token = new JaasAuthenticationToken(null, null, loginContext); SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(token); SessionDestroyedEvent event = mock(SessionDestroyedEvent.class); when(event.getSecurityContexts()).thenReturn(Arrays.asList(context)); jaasProvider.handleLogout(event); assertThat(loginContext.loggedOut).isTrue(); }
LoginContext loginContext = token.getLoginContext(); boolean debug = log.isDebugEnabled(); if (loginContext != null) { if (debug) { log.debug("Logging principal: [" + token.getPrincipal() + "] out of LoginContext"); log.debug("Cannot logout principal: [" + token.getPrincipal() + "] from LoginContext. " + "The LoginContext is unavailable");
LoginContext loginContext = token.getLoginContext(); if (loginContext == null) { return null;
JaasAuthenticationToken result = new JaasAuthenticationToken( request.getPrincipal(), request.getCredentials(), new ArrayList<>(authorities), loginContext);
LoginContext loginContext = token.getLoginContext(); boolean debug = this.log.isDebugEnabled(); if (loginContext != null) { if (debug) { this.log.debug("Logging principal: [" + token.getPrincipal() + "] out of LoginContext"); this.log.debug("Cannot logout principal: [" + token.getPrincipal() + "] from LoginContext. " + "The LoginContext is unavailable");
JaasAuthenticationToken result = new JaasAuthenticationToken(request.getPrincipal(), request.getCredentials(), new ArrayList<GrantedAuthority>(authorities), loginContext);
JaasAuthenticationToken result = new JaasAuthenticationToken( request.getPrincipal(), request.getCredentials(), new ArrayList<>(authorities), loginContext);