当前位置: 首页>>代码示例>>Java>>正文


Java StandardPasswordEncoder类代码示例

本文整理汇总了Java中org.springframework.security.crypto.password.StandardPasswordEncoder的典型用法代码示例。如果您正苦于以下问题:Java StandardPasswordEncoder类的具体用法?Java StandardPasswordEncoder怎么用?Java StandardPasswordEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StandardPasswordEncoder类属于org.springframework.security.crypto.password包,在下文中一共展示了StandardPasswordEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBcrypt

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Test
public void testBcrypt(){
	String pwd = "jfish";
	StandardPasswordEncoder def = new StandardPasswordEncoder();
	BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
	
	TimeCounter time = new TimeCounter("sha");
	int times = 1;
	time.start();
	LangOps.ntimesRun(times, ()->{
		def.encode(pwd);
	});
	time.stop();
	
	time.restart("bcrypt");
	LangOps.ntimesRun(times, ()->{
		String str = encoder.encode(pwd);
		System.out.println("BCrypt "+str.length()+":"+str);
	});
	time.stop();
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:22,代码来源:PasswordEncoderTest.java

示例2: registera

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@RequestMapping(value="/register", method = RequestMethod.POST)
	public String registera(Locale locale, 
			@RequestParam(value="username", required=false) String username,
			@RequestParam(value="password", required=false) String password,
			@RequestParam(value="firstName", required=false) String firstName,
			@RequestParam(value="lastName", required=false) String lastName,
			@RequestParam(value="email", required=false) String email,
			Model model) {	
		StandardPasswordEncoder encoder = new StandardPasswordEncoder();
		User user = new User();
		user.setUsername(username);
		user.setPassword(encoder.encode(password));
		user.setFirstName(firstName);
		user.setLastName(lastName);
		user.setEmail(email);
//		user.setStatus(status);
//		List<Roles> roles = new ArrayList<>();
//		user.setRoles(roles);
		usersRepository.save(user);
		return "redirect:login";
	}
 
开发者ID:rgajam,项目名称:sb-starter,代码行数:22,代码来源:RegistrationCtrl.java

示例3: getPasswordEncoder

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
public static PasswordEncoder getPasswordEncoder(String algorithm) {
    if (algorithm == null) {
        algorithm = "";
    }

    switch (algorithm) {
        case BCRYPT_ENCODER:
            return new BCryptPasswordEncoder();
        case NO_ENCODER:
            return NoOpPasswordEncoder.getInstance();
        case SHA_256_ENCODER:
            return new StandardPasswordEncoder();
        default: {
            LOGGER.error("No password encoder for algorithm " + algorithm + " found. "
            + "Password encoding is switched off.");
            return NoOpPasswordEncoder.getInstance();
        }
    }
}
 
开发者ID:patka,项目名称:cognitor,代码行数:20,代码来源:PasswordEncoderFactory.java

示例4: encodePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
/**
 * Encodes a given raw password with random salt via Spring {@link StandardPasswordEncoder}.
 *
 * @param  rawPassword  plaintext password
 *
 * @return  encoded password
 */
public static String encodePassword(String rawPassword) {

    /**
     * TODO: Think about to use a better password encoder
     *
     * Comment within StandardPasswordEncoder:
     *
     * If you are developing a new system,
     * {@link org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder} is
     * a better choice both in terms of security and interoperability with other languages.
     */

    StandardPasswordEncoder encoder = new StandardPasswordEncoder();

    return encoder.encode(rawPassword);
}
 
开发者ID:synyx,项目名称:urlaubsverwaltung,代码行数:24,代码来源:CryptoUtil.java

示例5: testStandardPasswordEncoder

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Test
public void testStandardPasswordEncoder(){
    PasswordEncoder passwordEncoder = new StandardPasswordEncoder("web_qq");
    String password1 = passwordEncoder.encode("12345");
    String password2 = passwordEncoder.encode("mingguobin4");
    System.out.println("password1:"+password1);
    System.out.println("password2:"+password2);
    System.out.println(passwordEncoder.matches("mingguobin4",password1));
}
 
开发者ID:damingerdai,项目名称:web-qq,代码行数:10,代码来源:PasswordEncoderTest.java

示例6: verifyPasswordEncoderByCustomClassName

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Test
public void verifyPasswordEncoderByCustomClassName() {
    final PasswordEncoderProperties p = new PasswordEncoderProperties();
    p.setType(StandardPasswordEncoder.class.getName());
    p.setSecret("SECRET");
    final PasswordEncoder e = Beans.newPasswordEncoder(p);
    assertNotNull(e);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:DefaultPasswordEncoderTests.java

示例7: createUserDetails

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
private static UserDetails createUserDetails(String whiteList, SystemUser.Role role) {
    SystemUser systemUser = new SystemUser();
    systemUser.setId(1L);
    systemUser.setUsername("username");
    systemUser.setRole(role);
    systemUser.setPasswordAsPlaintext("password", new StandardPasswordEncoder());
    systemUser.setIpWhiteList(whiteList);

    return new UserInfo.UserInfoBuilder(systemUser).createUserInfo();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:11,代码来源:RemoteAddressBlockerTest.java

示例8: testSpringPasswordEncoderInstance

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Test
public void testSpringPasswordEncoderInstance() {
    PasswordEncoder passwordEncoder = autoWiredIdmIdmEngineConfiguration.getPasswordEncoder();

    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(new SpringEncoder(new Md5PasswordEncoder()));
    validatePassword();

    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(new SpringEncoder(new StandardPasswordEncoder()));
    validatePassword();
    
    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(passwordEncoder);
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:13,代码来源:SpringPasswordEncoderTest.java

示例9: validate

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Override
public void validate(Object target, Errors errors) {
    PasswordUpdateForm form = (PasswordUpdateForm) target;
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    User user = (User) authentication.getPrincipal();
    if (!new StandardPasswordEncoder().matches(form.getCurrentPassword(), user.getPassword())) {
        errors.rejectValue("currentPassword", "error.wrongPassword");
    }
    if (!form.getNewPassword().equals(form.getNewPasswordConfirm())) {
        errors.rejectValue("newPasswordConfirm", "error.unmatched");
    }
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:13,代码来源:PasswordMatchValidator.java

示例10: update

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@RequestMapping("/update")
public String update(@AuthenticationPrincipal User user, @Validated PasswordUpdateForm form, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return edit(form);
    }
    user.setPassword(new StandardPasswordEncoder().encode(form.getNewPassword()));
    userRepository.save(user);
    return "redirect:/";
}
 
开发者ID:ksoichiro,项目名称:todo,代码行数:10,代码来源:PasswordController.java

示例11: createPasswordServiceDbImpl

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
public static PasswordServiceImpl createPasswordServiceDbImpl() {
	PasswordServiceImpl ret = new PasswordServiceImpl();

	ret.setPasswordEncoder(new StandardPasswordEncoder("test"));

	UserService userService = UserServiceImplFactory.createUsersServiceImpl();
	ret.setUserService(userService);

	PasswordDao passwordDao = Mockito.mock(PasswordDao.class);
	ret.setPasswordDao(passwordDao);

	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER))
			.thenReturn(PasswordFactory.createExistentUserPassword());
	when(passwordDao.findPasswordByUserUuid(UserFactory.NON_EXISTENT_USER)).thenReturn(null);
	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD)).thenReturn(null);
	when(passwordDao.findPasswordByUserUuid(UserFactory.USER_RESULT_IN_EXCEPTION))
			.thenThrow(new IllegalStateException("Simulate unexpected excception"));
	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER_2_PROBLEM_WITH_PASSWORD))
			.thenThrow(new IllegalStateException("Simulate unexpected excception"));

	when(passwordDao.updateUserPassword(eq(UserFactory.EXISTENT_USER), anyString())).thenReturn(1);
	when(passwordDao.updateUserPassword(eq(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD), anyString()))
			.thenReturn(0);

	when(passwordDao.setRestorationToken(eq(UserFactory.EXISTENT_USER), anyString())).thenReturn(1);
	when(passwordDao.setRestorationToken(eq(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD), anyString()))
			.thenReturn(0);

	return ret;
}
 
开发者ID:skarpushin,项目名称:summerb,代码行数:31,代码来源:PasswordServiceDbImplFactory.java

示例12: initAdminUserIfNotExists

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
private void initAdminUserIfNotExists()
{
	User myuser = userManager.getUserByEmail(config.ADMIN_USER);

	if (myuser == null)
	{
		// first user
		myuser = new User();
		UserGroup myGroup = new UserGroup();
		myuser.setAdmin(true);
		myuser.setFirstname("Admin");
		myuser.setLastname("User");
		myuser.setEmail(config.ADMIN_USER);
		StandardPasswordEncoder sp = new StandardPasswordEncoder();
		myuser.setPassword(sp.encode(config.ADMIN_PASSWORD));
		myuser.setDisabled(false);
		myuser.setUserGroup(myGroup);
		userManager.saveOrUpdateUser(myuser);

		// generate empty project
		ProjectManager projectManager = (ProjectManager) AppContext.getApplicationContext().getBean("ProjectManager", ProjectManager.class);
		projectManager.createProject(myuser, false);

		myGroup.setMaxProjects(50);
		userManager.saveOrUpdateUser(myuser);
	}
}
 
开发者ID:bonprix,项目名称:solidsearch-bot,代码行数:28,代码来源:BotInitializer.java

示例13: encodePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Test
public void encodePassword() throws Exception {
	StandardPasswordEncoder encoder = new StandardPasswordEncoder();
	String result = encoder.encode("password01");
	assertTrue(encoder.matches("password01", result));
	logger.info("Encoded password is {}", result);
	assertThat(result,is(notNullValue()));
}
 
开发者ID:lucamartellucci,项目名称:bookshop-api,代码行数:9,代码来源:PasswordEncoder.java

示例14: onStartup

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@PostConstruct
public void onStartup() {

    List<User> allUsers = userRepository.findAll();

    if (allUsers.size() == 0) {
        userRepository.save(new User("admin", new StandardPasswordEncoder().encode("admin"), "admin"));
    }
}
 
开发者ID:djschilling,项目名称:workinghours,代码行数:10,代码来源:Startup.java

示例15: changePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //导入依赖的package包/类
@Override
public void changePassword(String username, String password) {

    User user = userRepository.findOne(username);
    user.setPassword(new StandardPasswordEncoder().encode(password));
    userRepository.save(user);
}
 
开发者ID:djschilling,项目名称:workinghours,代码行数:8,代码来源:UserServiceImpl.java


注:本文中的org.springframework.security.crypto.password.StandardPasswordEncoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。