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


Java PasswordEncoder类代码示例

本文整理汇总了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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:23,代码来源:DefaultCalendarService.java

示例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());
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:25,代码来源:UserManagerImplTest.java

示例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());
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:25,代码来源:UserManagerImplTest.java

示例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());
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:25,代码来源:UserManagerImplTest.java

示例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));
}
 
开发者ID:sercxtyf,项目名称:onboard,代码行数:8,代码来源:PasswordUtilsTest.java

示例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;
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:11,代码来源:AdminUserCreator.java

示例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));
	}
}
 
开发者ID:JD-Software,项目名称:JDeSurvey,代码行数:16,代码来源:UserService.java

示例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);
}
 
开发者ID:JD-Software,项目名称:JDeSurvey,代码行数:9,代码来源:UserService.java

示例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);	
	}
}
 
开发者ID:JD-Software,项目名称:JDeSurvey,代码行数:30,代码来源:UserService.java

示例10: getPasswordEncoder

import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
@Override
protected PasswordEncoder getPasswordEncoder() {
    if (log.isDebugEnabled()) {
        log.debug("Invoking getPasswordEncoder");
    }
    return super.getPasswordEncoder();
}
 
开发者ID:jaschenk,项目名称:jeffaschenk-commons,代码行数:8,代码来源:SecurityServiceProviderImpl.java

示例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);
}
 
开发者ID:jaschenk,项目名称:jeffaschenk-commons,代码行数:8,代码来源:SecurityServiceProviderImpl.java

示例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);
}
 
开发者ID:jirkapinkas,项目名称:example-mailer-spring,代码行数:9,代码来源:UserService.java

示例13: setPasswordEncoder

import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
	this.passwordEncoder = passwordEncoder;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:4,代码来源:UserMaintain.java

示例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);
    }

}
 
开发者ID:dovier,项目名称:coj-web,代码行数:45,代码来源:RestPrivateController.java

示例15: setPasswordEncoder

import org.springframework.security.authentication.encoding.PasswordEncoder; //导入依赖的package包/类
public void setPasswordEncoder(PasswordEncoder passwordEncoder) {
    this.passwordEncoder = passwordEncoder;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:4,代码来源:CustomerServiceImpl.java


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