Package org.springframework.security.core.context

Examples of org.springframework.security.core.context.SecurityContextImpl


    public void getAuthenticatedUser_wrongPrincipalType() {
        AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
        expect(auth.getPrincipal()).andReturn(USER_ID).anyTimes();
        replay(auth);

        SecurityContext context = new SecurityContextImpl();
        SecurityContextHolder.setContext(context);

        service.getAuthenticatedUser();
    }
View Full Code Here


     }


    @Test
    public void clearAuthentication() {
        SecurityContext context = new SecurityContextImpl();
        SecurityContextHolder.setContext(context);
        service.clearAuthenticatedUser();
        assertThat(SecurityContextHolder.getContext(), not(sameInstance(context)));
    }
View Full Code Here

public class SpringSecurityContextFactory implements SecurityContextFactory
{
    @Override
    public SecurityContext create(Authentication authentication)
    {
        org.springframework.security.core.context.SecurityContext context = new SecurityContextImpl();
        context.setAuthentication(((SpringAuthenticationAdapter)authentication).getDelegate());

        if (authentication.getProperties() != null)
        {
            if (authentication.getProperties().containsKey("securityMode"))
            {
View Full Code Here

    @Override
    public void doTearDown()
    {
        // Clear the security context after each test.
        SecurityContextHolder.setContext(new SecurityContextImpl());
    }
View Full Code Here

    @Override
    public void doTearDown()
    {
        // Clear the security context after each test.
        SecurityContextHolder.setContext(new SecurityContextImpl());
    }
View Full Code Here

    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);

  }
View Full Code Here

        authorities.add(new GrantedAuthorityImpl(sc.getRole()));
        OAuthAuthenticationToken newAuthToken = new OAuthAuthenticationToken(new ForceUserPrincipal(sc.getUserName(),
                sc.getSessionId()), null, authorities);
        newAuthToken.setDetails(sc.getForceSecurityContext());

        org.springframework.security.core.context.SecurityContext springSecurityContext = new SecurityContextImpl();
        springSecurityContext.setAuthentication(newAuthToken);
        SecurityContextHolder.setContext(springSecurityContext);
    }
View Full Code Here

    }

  //--------------------------------------------------------------------------
   
    public void loginAs(User user) {
        SecurityContextImpl secContext = new SecurityContextImpl();
        Authentication authentication = new UsernamePasswordAuthenticationToken(
                user, null);
        secContext.setAuthentication(authentication);
        SecurityContextHolder.setContext(secContext);
    }
View Full Code Here

        final User authUser = new UserImpl(USER_ID);
        AbstractAuthenticationToken auth = createNiceMock(AbstractAuthenticationToken.class);
        expect(auth.getPrincipal()).andReturn(authUser).anyTimes();
        replay(auth);

        SecurityContext context = new SecurityContextImpl();
        context.setAuthentication(auth);
        SecurityContextHolder.setContext(context);

        User result = service.getAuthenticatedUser();

        assertThat(result, is(sameInstance(authUser)));
View Full Code Here

    }

    @Test(expected = SecurityException.class)
    public void getAuthenticatedUser_nullAuth() {

        SecurityContext context = new SecurityContextImpl();
        SecurityContextHolder.setContext(context);
        service.getAuthenticatedUser();
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.core.context.SecurityContextImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.