use of org.springframework.security.core.context.SecurityContext in project spring-security by spring-projects.
the class SecurityContextLogoutHandlerTests method clearsAuthentication.
// SEC-2025
@Test
public void clearsAuthentication() {
SecurityContext beforeContext = SecurityContextHolder.getContext();
handler.logout(request, response, SecurityContextHolder.getContext().getAuthentication());
assertThat(beforeContext.getAuthentication()).isNull();
}
use of org.springframework.security.core.context.SecurityContext in project spring-security by spring-projects.
the class SecurityContextLogoutHandlerTests method disableClearsAuthentication.
@Test
public void disableClearsAuthentication() {
handler.setClearAuthentication(false);
SecurityContext beforeContext = SecurityContextHolder.getContext();
Authentication beforeAuthentication = beforeContext.getAuthentication();
handler.logout(request, response, SecurityContextHolder.getContext().getAuthentication());
assertThat(beforeContext.getAuthentication()).isNotNull();
assertThat(beforeContext.getAuthentication()).isSameAs(beforeAuthentication);
}
use of org.springframework.security.core.context.SecurityContext in project spring-security by spring-projects.
the class HttpSessionDestroyedEventTests method getSecurityContextsMulti.
@Test
public void getSecurityContextsMulti() {
session.setAttribute("another", new SecurityContextImpl());
List<SecurityContext> securityContexts = destroyedEvent.getSecurityContexts();
assertThat(securityContexts).hasSize(2);
}
use of org.springframework.security.core.context.SecurityContext in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestFilterTests method startAsyncWithRequestResponseStart.
@Test
public void startAsyncWithRequestResponseStart() throws Exception {
ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
SecurityContext context = SecurityContextHolder.createEmptyContext();
TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password", "ROLE_USER");
context.setAuthentication(expectedAuth);
SecurityContextHolder.setContext(context);
AsyncContext asyncContext = mock(AsyncContext.class);
when(this.request.startAsync(this.request, this.response)).thenReturn(asyncContext);
Runnable runnable = new Runnable() {
@Override
public void run() {
}
};
wrappedRequest().startAsync(this.request, this.response).start(runnable);
verifyZeroInteractions(this.authenticationManager, this.logoutHandler);
verify(asyncContext).start(runnableCaptor.capture());
DelegatingSecurityContextRunnable wrappedRunnable = (DelegatingSecurityContextRunnable) runnableCaptor.getValue();
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegateSecurityContext")).isEqualTo(context);
assertThat(WhiteboxImpl.getInternalState(wrappedRunnable, "delegate")).isEqualTo(runnable);
}
use of org.springframework.security.core.context.SecurityContext in project head by mifos.
the class RepayLoanActionStrutsTest method setMifosUserFromContext.
private void setMifosUserFromContext() {
SecurityContext securityContext = new SecurityContextImpl();
MifosUser principal = new MifosUser(userContext.getId(), userContext.getBranchId(), userContext.getLevelId(), new ArrayList<Short>(userContext.getRoles()), userContext.getName(), "".getBytes(), true, true, true, true, new ArrayList<GrantedAuthority>(), userContext.getLocaleId());
Authentication authentication = new TestingAuthenticationToken(principal, principal);
securityContext.setAuthentication(authentication);
SecurityContextHolder.setContext(securityContext);
}
Aggregations