Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken


        String username = authentication.getPrincipal().toString();
        Object credentials = authentication.getCredentials();
        String password = credentials == null ? null : credentials.toString();
        Collection<? extends GrantedAuthority> authorities = remoteAuthenticationManager.attemptAuthentication(username, password);

        return new UsernamePasswordAuthenticationToken(username, password, authorities);
    }
View Full Code Here


            UserDetails user) {
        // Ensure we return the original credentials the user supplied,
        // so subsequent attempts are successful even with encoded passwords.
        // Also ensure we return the original getDetails(), so that future
        // authentication events after cache expiry contain the details
        UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(principal,
                authentication.getCredentials(), authoritiesMapper.mapAuthorities(user.getAuthorities()));
        result.setDetails(authentication.getDetails());

        return result;
    }
View Full Code Here

    public void testDianneRetrieval() {
        process("dianne", "emu", false);
    }

    protected void process(String username, String password, boolean shouldBeFiltered) {
        SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(username, password));
        System.out.println("------ Test for username: " + username + " ------");
        AbstractElement[] rootElements = documentDao.findElements(Directory.ROOT_DIRECTORY);
        assertEquals(3, rootElements.length);
        Directory homeDir = null;
        Directory nonHomeDir = null;
View Full Code Here

        return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
    }

    public void testContextIsResetEvenIfExceptionOccurs() throws Exception {
        // Setup client-side context
        Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
        SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);

        ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();

        try {
View Full Code Here

        assertNull("Authentication must be null ", SecurityContextHolder.getContext().getAuthentication());
    }

    public void testNormalOperation() throws Exception {
        // Setup client-side context
        Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
        SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);

        ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();

        // Set to null, as ContextPropagatingRemoteInvocation already obtained
View Full Code Here

        assertEquals("some_string Authentication empty", remoteInvocation.invoke(new TargetObject()));
    }

    // SEC-1867
    public void testNullCredentials() throws Exception {
        Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", null);
        SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);

        ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
        assertEquals(null, ReflectionTestUtils.getField(remoteInvocation, "credentials"));
    }
View Full Code Here

    public void setup() {
        user = new User();
        user.setId(0L);
        List<GrantedAuthority> authorities =
                AuthorityUtils.createAuthorityList("ROLE_USER");
        UsernamePasswordAuthenticationToken authentication =
                new UsernamePasswordAuthenticationToken(user, "notused", authorities);
        SecurityContextHolder
                .getContext()
                .setAuthentication(authentication);
    }
View Full Code Here

        SecurityContextHolder.clearContext();
    }

    public void testNormalOperation() throws Exception {
        // Setup client-side context
        Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("Aladdin", "open sesame");
        SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);

        // Create a connection and ensure our executor sets its
        // properties correctly
        AuthenticationSimpleHttpInvokerRequestExecutor executor = new AuthenticationSimpleHttpInvokerRequestExecutor();
View Full Code Here

        assertTrue(obj1.equals(obj2));
    }

    public void testSecurityContextCorrectOperation() {
        SecurityContext context = new SecurityContextImpl();
        Authentication auth = new UsernamePasswordAuthenticationToken("rod", "koala");
        context.setAuthentication(auth);
        assertEquals(auth, context.getAuthentication());
        assertTrue(context.toString().lastIndexOf("rod") != -1);
    }
View Full Code Here

        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
    }

    public void testContextHolderGetterSetterClearer() {
        SecurityContext sc = new SecurityContextImpl();
        sc.setAuthentication(new UsernamePasswordAuthenticationToken("Foobar", "pass"));
        SecurityContextHolder.setContext(sc);
        assertEquals(sc, SecurityContextHolder.getContext());
        SecurityContextHolder.clearContext();
        assertNotSame(sc, SecurityContextHolder.getContext());
        SecurityContextHolder.clearContext();
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

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.