Java Code Examples for org.apache.shiro.authc.credential.HashedCredentialsMatcher#setHashAlgorithmName()
The following examples show how to use
org.apache.shiro.authc.credential.HashedCredentialsMatcher#setHashAlgorithmName() .
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: ShiroDbRealm.java From MeetingFilm with Apache License 2.0 | 5 votes |
/** * 设置认证加密方式 */ @Override public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) { HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher(); md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName); md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations); super.setCredentialsMatcher(md5CredentialsMatcher); }
Example 2
Source File: SimpleAuthorizingRealm.java From NutzSite with Apache License 2.0 | 5 votes |
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 3
Source File: ApiController.java From WebStack-Guns with MIT License | 5 votes |
/** * 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 4
Source File: ShiroDbRealm.java From WebStack-Guns with MIT License | 5 votes |
/** * 设置认证加密方式 */ @Override public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) { HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher(); md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName); md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations); super.setCredentialsMatcher(md5CredentialsMatcher); }
Example 5
Source File: UserRealm.java From kvf-admin with MIT License | 5 votes |
@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 6
Source File: Sha256CredentialsHashingStrategy.java From arcusplatform with Apache License 2.0 | 5 votes |
public Sha256CredentialsHashingStrategy() { HashedCredentialsMatcher hashMatcher = new HashedCredentialsMatcher(); hashMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME); hashMatcher.setHashIterations(ITERATIONS); hashMatcher.setStoredCredentialsHexEncoded(false); credentialsMatcher = hashMatcher; }
Example 7
Source File: MyShiroRealm.java From SpringBootBucket with MIT License | 5 votes |
/** * 设置认证加密方式 */ @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 8
Source File: UserRealm.java From seezoon-framework-all with Apache License 2.0 | 5 votes |
@Override public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) { HashedCredentialsMatcher shaCredentialsMatcher = new HashedCredentialsMatcher(); shaCredentialsMatcher.setHashAlgorithmName(ShiroUtils.hashAlgorithmName); shaCredentialsMatcher.setHashIterations(ShiroUtils.hashIterations); super.setCredentialsMatcher(shaCredentialsMatcher); }
Example 9
Source File: ShiroConfig.java From Spring-Shiro-Spark with Apache License 2.0 | 5 votes |
/** * 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: ShiroConfiguration.java From wangmarket with Apache License 2.0 | 5 votes |
@Bean(name = "hashedCredentialsMatcher") public HashedCredentialsMatcher hashedCredentialsMatcher() { HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); credentialsMatcher.setHashAlgorithmName("MD5"); credentialsMatcher.setHashIterations(2); credentialsMatcher.setStoredCredentialsHexEncoded(true); return credentialsMatcher; }
Example 11
Source File: AuthorizingRealmImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Inject public AuthorizingRealmImpl(final RealmSecurityManager realmSecurityManager, final UserManager userManager, final Map<String, UserManager> userManagerMap) { this.realmSecurityManager = realmSecurityManager; this.userManager = userManager; this.userManagerMap = userManagerMap; HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); credentialsMatcher.setHashAlgorithmName(Sha1Hash.ALGORITHM_NAME); setCredentialsMatcher(credentialsMatcher); setName(NAME); setAuthenticationCachingEnabled(false); // we authz only, no authc done by this realm setAuthorizationCachingEnabled(true); }
Example 12
Source File: WebSecurityConfig.java From java-webapp-security-examples with Apache License 2.0 | 5 votes |
@Bean(name = "jdbcRealm") @DependsOn("lifecycleBeanPostProcessor") public JdbcRealm jdbcRealm() { JdbcRealm realm = new JdbcRealm(); HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); credentialsMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME); realm.setCredentialsMatcher(credentialsMatcher); realm.setDataSource(dataSource); realm.init(); return realm; }