Search in sources :

Example 1 with SessionDestroyedEvent

use of org.springframework.security.core.session.SessionDestroyedEvent in project ma-core-public by infiniteautomation.

the class MangoWebSocketConfiguration method postConstruct.

@PostConstruct
public void postConstruct() {
    // SessionDestroyedEvent from root context are not propagated to the child web context. Register as a listener
    // on the parent.
    ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context.getParent();
    ApplicationListener<SessionDestroyedEvent> listener = this::sessionDestroyed;
    parent.addApplicationListener(listener);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SessionDestroyedEvent(org.springframework.security.core.session.SessionDestroyedEvent) PostConstruct(javax.annotation.PostConstruct)

Example 2 with SessionDestroyedEvent

use of org.springframework.security.core.session.SessionDestroyedEvent in project spring-security by spring-projects.

the class DefaultJaasAuthenticationProviderTests method logoutNullSession.

@Test
public void logoutNullSession() {
    SessionDestroyedEvent event = mock(SessionDestroyedEvent.class);
    this.provider.handleLogout(event);
    verify(event).getSecurityContexts();
    verify(this.log).debug(anyString());
    verifyNoMoreInteractions(event);
}
Also used : SessionDestroyedEvent(org.springframework.security.core.session.SessionDestroyedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with SessionDestroyedEvent

use of org.springframework.security.core.session.SessionDestroyedEvent in project spring-security by spring-projects.

the class DefaultJaasAuthenticationProviderTests method logoutNonJaasAuthentication.

@Test
public void logoutNonJaasAuthentication() {
    SessionDestroyedEvent event = mock(SessionDestroyedEvent.class);
    SecurityContext securityContext = mock(SecurityContext.class);
    given(event.getSecurityContexts()).willReturn(Arrays.asList(securityContext));
    given(securityContext.getAuthentication()).willReturn(this.token);
    this.provider.handleLogout(event);
    verify(event).getSecurityContexts();
    verify(event).getSecurityContexts();
    verify(securityContext).getAuthentication();
    verifyNoMoreInteractions(event, securityContext);
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) SessionDestroyedEvent(org.springframework.security.core.session.SessionDestroyedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with SessionDestroyedEvent

use of org.springframework.security.core.session.SessionDestroyedEvent in project spring-security by spring-projects.

the class DefaultJaasAuthenticationProviderTests method logoutNullAuthentication.

@Test
public void logoutNullAuthentication() {
    SessionDestroyedEvent event = mock(SessionDestroyedEvent.class);
    SecurityContext securityContext = mock(SecurityContext.class);
    given(event.getSecurityContexts()).willReturn(Arrays.asList(securityContext));
    this.provider.handleLogout(event);
    verify(event).getSecurityContexts();
    verify(event).getSecurityContexts();
    verify(securityContext).getAuthentication();
    verifyNoMoreInteractions(event, securityContext);
}
Also used : SecurityContext(org.springframework.security.core.context.SecurityContext) SessionDestroyedEvent(org.springframework.security.core.session.SessionDestroyedEvent) Test(org.junit.jupiter.api.Test)

Example 5 with SessionDestroyedEvent

use of org.springframework.security.core.session.SessionDestroyedEvent in project spring-security by spring-projects.

the class DefaultJaasAuthenticationProviderTests method logout.

@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);
    given(event.getSecurityContexts()).willReturn(Arrays.asList(securityContext));
    given(securityContext.getAuthentication()).willReturn(token);
    given(token.getLoginContext()).willReturn(context);
    this.provider.onApplicationEvent(event);
    verify(event).getSecurityContexts();
    verify(securityContext).getAuthentication();
    verify(token).getLoginContext();
    verify(context).logout();
    verifyNoMoreInteractions(event, securityContext, token, context);
}
Also used : LoginContext(javax.security.auth.login.LoginContext) SecurityContext(org.springframework.security.core.context.SecurityContext) SessionDestroyedEvent(org.springframework.security.core.session.SessionDestroyedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

SessionDestroyedEvent (org.springframework.security.core.session.SessionDestroyedEvent)10 Test (org.junit.jupiter.api.Test)8 SecurityContext (org.springframework.security.core.context.SecurityContext)7 LoginContext (javax.security.auth.login.LoginContext)2 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 LoginException (javax.security.auth.login.LoginException)1 Test (org.junit.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1