use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestWrapperTests method testRolePrefix.
@Test
public void testRolePrefix() {
Authentication auth = new TestingAuthenticationToken("user", "koala", "ROLE_HELLO", "ROLE_FOOBAR");
SecurityContextHolder.getContext().setAuthentication(auth);
MockHttpServletRequest request = new MockHttpServletRequest();
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "ROLE_");
assertThat(wrapper.isUserInRole("HELLO")).isTrue();
assertThat(wrapper.isUserInRole("FOOBAR")).isTrue();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestWrapperTests method testUseOfRolePrefixMeansItIsntNeededWhenCallngIsUserInRole.
@Test
public void testUseOfRolePrefixMeansItIsntNeededWhenCallngIsUserInRole() {
Authentication auth = new TestingAuthenticationToken("rod", "koala", "ROLE_FOO");
SecurityContextHolder.getContext().setAuthentication(auth);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/");
SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, "ROLE_");
assertThat(wrapper.isUserInRole("FOO")).isTrue();
}
use of org.springframework.security.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class AuthenticationPrincipalArgumentResolverTests method setAuthenticationPrincipal.
private void setAuthenticationPrincipal(Object principal) {
this.expectedPrincipal = principal;
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(expectedPrincipal, "password", "ROLE_USER"));
}
use of org.springframework.security.authentication.TestingAuthenticationToken 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.authentication.TestingAuthenticationToken in project spring-security by spring-projects.
the class SecurityContextHolderAwareRequestFilterTests method authenticateTrue.
@Test
public void authenticateTrue() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("test", "password", "ROLE_USER"));
assertThat(wrappedRequest().authenticate(this.response)).isTrue();
verifyZeroInteractions(this.authenticationEntryPoint, this.authenticationManager, this.logoutHandler);
verify(this.request, times(0)).authenticate(any(HttpServletResponse.class));
}
Aggregations