本文整理汇总了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();
}
示例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";
}
示例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();
}
}
}
示例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);
}
示例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));
}
示例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);
}
示例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();
}
示例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);
}
示例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");
}
}
示例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:/";
}
示例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;
}
示例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);
}
}
示例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()));
}
示例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"));
}
}
示例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);
}