本文整理汇总了Java中org.apache.shiro.crypto.hash.Sha512Hash类的典型用法代码示例。如果您正苦于以下问题:Java Sha512Hash类的具体用法?Java Sha512Hash怎么用?Java Sha512Hash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sha512Hash类属于org.apache.shiro.crypto.hash包,在下文中一共展示了Sha512Hash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUserIfMissing
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Creates a new user if does not exist. If it exists, it is unlocked and roles are reset (password is untouched).
*
* @param cnx
* @param login
* @param password
* the raw password. it will be hashed.
* @param description
* @param roles
*/
static void createUserIfMissing(DbConn cnx, String login, String password, String description, String... roles)
{
try
{
int userId = cnx.runSelectSingle("user_select_id_by_key", Integer.class, login);
cnx.runUpdate("user_update_enable_by_id", userId);
RUser.set_roles(cnx, userId, roles);
}
catch (NoResultException e)
{
ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
String hash = new Sha512Hash(password, salt, 100000).toHex();
String saltS = salt.toHex();
RUser.create(cnx, login, hash, saltS, roles);
}
}
示例2: getPasswordService
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public static HashingPasswordService getPasswordService() {
DefaultHashService hashService = new DefaultHashService();
hashService.setHashIterations(HASH_ITERATIONS);
hashService.setHashAlgorithmName(Sha512Hash.ALGORITHM_NAME);
hashService.setGeneratePublicSalt(true);
DefaultPasswordService passwordService = new DefaultPasswordService();
passwordService.setHashService(hashService);
return passwordService;
}
示例3: generatePassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public static User generatePassword(User user){
byte[] passwordSalt = UUID.randomUUID().toString().getBytes();
user.setPasswordSalt(passwordSalt);
String passwordHash = new Sha512Hash(user.getPassword(), user.getName() + new String(passwordSalt), 99).toString();
user.setPasswordHash(passwordHash);
return user;
}
示例4: postConstruct
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
@PostConstruct
public void postConstruct() {
setCacheManager(new MemoryConstrainedCacheManager());
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "shiro.password.");
nbHashIterations = propertyResolver.getProperty("nbHashIterations", Integer.class);
HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(Sha512Hash.ALGORITHM_NAME);
credentialsMatcher.setHashIterations(nbHashIterations);
setCredentialsMatcher(credentialsMatcher);
salt = propertyResolver.getProperty("salt");
}
示例5: changeUserPassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public static void changeUserPassword(DbConn cnx, int userId, String newPassword)
{
ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
String hash = new Sha512Hash(newPassword, salt, 100000).toHex();
QueryResult qr = cnx.runUpdate("user_update_password_by_id", hash, salt.toHex(), userId);
if (qr.nbUpdated == 0)
{
throw new JqmAdminApiUserException("user with this ID does not exist");
}
}
示例6: createUser
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public static void createUser(DbConn cnx, String login, String password, RRole... roles)
{
ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
String[] rr = new String[roles.length];
for (int i = 0; i < roles.length; i++)
{
rr[i] = roles[i].getName();
}
RUser.create(cnx, login, new Sha512Hash(password, salt, 100000).toHex(), salt.toHex(), rr);
}
示例7: Sha512CredentialsMatcher
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public Sha512CredentialsMatcher() {
super();
setHashAlgorithmName(Sha512Hash.ALGORITHM_NAME);
}
示例8: setEncryptedPassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* @param plainPassword The new password of the User as plain text.
*/
@JsonIgnore
public void setEncryptedPassword(String plainPassword) {
this.salt = new SecureRandomNumberGenerator().nextBytes().toBase64();
this.password = new Sha512Hash(plainPassword, this.salt, HASH_ITERATIONS).toBase64();
}
示例9: contextInitialized
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
WebApplicationContext webApplicationContext =
WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
PersonRepository personRepository = webApplicationContext.getBean(PersonRepository.class);
personRepository.deleteAll();
List<Person> personList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
String chars = "abcdefghijklmnopqrstuvwxyz";
String name = String.valueOf(chars.charAt((int) (Math.random() * 26)));
Person person = new Person();
person.setName(name);
person.setAge((i % 100) + 1);
personList.add(person);
}
personRepository.save(personList);
UserRepository userRepository = webApplicationContext.getBean(UserRepository.class);
userRepository.deleteAll();
User user = new User();
user.setName("[email protected]");
byte[] passwordSalt = UUID.randomUUID().toString().getBytes();
user.setPasswordSalt(passwordSalt);
user.setPassword("123");
String passwordHash =
new Sha512Hash(user.getPassword(), user.getName() + new String(passwordSalt), 99)
.toString();
user.setPasswordHash(passwordHash);
RoleRepository roleRepository = webApplicationContext.getBean(RoleRepository.class);
roleRepository.deleteAll();
Set<Role> roleSet = new HashSet<>();
Role role = new Role();
role.setName("admin");
role.setDescription("管理员");
List<String> permissisonList = new ArrayList<>();
permissisonList.add("user:view");
permissisonList.add("role:view");
role.setPermissions(permissisonList);
roleSet.add(roleRepository.save(role));
user.setRoles(roleSet);
userRepository.save(user);
}
示例10: hashKey
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
public String hashKey(String key) {
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "shiro.password.");
return new Sha512Hash(key, propertyResolver.getProperty("salt"),
propertyResolver.getProperty("nbHashIterations", Integer.class)).toString();
}
示例11: getId
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Will create (or recreate) if necessary the temporary login data.<br>
* Will create its own transaction - therefore the given connection must not have any active transaction.
*/
static Duet getId(DbConn cnx)
{
if (logindata == null && useAuth == null)
{
useAuth = Boolean.parseBoolean(GlobalParameter.getParameter(cnx, "enableWsApiAuth", "true"));
if (!useAuth)
{
jqmlogger.debug("The client API will not use any authentication to download files");
logindata = new Duet();
logindata.pass = null;
logindata.usr = null;
}
else
{
jqmlogger.debug("The client API will use authentication to download files");
}
}
if (!useAuth)
{
return logindata;
}
if (user == null || user.getExpirationDate().before(Calendar.getInstance()))
{
synchronized (lock)
{
if (user == null || user.getExpirationDate().before(Calendar.getInstance()))
{
jqmlogger.debug("The client API will create an internal secret to access the simple API for file downloading");
// Create new
String login = UUID.randomUUID().toString();
secret = UUID.randomUUID().toString();
ByteSource salt = new SecureRandomNumberGenerator().nextBytes();
String hash = new Sha512Hash(secret, salt, 100000).toHex();
String saltS = salt.toHex();
Calendar expiration = Calendar.getInstance();
expiration.add(Calendar.DAY_OF_YEAR, 1);
int id = RUser.create(cnx, login, hash, saltS, expiration, true, "administrator");
user = RUser.select_id(cnx, id);
logindata = new Duet();
logindata.pass = secret;
logindata.usr = login;
// Purge all old internal accounts
cnx.runUpdate("user_delete_expired_internal");
cnx.commit();
}
}
}
return logindata;
}
示例12: setHumanReadablePassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Sets the password in human readable format. The password will internally
* be hashed.
*
* @param password
*/
public void setHumanReadablePassword(String password) {
this.password = new Sha512Hash(password, AppUserAuthenticationInfo.PW_SALT)
.toHex();
}
示例13: isValidPassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Checks if the given password equals the password of the user.
*
* @param plainPasswordToCheck
* The password to check.
* @return True, if both passwords matched, false otherwise.
*/
@JsonIgnore
public boolean isValidPassword(String plainPasswordToCheck) {
String hashedPassword = new Sha512Hash(plainPasswordToCheck, this.salt, HASH_ITERATIONS).toBase64();
return hashedPassword.equals(this.password);
}
示例14: hashPassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Hash user password.
*
* @param password
* @return
*/
public String hashPassword(String password) {
RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(env, "shiro.password.");
return new Sha512Hash(password, propertyResolver.getProperty("salt"),
propertyResolver.getProperty("nbHashIterations", Integer.class)).toString();
}
示例15: getEncryptedPassword
import org.apache.shiro.crypto.hash.Sha512Hash; //导入依赖的package包/类
/**
* Get the encrypted password for plain text and hash salt
*
* @param plainPassword
* plain text password
* @param hashSalt
* salt for the hash
* @return result hex string
*/
public static String getEncryptedPassword( String plainPassword, String hashSalt ) {
return new Sha512Hash( plainPassword, hashSalt, 5 ).toHex();
}