Search in sources :

Example 16 with SecurityContextImpl

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
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Test(org.junit.Test)

Example 17 with SecurityContextImpl

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());
}
Also used : HttpRequestResponseHolder(org.springframework.security.web.context.HttpRequestResponseHolder) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) HttpSessionSecurityContextRepository(org.springframework.security.web.context.HttpSessionSecurityContextRepository)

Example 18 with SecurityContextImpl

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();
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Test(org.junit.Test)

Example 19 with SecurityContextImpl

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);
}
Also used : ResourceOwnerPasswordResourceDetails(org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Date(java.util.Date) Before(org.junit.Before)

Example 20 with SecurityContextImpl

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);
}
Also used : SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) SecurityContext(org.springframework.security.core.context.SecurityContext) Test(org.junit.Test)

Aggregations

SecurityContextImpl (org.springframework.security.core.context.SecurityContextImpl)69 Authentication (org.springframework.security.core.Authentication)48 SecurityContext (org.springframework.security.core.context.SecurityContext)46 MifosUser (org.mifos.security.MifosUser)38 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)38 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)29 Test (org.junit.Test)18 Before (org.junit.Before)16 GrantedAuthority (org.springframework.security.core.GrantedAuthority)15 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)11 ArrayList (java.util.ArrayList)8 TgolUserDetails (org.asqatasun.webapp.security.userdetails.TgolUserDetails)5 MeetingBO (org.mifos.application.meeting.business.MeetingBO)5 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)5 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)5 Date (java.util.Date)4 LocalDate (org.joda.time.LocalDate)4 Money (org.mifos.framework.util.helpers.Money)4 BigDecimal (java.math.BigDecimal)3