Package org.springframework.security.crypto.password

Examples of org.springframework.security.crypto.password.PasswordEncoder


    }

    // SEC-2056
    public void testUserNotFoundEncodesPassword() {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("missing", "koala");
        PasswordEncoder encoder = mock(PasswordEncoder.class);
        when(encoder.encode(anyString())).thenReturn("koala");
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setHideUserNotFoundExceptions(false);
        provider.setPasswordEncoder(encoder);
        provider.setUserDetailsService(new MockAuthenticationDaoUserrod());
        try {
View Full Code Here


        verify(encoder).matches(isA(String.class),  isA(String.class));
    }

    public void testUserNotFoundBCryptPasswordEncoder() {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("missing", "koala");
        PasswordEncoder encoder =  new BCryptPasswordEncoder();
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setHideUserNotFoundExceptions(false);
        provider.setPasswordEncoder(encoder);
        MockAuthenticationDaoUserrod userDetailsService = new MockAuthenticationDaoUserrod();
        userDetailsService.password = encoder.encode((CharSequence) token.getCredentials());
        provider.setUserDetailsService(userDetailsService);
        try {
            provider.authenticate(token);
            fail("Expected Exception");
        } catch(UsernameNotFoundException success) {}
View Full Code Here

     * deterministic and {@link #testUserNotFoundEncodesPassword()} ensures that SEC-2056 is fixed.
     */
    public void IGNOREtestSec2056() {
        UsernamePasswordAuthenticationToken foundUser = new UsernamePasswordAuthenticationToken("rod", "koala");
        UsernamePasswordAuthenticationToken notFoundUser = new UsernamePasswordAuthenticationToken("notFound", "koala");
        PasswordEncoder encoder = new BCryptPasswordEncoder(10,new SecureRandom());
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setHideUserNotFoundExceptions(false);
        provider.setPasswordEncoder(encoder);
        MockAuthenticationDaoUserrod userDetailsService = new MockAuthenticationDaoUserrod();
        userDetailsService.password = encoder.encode((CharSequence) foundUser.getCredentials());
        provider.setUserDetailsService(userDetailsService);

        int sampleSize = 100;

        List<Long> userFoundTimes = new ArrayList<Long>(sampleSize);
View Full Code Here

        return sum / counts.size();
    }

    public void testUserNotFoundNullCredentials() {
        UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("missing", null);
        PasswordEncoder encoder = mock(PasswordEncoder.class);
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setHideUserNotFoundExceptions(false);
        provider.setPasswordEncoder(encoder);
        provider.setUserDetailsService(new MockAuthenticationDaoUserrod());
        try {
View Full Code Here

        }

        ApplicationContext ctx =
                WebApplicationContextUtils.getRequiredWebApplicationContext(context);

        PasswordEncoder passwordEncoder = null;
        try {
            ProviderManager provider = (ProviderManager) ctx.getBean("org.springframework.security.authentication.ProviderManager#0");
            for (Object o : provider.getProviders()) {
                AuthenticationProvider p = (AuthenticationProvider) o;
                if (p instanceof RememberMeAuthenticationProvider) {
                    config.put("rememberMeEnabled", Boolean.TRUE);
                } else if (ctx.getBean("passwordEncoder") != null) {
                    passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
                }
            }
        } catch (NoSuchBeanDefinitionException n) {
            log.debug("authenticationManager bean not found, assuming test and ignoring...");
            // ignore, should only happen when testing
        }

        context.setAttribute(Constants.CONFIG, config);

        // output the retrieved values for the Init and Context Parameters
        if (log.isDebugEnabled()) {
            log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
            if (passwordEncoder != null) {
                log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
            }
            log.debug("Populating drop-downs...");
        }

        setupContext(context);
View Full Code Here

  }

  @Transactional
  public void createTestUsers() {
    PasswordEncoder encoder = injector.getInstance(PasswordEncoder.class);

    RoleEntity adminRole = new RoleEntity();
    adminRole.setRoleName("admin");

    UserEntity admin = new UserEntity();
    admin.setUserName("administrator");
    admin.setUserPassword(encoder.encode("admin"));

    Set<RoleEntity> roles = new HashSet<RoleEntity>();
    Set<UserEntity> users = new HashSet<UserEntity>();

    roles.add(adminRole);
    users.add(admin);

    admin.setRoleEntities(roles);
    adminRole.setUserEntities(users);

    userDAO.create(admin);
    roleDAO.create(adminRole);

    UserEntity userWithoutRoles = new UserEntity();
    userWithoutRoles.setUserName("userWithoutRoles");
    userWithoutRoles.setUserPassword(encoder.encode("test"));
    userDAO.create(userWithoutRoles);

  }
View Full Code Here

     */
    @Override
    public boolean isPaswordCorrect(User user, String password) {
        // load fresh user version from db to be sure to have current password.
        User userFromDb = findById(user.getId());
        PasswordEncoder encoder = new StandardPasswordEncoder();
        String encodedPassword = encoder.encode(password);
        return encodedPassword.equals(userFromDb.getPassword());
    }
View Full Code Here

     * @see ${package}.services.IUserService${symbol_pound}changePassword(${package}.domain.User, java.lang.String)
     */
    @Override
    @Transactional(readOnly = false)
    public void changePassword(User user, String newPassword) {
        PasswordEncoder encoder = new StandardPasswordEncoder();
        String encodedPassword = encoder.encode(newPassword);
        // load fresh user version from db to have managed version and avoid optimistic lock exception.
        User userFromDb = findById(user.getId());
        userFromDb.setPassword(encodedPassword);
        update(userFromDb);
    }
View Full Code Here

     */
    @Override
    public boolean isPaswordCorrect(User user, String password) {
        // load fresh user version from db to be sure to have current password.
        User userFromDb = findById(user.getId());
        PasswordEncoder encoder = new StandardPasswordEncoder();
        String encodedPassword = encoder.encode(password);
        return encodedPassword.equals(userFromDb.getPassword());
    }
View Full Code Here

     * @see org.happyfaces.services.IUserService#changePassword(org.happyfaces.domain.User, java.lang.String)
     */
    @Override
    @Transactional(readOnly = false)
    public void changePassword(User user, String newPassword) {
        PasswordEncoder encoder = new StandardPasswordEncoder();
        String encodedPassword = encoder.encode(newPassword);
        // load fresh user version from db to have managed version and avoid optimistic lock exception.
        User userFromDb = findById(user.getId());
        userFromDb.setPassword(encodedPassword);
        update(userFromDb);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.crypto.password.PasswordEncoder

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.