Examples of UsernamePasswordAuthenticationToken


Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        cap.setTicketValidator(validator);
        cap.setServiceProperties(serviceProperties);
        cap.afterPropertiesSet();

        String ticket = "ST-456";
        UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER, ticket);

        Authentication result = cap.authenticate(token);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            password = "";
        }

        username = username.trim();

        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);

        // Allow subclasses to set the "details" property
        setDetails(request, authRequest);

        return this.getAuthenticationManager().authenticate(authRequest);
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        cap.setTicketValidator(validator);
        cap.setServiceProperties(serviceProperties);
        cap.afterPropertiesSet();

        String ticket = "ST-456";
        UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER, ticket);

        Authentication result = cap.authenticate(token);
        verify(validator).validate(ticket, serviceProperties.getService());

        serviceProperties.setAuthenticateAllArtifacts(true);
        result = cap.authenticate(token);
        verify(validator,times(2)).validate(ticket, serviceProperties.getService());

        token.setDetails(details);
        result = cap.authenticate(token);
        verify(validator).validate(ticket, serviceUrl);

        serviceProperties.setAuthenticateAllArtifacts(false);
        serviceProperties.setService(null);
        cap.setServiceProperties(serviceProperties);
        cap.afterPropertiesSet();
        result = cap.authenticate(token);
        verify(validator,times(2)).validate(ticket, serviceUrl);

        token.setDetails(new WebAuthenticationDetails(new MockHttpServletRequest()));
        try {
            cap.authenticate(token);
            fail("Expected Exception");
        }catch(IllegalStateException success) {}
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        cap.setStatelessTicketCache(cache);
        cap.setTicketValidator(new MockTicketValidator(true));
        cap.setServiceProperties(makeServiceProperties());
        cap.afterPropertiesSet();

        UsernamePasswordAuthenticationToken token =
                new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER, "");

        cap.authenticate(token);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        cap.setStatelessTicketCache(new MockStatelessTicketCache());
        cap.setTicketValidator(new MockTicketValidator(true));
        cap.setServiceProperties(makeServiceProperties());
        cap.afterPropertiesSet();

        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("some_normal_user",
                "password", AuthorityUtils.createAuthorityList("ROLE_A"));
        assertEquals(null, cap.authenticate(token));
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        if (password == null) {
            logger.debug("Failed to obtain an artifact (cas ticket)");
            password = "";
        }

        final UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);

        authRequest.setDetails(authenticationDetailsSource.buildDetails(request));

        return this.getAuthenticationManager().authenticate(authRequest);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        final Assertion assertion = new AssertionImpl("test");

        CasAuthenticationToken token1 = new CasAuthenticationToken("key", makeUserDetails(), "Password", ROLES,
                makeUserDetails(), assertion);

        UsernamePasswordAuthenticationToken token2 = new UsernamePasswordAuthenticationToken("Test", "Password", ROLES);
        assertTrue(!token1.equals(token2));
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

     * @throws DisabledException If the target user is disabled.
     * @throws AccountExpiredException If the target user account is expired.
     * @throws CredentialsExpiredException If the target user credentials are expired.
     */
    protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {
        UsernamePasswordAuthenticationToken targetUserRequest;

        String username = request.getParameter(usernameParameter);

        if (username == null) {
            username = "";
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

     * @see SwitchUserGrantedAuthority
     */
    private UsernamePasswordAuthenticationToken createSwitchUserToken(HttpServletRequest request,
            UserDetails targetUser) {

        UsernamePasswordAuthenticationToken targetUserRequest;

        // grant an additional authority that contains the original Authentication object
        // which will be used to 'exit' from the current switched user.

        Authentication currentAuth;

        try {
            // SEC-1763. Check first if we are already switched.
            currentAuth = attemptExitUser(request);
        } catch (AuthenticationCredentialsNotFoundException e) {
            currentAuth = SecurityContextHolder.getContext().getAuthentication();
        }

        GrantedAuthority switchAuthority = new SwitchUserGrantedAuthority(ROLE_PREVIOUS_ADMINISTRATOR, currentAuth);

        // get the original authorities
        Collection<? extends GrantedAuthority> orig = targetUser.getAuthorities();

        // Allow subclasses to change the authorities to be granted
        if (switchUserAuthorityChanger != null) {
            orig = switchUserAuthorityChanger.modifyGrantedAuthorities(targetUser, currentAuth, orig);
        }

        // add the new switch user authority
        List<GrantedAuthority> newAuths = new ArrayList<GrantedAuthority>(orig);
        newAuths.add(switchAuthority);

        // create the new authentication token
        targetUserRequest = new UsernamePasswordAuthenticationToken(targetUser, targetUser.getPassword(), newAuths);

        // set details
        targetUserRequest.setDetails(authenticationDetailsSource.buildDetails(request));

        return targetUserRequest;
    }
View Full Code Here

Examples of org.springframework.security.providers.UsernamePasswordAuthenticationToken

    public void changePassword(String oldPassword, String newPassword) {

        User user = getCurrentUser();

        Authentication oldAuth = new UsernamePasswordAuthenticationToken(
                user.getUsername(), oldPassword);
        authMgr.authenticate(oldAuth);

        createPassWord(user, newPassword);

        log.debug("password changed, saving");
        save(user);

        log.debug("remove from cache");
        userCache.removeUserFromCache(user.getUsername());

        log.debug("change security context");
        Authentication newAuthentication = new UsernamePasswordAuthenticationToken(
                user.getUsername(), newPassword);
        authMgr.authenticate(newAuthentication);
        SecurityContextHolder.getContext().setAuthentication(
                newAuthentication);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.