use of org.springframework.security.core.context.SecurityContextImpl in project spring-security by spring-projects.
the class Gh3409Tests method unauthenticatedAnonymousUser.
// gh-3409
@Test
public void unauthenticatedAnonymousUser() throws Exception {
// @formatter:off
this.mockMvc.perform(get("/public/").with(securityContext(new SecurityContextImpl())));
this.mockMvc.perform(get("/public/")).andExpect(unauthenticated());
// @formatter:on
}
use of org.springframework.security.core.context.SecurityContextImpl in project spring-security by spring-projects.
the class SessionManagementConfigServlet31Tests method login.
private void login(Authentication auth) {
HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
HttpRequestResponseHolder requestResponseHolder = new HttpRequestResponseHolder(request, response);
repo.loadContext(requestResponseHolder);
SecurityContextImpl securityContextImpl = new SecurityContextImpl();
securityContextImpl.setAuthentication(auth);
repo.saveContext(securityContextImpl, requestResponseHolder.getRequest(), requestResponseHolder.getResponse());
}
use of org.springframework.security.core.context.SecurityContextImpl in project spring-security by spring-projects.
the class SecurityContextHolderTests method testContextHolderGetterSetterClearer.
@Test
public void testContextHolderGetterSetterClearer() {
SecurityContext sc = new SecurityContextImpl();
sc.setAuthentication(new UsernamePasswordAuthenticationToken("Foobar", "pass"));
SecurityContextHolder.setContext(sc);
assertThat(SecurityContextHolder.getContext()).isEqualTo(sc);
SecurityContextHolder.clearContext();
assertThat(SecurityContextHolder.getContext()).isNotSameAs(sc);
SecurityContextHolder.clearContext();
}
use of org.springframework.security.core.context.SecurityContextImpl in project spring-security-oauth by spring-projects.
the class RefreshTokenGrantTests method setup.
@Before
public void setup() {
resource = new ResourceOwnerPasswordResourceDetails();
resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
resource.setClientId("my-trusted-client");
resource.setId("sparklr");
resource.setScope(Arrays.asList("trust"));
resource.setUsername("marissa");
resource.setPassword("koala");
OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
existingToken = template.getAccessToken();
((DefaultOAuth2AccessToken) existingToken).setExpiration(new Date(0L));
SecurityContextImpl securityContext = new SecurityContextImpl();
securityContext.setAuthentication(new TestingAuthenticationToken("marissa", "koala", "ROLE_USER"));
SecurityContextHolder.setContext(securityContext);
}
use of org.springframework.security.core.context.SecurityContextImpl 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);
}
Aggregations