本文整理汇总了Java中org.springframework.security.authentication.encoding.ShaPasswordEncoder类的典型用法代码示例。如果您正苦于以下问题:Java ShaPasswordEncoder类的具体用法?Java ShaPasswordEncoder怎么用?Java ShaPasswordEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShaPasswordEncoder类属于org.springframework.security.authentication.encoding包,在下文中一共展示了ShaPasswordEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
static public void main(String[] args ) {
if (args == null || args.length != 2) {
System.out.println("Please use: EssencePasswordEncoderSHA username password");
System.exit(1);
}
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String hash = encoder.encodePassword(args[1], args[0]); // pwd, salt
System.out.println("Encoded password for " + args[0] + "/" + args[1] + " is: " + hash);
}
示例2: init
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
ShaPasswordEncoder encoder = new ShaPasswordEncoder();
encoder.setEncodeHashAsBase64(true);
auth
.inMemoryAuthentication()
.passwordEncoder(encoder)
.withUser("admin").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("ADMIN").and()
.withUser("coordinator").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("COORDINATOR");
User coordinator = new Coordinator();
coordinator.setUsername("coordinator");
userRepository.save(coordinator);
auth
.ldapAuthentication()
.userSearchFilter("uid={0}")
.contextSource().url("ldap://dir3.udl.net:389/dc=UdL,dc=es")
.and()
.userDetailsContextMapper(userDetailsContextMapper);
}
示例3: save
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public User save(User user) {
logger.debug("UserServiceImpl - save: plainPassword: " + user.getPlainPassword());
// get existing user for salt string
if (user.getId() == 0L && user.getPlainPassword() != null) {
// create salt and password for inserted or updated user
ShaPasswordEncoder pwdEnc = new ShaPasswordEncoder();
user.setSalt(user.getUsername() + "-" + user.getEmail());
user.setPassword(pwdEnc.encodePassword(user.getPlainPassword(), user.getSalt()));
}
// save new or updated user
return userDao.save(user);
}
示例4: main
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
public static void main(String[] args) {
ShaPasswordEncoder enc = new ShaPasswordEncoder(512);
enc.setIterations(1000);
enc.setEncodeHashAsBase64(true);
String encodedPass = enc.encodePassword("nesa", "nesa");
System.out.println(encodedPass);
System.out.println(enc.isPasswordValid(encodedPass, "nesa", "nesa"));
}
示例5: testSha
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@SuppressWarnings("unused")
static private void testSha() {
ShaPasswordEncoder encoder = new ShaPasswordEncoder();
String hash = encoder.encodePassword("test1", "test1"); // pwd, salt
System.out.println("test1:" + hash);
System.out.println("test2:" + encoder.encodePassword("test2", "test2"));
ShaPasswordEncoder encoder1 = new ShaPasswordEncoder(256);
String hash1 = encoder1.encodePassword("test1", "test1"); // pwd, salt
System.out.println("test1-256:" + hash1);
}
示例6: init
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
ShaPasswordEncoder encoder = new ShaPasswordEncoder();
encoder.setEncodeHashAsBase64(true);
auth
.inMemoryAuthentication()
.passwordEncoder(encoder)
.withUser("admin").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("ADMIN").and()
.withUser("coordinator1").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("COORDINATOR").and()
.withUser("professor1").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("PROFESSOR", "PROPONENT").and()
.withUser("student1").password("18LcJuI3xeanShlrg/oherDmVf4=").roles("STUDENT", "PROFESSOR");
}
示例7: InternalAuthenticationProvider
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Autowired
public InternalAuthenticationProvider(SCIMUserProvisioning userProvisioning,
ShaPasswordEncoder shaPasswordEncoder,
BCryptPasswordEncoder bCryptPasswordEncoder,
@Value("${osiam.tempLock.count:0}") Integer maxLoginFailures,
@Value("${osiam.tempLock.timeout:0}") Integer lockTimeout) {
this.userProvisioning = userProvisioning;
this.shaPasswordEncoder = shaPasswordEncoder;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
this.maxLoginFailures = maxLoginFailures;
this.lockTimeout = lockTimeout;
}
示例8: user_prepareForgotPasswordMessage
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的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));
}
}
示例9: user_updatePassword
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的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);
}
示例10: user_merge
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的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);
}
}
示例11: UserServiceImpl
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Autowired
public UserServiceImpl(@Qualifier("userRepository") UserRepository repository,
@Qualifier("dozerMapper") Mapper dozerMapper,
@Qualifier("userPasswordEncoder") ShaPasswordEncoder passwordEncoder) {
super(repository, dozerMapper, UserInfo.class, User.class);
this.userRepository = repository;
this.passwordEncoder = passwordEncoder;
}
示例12: getUserByUsername
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Override
public User getUserByUsername(String username) {
// Just a mock interface support only one single root
// Here you can add DAO to load user from the database
if (username.equals(USER_TEST)) {
User user = new User();
user.setLogin(USER_TEST);
user.setPassword(new ShaPasswordEncoder().encodePassword("password", null));
return user;
} else {
return null;
}
}
示例13: authenticate
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Override
public User authenticate(String username, String password) {
// get user by username
User user = userDao.getByUsername(username);
if (user != null) {
ShaPasswordEncoder pwdEnc = new ShaPasswordEncoder();
String pwd = pwdEnc.encodePassword(password, user.getSalt());
if (pwd.equals(user.getPassword())) {
return user;
}
}
return null;
}
示例14: encode
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
public static String encode(String password) {
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String encodedPassword = encoder.encodePassword(password, null);
return encodedPassword;
}
示例15: passwordEncoder
import org.springframework.security.authentication.encoding.ShaPasswordEncoder; //导入依赖的package包/类
@Bean
public ShaPasswordEncoder passwordEncoder() {
return new ShaPasswordEncoder();// argument can put 256 for SHA-256
}