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();
        verify(auth);
    }
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 void clearAuthenticatedUser() {
        SecurityContextHolder.clearContext();
    }

    private SecurityContext createContext(final User user) {
        SecurityContext securityContext = new SecurityContextImpl();
        securityContext.setAuthentication(new AbstractAuthenticationToken(user.getAuthorities()) {
            private static final long serialVersionUID = 1L;

            @Override
            public Object getCredentials() {
                return "N/A";
View Full Code Here

        }
    }

    private SecurityContext createSecurityContext(UserDetails userDetails) {
        if (userDetails != null) {
            SecurityContextImpl securityContext = new SecurityContextImpl();
            Authentication authentication = new UsernamePasswordAuthenticationToken(userDetails.getUsername(), userDetails.getPassword(), userDetails.getAuthorities());
            securityContext.setAuthentication(authentication);
            return securityContext;
        }
        return SecurityContextHolder.createEmptyContext();
    }
View Full Code Here

  public void testAdditionalAuthenticationChecks() {
    UserDetails user = userDetailService.loadUserByUsername(getTestUser().getUserId());
   
    //remove authentication temporally
    Authentication oriAuth = SecurityContextHolder.getContext().getAuthentication();
    SecurityContextImpl context = new SecurityContextImpl();
    SecurityContextHolder.setContext(context);

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", null);
    try {
      provider.additionalAuthenticationChecks(user, token);
      assertTrue(false);
    } catch (BadCredentialsException e) {
      assertTrue(true);
    }

    token = new UsernamePasswordAuthenticationToken("TEST_USER", "123");
    provider.additionalAuthenticationChecks(user, token);
   
    context.setAuthentication(oriAuth);
  }
View Full Code Here

  protected User testUser = null;

  @Before
  public void beforeSetSecurity() {
    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("admin", null);
    SecurityContextImpl context = new SecurityContextImpl();
    context.setAuthentication(token);
    SecurityContextHolder.setContext(context);
  }
View Full Code Here

    public void clearAuthenticatedUser() {
        SecurityContextHolder.clearContext();
    }

    private SecurityContext createContext(final User user) {
        SecurityContext securityContext = new SecurityContextImpl();
        securityContext.setAuthentication(new AbstractAuthenticationToken(user.getAuthorities()) {
            @Override
            public Object getCredentials() {
                return "N/A";
            }
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

    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();
        verify(auth);
    }
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.