本文整理汇总了Java中org.springframework.security.authentication.encoding.PasswordEncoder类的典型用法代码示例。如果您正苦于以下问题:Java PasswordEncoder类的具体用法?Java PasswordEncoder怎么用?Java PasswordEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PasswordEncoder类属于org.springframework.security.authentication.encoding包,在下文中一共展示了PasswordEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DefaultCalendarService
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Autowired
public DefaultCalendarService(final EventDao eventDao,
final CalendarUserDao userDao,
final JdbcOperations jdbcOperations,
final PasswordEncoder passwordEncoder) {
if (eventDao == null) {
throw new IllegalArgumentException("eventDao cannot be null");
}
if (userDao == null) {
throw new IllegalArgumentException("userDao cannot be null");
}
if (jdbcOperations == null) {
throw new IllegalArgumentException("jdbcOperations cannot be null");
}
if (passwordEncoder == null) {
throw new IllegalArgumentException("passwordEncoder cannot be null");
}
this.eventDao = eventDao;
this.userDao = userDao;
this.jdbcOperations = jdbcOperations;
this.passwordEncoder = passwordEncoder;
}
示例2: testSaveUserPasswordEncryptionChanged
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
/**
* Password encryption test method for
* {@link com.impetus.ankush.service.impl.UserManagerImpl#saveUser(com.impetus.ankush.common.domain.model.User)}
* .
* @throws UserExistsException
*/
@Test
public void testSaveUserPasswordEncryptionChanged() throws UserExistsException {
user.setVersion(1);
user.setUsername(user.getUsername().toLowerCase());
String encryptedPassword = "ENCRYPTED"+user.getPassword();
PasswordEncoder passwordEncoder = EasyMock.createMock(PasswordEncoder.class);
((UserManagerImpl)userManager).setPasswordEncoder(passwordEncoder);
EasyMock.expect(passwordEncoder.encodePassword(user.getPassword(), null)).andReturn(encryptedPassword);
EasyMock.expect(userDao.getUserPassword(user.getUsername())).andReturn(user.getPassword()+"Old");
EasyMock.expect(userDao.saveUser(user)).andReturn(user);
EasyMock.replay(userDao, passwordEncoder);
userManager.saveUser(user);
assertEquals("password not encrypted", encryptedPassword, user.getPassword());
}
示例3: testSaveUserPasswordEncryptionNew
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
/**
* Password encryption test method for
* {@link com.impetus.ankush.service.impl.UserManagerImpl#saveUser(com.impetus.ankush.common.domain.model.User)}
* .
* @throws UserExistsException
*/
@Test
public void testSaveUserPasswordEncryptionNew() throws UserExistsException {
user.setVersion(1);
user.setUsername(user.getUsername().toLowerCase());
String encryptedPassword = "ENCRYPTED"+user.getPassword();
PasswordEncoder passwordEncoder = EasyMock.createMock(PasswordEncoder.class);
((UserManagerImpl)userManager).setPasswordEncoder(passwordEncoder);
EasyMock.expect(passwordEncoder.encodePassword(user.getPassword(), null)).andReturn(encryptedPassword);
EasyMock.expect(userDao.getUserPassword(user.getUsername())).andReturn(null);
EasyMock.expect(userDao.saveUser(user)).andReturn(user);
EasyMock.replay(userDao, passwordEncoder);
userManager.saveUser(user);
assertEquals("password not encrypted", encryptedPassword, user.getPassword());
}
示例4: testSaveUserPasswordEncryptionUnchanged
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
/**
* Password encryption test method for
* {@link com.impetus.ankush.service.impl.UserManagerImpl#saveUser(com.impetus.ankush.common.domain.model.User)}
* .
* @throws UserExistsException
*/
@Test
public void testSaveUserPasswordEncryptionUnchanged() throws UserExistsException {
user.setVersion(1);
user.setUsername(user.getUsername().toLowerCase());
String encryptedPassword = "ENCRYPTED"+user.getPassword();
user.setPassword(encryptedPassword);
PasswordEncoder passwordEncoder = EasyMock.createStrictMock(PasswordEncoder.class);
((UserManagerImpl)userManager).setPasswordEncoder(passwordEncoder);
EasyMock.expect(userDao.getUserPassword(user.getUsername())).andReturn(encryptedPassword);
EasyMock.expect(userDao.saveUser(user)).andReturn(user);
EasyMock.replay(userDao, passwordEncoder);
userManager.saveUser(user);
assertEquals("password not encrypted", encryptedPassword, user.getPassword());
}
示例5: testOldPWMigrate
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Test
public void testOldPWMigrate() {
PasswordEncoder encoder = new Md5PasswordEncoder();
String oldPW = encoder.encodePassword(STRING, null).toUpperCase();
String newPW = PasswordUtils.updateOldEncPass(oldPW, DATESTRING);
assertTrue("Old PW should match", PasswordUtils.isPasswordValid(newPW, STRING, DATESTRING));
}
示例6: AdminUserCreator
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public AdminUserCreator(UserRepository userRepository, PasswordEncoder passwordEncoder, @Value("${carldav.admin.name}") String adminName, @Value("${carldav.admin.password:null}") String adminPassword) {
Assert.notNull(userRepository, "userRepository is null");
Assert.notNull(passwordEncoder, "passwordEncoder is null");
Assert.hasText(adminName, "adminName is null");
Assert.hasText(adminPassword, "adminPassword is null");
this.userRepository = userRepository;
this.passwordEncoder = passwordEncoder;
this.adminName = adminName;
this.adminPassword = adminPassword;
}
示例7: user_prepareForgotPasswordMessage
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public String user_prepareForgotPasswordMessage(Long id) {
try {
User user = userDAO.findById(id);
PasswordEncoder encoder = new ShaPasswordEncoder(256);
String hash = encoder.encodePassword(user.getEmail() + new Date().getTime(), user.getSalt());
PasswordResetRequest passwordResetRequest = new PasswordResetRequest(user.getLogin() ,hash);
passwordResetRequestDAO.merge(passwordResetRequest);
return hash;
}
catch (Exception e) {
log.error(e.getMessage(),e);
throw (new RuntimeException(e));
}
}
示例8: user_updatePassword
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Transactional(readOnly = false)
public User user_updatePassword(User user) {
User dbUser = userDAO.findById(user.getId());
dbUser.setLastUpdateDate(new Date());
PasswordEncoder encoder = new ShaPasswordEncoder(256);
dbUser.setPassword(encoder.encodePassword(user.getPassword(), user.getSalt()));
return userDAO.merge(dbUser);
}
示例9: user_merge
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Transactional(readOnly = false)
public User user_merge(User user) {
//create save the password
if (user.getId() == null) {
user.setCreationDate(new Date());
user.setLastUpdateDate(new Date());
PasswordEncoder encoder = new ShaPasswordEncoder(256);
user.setPassword(encoder.encodePassword(user.getPassword(), user.getSalt()));
return userDAO.merge(user);
}
else
//update do not update the password
{
User dbUser = userDAO.findById(user.getId());
dbUser.setLastUpdateDate(new Date());
dbUser.setLogin(user.getLogin());
dbUser.setFirstName(user.getFirstName());
dbUser.setDateOfBirth(user.getDateOfBirth());
dbUser.setMiddleName(user.getMiddleName());
dbUser.setLastName(user.getLastName());
dbUser.setEmail(user.getEmail());
dbUser.setEnabled(user.getEnabled());
dbUser.setGroups(user.getGroups());
dbUser.setDepartments(user.getDepartments());
dbUser.setSurveyDefinitions(user.getSurveyDefinitions());
return userDAO.merge(dbUser);
}
}
示例10: getPasswordEncoder
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Override
protected PasswordEncoder getPasswordEncoder() {
if (log.isDebugEnabled()) {
log.debug("Invoking getPasswordEncoder");
}
return super.getPasswordEncoder();
}
示例11: setPasswordEncoder
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Override
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
if (log.isDebugEnabled()) {
log.debug("Invoking setPasswordEncoder");
}
super.setPasswordEncoder(passwordEncoder);
}
示例12: create
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public User create(User user) {
user.setEnabled(true);
user.setRegistrationDate(new Date());
PasswordEncoder encoder = new Md5PasswordEncoder();
String hashedPass = encoder.encodePassword(user.getPassword(), null);
user.setPassword(hashedPass);
return userRepository.save(user);
}
示例13: setPasswordEncoder
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}
示例14: CreateToken
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@ApiOperation(value = "Autentificar un Usuario",
notes = "Autentica un usuario, de ser correcto devuelve un token con el que se podrá acceder a los demás métodos privados.",
response = TokenRest.class)
@ApiResponses(value = { @ApiResponse(code = 401, message = "username token mismatch<br> hash incorrect<br> token expirated<br> username apikey mismatch<br> apikey hash incorrect<br> apikey expirated<br> apikey secret incorrect<br> token or apikey incorrect"),
@ApiResponse(code = 400, message = "incorrect request") })
@RequestMapping(value = "/login", method = RequestMethod.POST, headers = "Accept=application/json", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<?> CreateToken(
@ApiParam(value = "JSON con el envío") @RequestBody InputUserRest bodyjson){
try {
int error = ValidateApi(bodyjson.getApikey());
if (error > 0) {
return new ResponseEntity<>(TokenUtils.ErrorMessage(error), HttpStatus.UNAUTHORIZED);
}
String username = bodyjson.getUsername();
String password = bodyjson.getPassword();
String sql = "SELECT * FROM public.users WHERE username = ?";
try{
User user = (User) jdbcTemplate.queryForObject(sql,new Object[]{username},new BeanPropertyRowMapper(User.class));
PasswordEncoder encoder = new Md5PasswordEncoder();
password = encoder.encodePassword(password,"ABC123XYZ789");
if(user.getPassword().equals(password)){
TokenRest token = new TokenRest(TokenUtils.CreateTokenUser(username), TokenUtils.expirityToken);
return new ResponseEntity<>(token, HttpStatus.OK);
}
else
return new ResponseEntity<>(ErrorUtils.BAD_USERNAME_PASSWORD, HttpStatus.UNAUTHORIZED);
}catch(Exception e){
return new ResponseEntity<>(ErrorUtils.BAD_USERNAME_PASSWORD, HttpStatus.UNAUTHORIZED);
}
} catch (IOException ex) {
return new ResponseEntity<>(TokenUtils.ErrorMessage(8), HttpStatus.BAD_REQUEST);
}
}
示例15: setPasswordEncoder
import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
this.passwordEncoder = passwordEncoder;
}