Examples of ShaPasswordEncoder


Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

   *         returns default {@link ShaPasswordEncoder}
   */
  @Bean(name = "shaPasswordEncoder")
  public ShaPasswordEncoder sharPasswordEncoder() {
    boolean useEnhancedEncoding = config.getControllerProperties().getPropertyBoolean(ControllerConstants.PROP_CONTROLLER_USER_PASSWORD_SHA256);
    return useEnhancedEncoding ? new ShaPasswordEncoder(256) : new ShaPasswordEncoder();
  }
View Full Code Here

Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

  public void loadUserExist() {

    //准备数据
    User user = new User();
    user.setLoginName("admin");
    user.setShaPassword(new ShaPasswordEncoder().encodePassword("admin", null));
    Role role1 = new Role();
    role1.setName("admin");
    Role role2 = new Role();
    role2.setName("user");
    user.getRoleList().add(role1);
    user.getRoleList().add(role2);

    //录制脚本
    EasyMock.expect(mockAccountManager.findUserByLoginName("admin")).andReturn(user);
    control.replay();

    //执行测试
    OperatorDetails operator = (OperatorDetails) userDetailsService.loadUserByUsername(user.getLoginName());

    //校验结果
    assertEquals(user.getLoginName(), operator.getUsername());
    assertEquals(new ShaPasswordEncoder().encodePassword("admin", null), operator.getPassword());
    assertEquals(2, operator.getAuthorities().size());
    assertEquals(new GrantedAuthorityImpl("ROLE_admin"), operator.getAuthorities().iterator().next());
    assertNotNull(operator.getLoginTime());
  }
View Full Code Here

Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

   * 如果用户名或密码错误则抛出异常.
   */
  public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    PasswordEncoder encoder = new ShaPasswordEncoder();
    User user = accountManager.findUserByLoginName(pc.getIdentifier());

    if (user == null) {
      throw new IOException("wrong login name " + pc.getIdentifier());
    }
    //对WSPasswordCallback中的明文密码进行sha1散列, 再与数据库中保存的用户sha1散列密码进行比较.
    if (!encoder.isPasswordValid(user.getShaPassword(), pc.getPassword(), null)) {
      throw new IOException("wrong password " + pc.getPassword() + " for " + pc.getIdentifier());
    }
  }
View Full Code Here

Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

    };
  }

  @Bean
  public PasswordEncoder passwordEncoder() {
    return new ShaPasswordEncoder(256);
  }
View Full Code Here

Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

    @Autowired
    private CustomerUserFacade cuFacade;

    @Override
    public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
        ShaPasswordEncoder spe = new ShaPasswordEncoder();
        System.out.println(spe.encodePassword("rest", "rest"));
        //
        CustomUserDetails d = new CustomUserDetails();
        if (string.equals(adminUsername)) {
            d.setIsAdmin(Boolean.TRUE);
            d.setAuthorities(Arrays.asList(createRole("ROLE_ADMIN")));
View Full Code Here

Examples of org.springframework.security.authentication.encoding.ShaPasswordEncoder

    @Bean
    @Autowired
    public AuthenticationProvider authenticationProvider(UserDetailsService usersService) throws Exception {
        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
        provider.setPasswordEncoder(new ShaPasswordEncoder());
        provider.setUserDetailsService(usersService);
        provider.afterPropertiesSet();
        return provider;
    }
View Full Code Here

Examples of org.springframework.security.providers.encoding.ShaPasswordEncoder

        if (doEncrypt) {
            DaoAuthenticationProvider provider = (DaoAuthenticationProvider) ctx.getBean("org.springframework.security.providers.dao.DaoAuthenticationProvider#0");
            String algorithm = WebloggerConfig.getProperty("passwds.encryption.algorithm");
            PasswordEncoder encoder = null;
            if (algorithm.equalsIgnoreCase("SHA")) {
                encoder = new ShaPasswordEncoder();
            } else if (algorithm.equalsIgnoreCase("MD5")) {
                encoder = new Md5PasswordEncoder();
            } else {
                log.error("Encryption algorithm '" + algorithm + "' not supported, disabling encryption.");
            }
View Full Code Here

Examples of org.springframework.security.providers.encoding.ShaPasswordEncoder

        UserDetailsAdapter userDetails = new UserDetailsAdapter(user); // 1
        String password = userDetails.getPassword();
        ReflectionSaltSource saltSource = new ReflectionSaltSource();
        saltSource.setUserPropertyToUse("username");
        Object salt = saltSource.getSalt(userDetails); // 2
        user.setPassword((new ShaPasswordEncoder()).encodePassword(password, salt)); // 3
    }
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.