Examples of UsernamePasswordAuthenticationToken


Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

     */
    public static void extendAuthContext(final Long roleId) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(auth.getAuthorities());
        authorities.add(new SimpleGrantedAuthority(EntitlementUtil.getEntitlementNameFromRoleId(roleId)));
        Authentication newAuth = new UsernamePasswordAuthenticationToken(
                auth.getPrincipal(), auth.getCredentials(), authorities);
        SecurityContextHolder.getContext().setAuthentication(newAuth);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

  @Override
  public Authentication authenticate(Authentication auth)
      throws AuthenticationException {
   
    if (auth.getName().equals(auth.getCredentials())) {
      return new UsernamePasswordAuthenticationToken(auth.getName(),
        auth.getCredentials(), AUTHORITIES);
    }
   
    throw new BadCredentialsException("Bad Credentials");
   
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            throws AuthenticationException {
       
        if ( authentication == null ) return null;
        if ( !supports(authentication.getClass()) ) return null;
       
        UsernamePasswordAuthenticationToken retr
            = (UsernamePasswordAuthenticationToken) authentication;
       
        String principal = (String) retr.getPrincipal();
        String password = (String) retr.getCredentials();
       
        PracticalUserDetails user = null;
       
        try {
       
            user = pudsim.loadUserByUsername(principal);
           
        } catch(UsernameNotFoundException ex) {
           
             throw new BadCredentialsException(
                 principal + " principal not found", ex);
           
        }
       
        // Returned user is never null
        if ( !user.isEnabled() ) {
            throw new DisabledException("Username: " + user.getUsername());
        }
       
        if ( !user.isAccountNonLocked() ) {
            throw new LockedException("Username: " + user.getUsername());
        }
       
        if ( !user.getPassword().equals(password) ) {
            throw new BadCredentialsException("Username: " + user.getUsername());
        }
       
        return new UsernamePasswordAuthenticationToken(
            user.getUsername(), user.getPassword(), user.getAuthorities());
       
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        }

        final UserDetails userDetails = new User("admin", "FAKE_PASSWORD", true, true, true, true, authorities);

        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(userDetails, "FAKE_PASSWORD", authorities));
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

                passwordUser.setPassword(authentication.getCredentials().toString(), user.getCipherAlgoritm(), 0);
                authenticated = user.getPassword().equalsIgnoreCase(passwordUser.getPassword());
            }
        }

        UsernamePasswordAuthenticationToken token;

        if (authenticated) {
            token = new UsernamePasswordAuthenticationToken(
                    authentication.getPrincipal(),
                    null,
                    userDetailsService.loadUserByUsername(authentication.getPrincipal().toString()).getAuthorities());

            token.setDetails(authentication.getDetails());

            auditManager.audit(Category.authentication, AuthenticationSubCategory.login, Result.success,
                    "Successfully authenticated, with roles: " + token.getAuthorities());

            LOG.debug("User {} successfully authenticated, with roles {}", authentication.getPrincipal(), token.
                    getAuthorities());

            if (user != null) {
                user.setLastLoginDate(new Date());
                user.setFailedLogins(0);
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        ProviderManager pm = (ProviderManager) appContext.getBeansOfType(ProviderManager.class).values().toArray()[0];
        Object eventPublisher = FieldUtils.getFieldValue(pm, "eventPublisher");
        assertNotNull(eventPublisher);
        assertTrue(eventPublisher instanceof DefaultAuthenticationEventPublisher);

        pm.authenticate(new UsernamePasswordAuthenticationToken("bob", "bobspassword"));
        assertEquals(1, listener.events.size());
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

            password = "wombat";
        } else if ("peter".equals(username)) {
            password = "opal";
        }

        Authentication authRequest = new UsernamePasswordAuthenticationToken(username, password);
        SecurityContextHolder.getContext().setAuthentication(authRequest);
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        chain.doFilter(request, response);
    }

    private Authentication createSuccessfulAuthentication(HttpServletRequest request, UserDetails user) {
        UsernamePasswordAuthenticationToken authRequest;
        if (createAuthenticatedToken) {
            authRequest = new UsernamePasswordAuthenticationToken(user, user.getPassword(), user.getAuthorities());
        }
        else {
            authRequest = new UsernamePasswordAuthenticationToken(user, user.getPassword());
        }

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

        return authRequest;
    }
View Full Code Here

Examples of org.springframework.security.authentication.UsernamePasswordAuthenticationToken

        cap.setServiceProperties(makeServiceProperties());

        cap.setTicketValidator(new MockTicketValidator(true));
        cap.afterPropertiesSet();

        UsernamePasswordAuthenticationToken token =
            new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER, "ST-123");
        token.setDetails("details");

        Authentication result = cap.authenticate(token);

        // Confirm ST-123 was NOT added to the cache
        assertTrue(cache.getByTicketId("ST-456") == null);
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_STATELESS_IDENTIFIER, "ST-456");
        token.setDetails("details");

        Authentication result = cap.authenticate(token);

        // Confirm ST-456 was added to the cache
        assertTrue(cache.getByTicketId("ST-456") != null);
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.