Java Code Examples for org.apache.shiro.authc.credential.HashedCredentialsMatcher#setHashIterations()

The following examples show how to use org.apache.shiro.authc.credential.HashedCredentialsMatcher#setHashIterations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthRealm.java    From mysiteforme with Apache License 2.0 5 votes vote down vote up
/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
    HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(Constants.HASH_ALGORITHM);
    matcher.setHashIterations(Constants.HASH_INTERATIONS);
    setCredentialsMatcher(matcher);
}
 
Example 2
Source File: ShiroDbRealm.java    From dubai with MIT License 5 votes vote down vote up
/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
	HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(UserService.HASH_ALGORITHM);
	matcher.setHashIterations(UserService.HASH_INTERATIONS);

	setCredentialsMatcher(matcher);
}
 
Example 3
Source File: ShiroDbRealm.java    From Mario with Apache License 2.0 5 votes vote down vote up
/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
    HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(
            AccountService.HASH_ALGORITHM);
    matcher.setHashIterations(AccountService.HASH_INTERATIONS);

    setCredentialsMatcher(matcher);
}
 
Example 4
Source File: UserRealm.java    From MultimediaDesktop with Apache License 2.0 5 votes vote down vote up
/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
	HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(
			UserConstant.HASH_ALGORITHM);
	matcher.setHashIterations(UserConstant.HASH_INTERATIONS);
	setCredentialsMatcher(matcher);
}
 
Example 5
Source File: ShiroDbRealm.java    From spring-boot-quickstart with Apache License 2.0 5 votes vote down vote up
/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
	HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(AccountService.HASH_ALGORITHM);
	matcher.setHashIterations(AccountService.HASH_INTERATIONS);

	setCredentialsMatcher(matcher);
}
 
Example 6
Source File: SystemAuthorizingRealm.java    From Shop-for-JavaWeb with MIT License 5 votes vote down vote up
/**
 * 设定密码校验的Hash算法与迭代次数
 */
@PostConstruct
public void initCredentialsMatcher() {
	HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(SystemService.HASH_ALGORITHM);
	matcher.setHashIterations(SystemService.HASH_INTERATIONS);
	setCredentialsMatcher(matcher);
}
 
Example 7
Source File: ShiroConfiguration.java    From wangmarket with Apache License 2.0 5 votes vote down vote up
@Bean(name = "hashedCredentialsMatcher")
public HashedCredentialsMatcher hashedCredentialsMatcher() {
	HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
	credentialsMatcher.setHashAlgorithmName("MD5");
	credentialsMatcher.setHashIterations(2);
	credentialsMatcher.setStoredCredentialsHexEncoded(true);
	return credentialsMatcher;
}
 
Example 8
Source File: SystemAuthorizingRealm.java    From easyweb with Apache License 2.0 5 votes vote down vote up
/**
 * 设定密码校验的Hash算法与迭代次数
 */
@PostConstruct
public void initCredentialsMatcher() {
	HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(MD5Util.HASH_ALGORITHM);
	matcher.setHashIterations(MD5Util.HASH_INTERATIONS);
	setCredentialsMatcher(matcher);
}
 
Example 9
Source File: ShiroConfig.java    From Spring-Shiro-Spark with Apache License 2.0 5 votes vote down vote up
/**
 * HashCredentialsMatcher,对密码进行编码
 */
@Bean(name = "hashCredentialsMatcher")
public HashedCredentialsMatcher hashedCredentialsMatcher(){
    HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
    credentialsMatcher.setHashAlgorithmName("MD5");
    credentialsMatcher.setHashIterations(2); //散列两次
    credentialsMatcher.setStoredCredentialsHexEncoded(true);
    return credentialsMatcher;
}
 
Example 10
Source File: MyShiroRealm.java    From erp-framework with MIT License 5 votes vote down vote up
/**
 * 重写shiro的密码验证,让shiro用我自己的验证.
 */
@PostConstruct
public void initCredentialsMatcher() {
    HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(Constants.HASH_ALGORITHM);
    matcher.setHashIterations(Constants.HASH_INTERATIONS);
    setCredentialsMatcher(matcher);
}
 
Example 11
Source File: UserRealm.java    From seezoon-framework-all with Apache License 2.0 5 votes vote down vote up
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
	HashedCredentialsMatcher shaCredentialsMatcher = new HashedCredentialsMatcher();
	shaCredentialsMatcher.setHashAlgorithmName(ShiroUtils.hashAlgorithmName);
	shaCredentialsMatcher.setHashIterations(ShiroUtils.hashIterations);
	super.setCredentialsMatcher(shaCredentialsMatcher);
}
 
Example 12
Source File: MyShiroRealm.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * 设置认证加密方式
 */
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
    md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.HASH_ALGORITHM_NAME);
    md5CredentialsMatcher.setHashIterations(ShiroKit.HASH_ITERATIONS);
    super.setCredentialsMatcher(md5CredentialsMatcher);
}
 
Example 13
Source File: Sha256CredentialsHashingStrategy.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Sha256CredentialsHashingStrategy() {
   HashedCredentialsMatcher hashMatcher = new HashedCredentialsMatcher();
   hashMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
   hashMatcher.setHashIterations(ITERATIONS);
   hashMatcher.setStoredCredentialsHexEncoded(false);
   credentialsMatcher = hashMatcher;
}
 
Example 14
Source File: UserRealm.java    From kvf-admin with MIT License 5 votes vote down vote up
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher shaCredentialsMatcher = new HashedCredentialsMatcher();
    shaCredentialsMatcher.setHashAlgorithmName(ShiroKit.HASH_ALGORITHM_NAME);
    shaCredentialsMatcher.setHashIterations(ShiroKit.HASH_ITERATIONS);
    super.setCredentialsMatcher(shaCredentialsMatcher);
}
 
Example 15
Source File: ShiroDbRealm.java    From WebStack-Guns with MIT License 5 votes vote down vote up
/**
 * 设置认证加密方式
 */
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
    md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
    md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
    super.setCredentialsMatcher(md5CredentialsMatcher);
}
 
Example 16
Source File: ApiController.java    From WebStack-Guns with MIT License 5 votes vote down vote up
/**
 * api登录接口,通过账号密码获取token
 */
@RequestMapping("/auth")
public Object auth(@RequestParam("username") String username,
                   @RequestParam("password") String password) {

    //封装请求账号密码为shiro可验证的token
    UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password.toCharArray());

    //获取数据库中的账号密码,准备比对
    User user = userMapper.getByAccount(username);

    String credentials = user.getPassword();
    String salt = user.getSalt();
    ByteSource credentialsSalt = new Md5Hash(salt);
    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
            new ShiroUser(), credentials, credentialsSalt, "");

    //校验用户账号密码
    HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
    md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
    md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
    boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch(
            usernamePasswordToken, simpleAuthenticationInfo);

    if (passwordTrueFlag) {
        HashMap<String, Object> result = new HashMap<>();
        result.put("token", JwtTokenUtil.generateToken(String.valueOf(user.getId())));
        return result;
    } else {
        return new ErrorResponseData(500, "账号密码错误!");
    }
}
 
Example 17
Source File: SimpleAuthorizingRealm.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
public SimpleAuthorizingRealm(CacheManager cacheManager, CredentialsMatcher matcher) {
	super(cacheManager, matcher);
	HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
	hashedCredentialsMatcher.setHashAlgorithmName("SHA-256");
	hashedCredentialsMatcher.setHashIterations(1024);
	// 这一行决定hex还是base64
	hashedCredentialsMatcher.setStoredCredentialsHexEncoded(false);
	// 设置token类型是关键!!!
	setCredentialsMatcher(hashedCredentialsMatcher);
	setAuthenticationTokenClass(UsernamePasswordToken.class);
}
 
Example 18
Source File: ShiroDbRealm.java    From MeetingFilm with Apache License 2.0 5 votes vote down vote up
/**
 * 设置认证加密方式
 */
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
    md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
    md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
    super.setCredentialsMatcher(md5CredentialsMatcher);
}