Shiro Odd number of characters.
2017-11-17 11:33
761 查看
这几天在集成Shiro,从网上找了代码,自己参考着写自己的Demo的。
参照着他的代码,mybatis部分没有集成,自己返回的固定数据,执行登录的时候出现以下问题。
网上搜了下,这个问题出现的很多,基本都是说加密这块出了问题。最终还是仔细阅读那位兄弟代码的时候发现有个password加密的部分。而且也提供了相应的加密。
首先,我这里进入Shiro的时候会执行doGetAuthenticationInfo方法,这里会使用hashedCredentialsMatcher对密码进行加密,仔细对比后确定问题就出在这,所以讲自己返回的数据中的密码进行如下加密后测试OK了。
这里的hashIterations次数要跟hashedCredentialsMatcher方法设置中的次数相同,加密方式也要相同(一般MD5足够了)。
参照着他的代码,mybatis部分没有集成,自己返回的固定数据,执行登录的时候出现以下问题。
Authentication failed for token submission [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=false]. Possible unexpected error? (Typical or expected login exceptions should extend from AuthenticationException). java.lang.IllegalArgumentException: Odd number of characters.
网上搜了下,这个问题出现的很多,基本都是说加密这块出了问题。最终还是仔细阅读那位兄弟代码的时候发现有个password加密的部分。而且也提供了相应的加密。
首先,我这里进入Shiro的时候会执行doGetAuthenticationInfo方法,这里会使用hashedCredentialsMatcher对密码进行加密,仔细对比后确定问题就出在这,所以讲自己返回的数据中的密码进行如下加密后测试OK了。
public class PasswordHelper { private String algorithmName = "md5"; private int hashIterations = 2; public void encryptPassword(User user) { //String salt=randomNumberGenerator.nextBytes().toHex(); String newPassword = new SimpleHash(algorithmName, user.getPassword(), ByteSource.Util.bytes(user.getUsername()), hashIterations).toHex(); //String newPassword = new SimpleHash(algorithmName, user.getPassword()).toHex(); user.setPassword(newPassword); } public static void main(String[] args) { PasswordHelper passwordHelper = new PasswordHelper(); User user = new User(); user.setUsername("admin"); user.setPassword("admin"); passwordHelper.encryptPassword(user); System.out.println(user); }
这里的hashIterations次数要跟hashedCredentialsMatcher方法设置中的次数相同,加密方式也要相同(一般MD5足够了)。
相关文章推荐
- Shiro Odd number of characters.
- Find the Number Occurring Odd Number of Times
- *Find the Number Occurring Odd Number of Times
- Microsoft SQL Server 2008 R2 XML处理 One solution is to increase the number of characters retrieved from the server for XML data.
- ICS Return 1 when x contains an odd number of 1s,0 otherwise(判断二进制表示中1的个数是否为奇数)
- Find the Number Occurring Odd Number of Times
- jxl下拉长度的问题,Validation list exceeds maximum number of characters - truncating
- Finding a number that repeats even no of times where all the other numbers repeat odd no of times
- 当x有奇数个1时返回1,retrun 1 when x contains an odd number of 1s
- A string s is LUCKY if and only if the number of different characters in s is a fibonacci number. Gi
- calculate the number of characters-统计文件中的字符数,非空白字符数,字母数,输入到文件和屏幕:
- 《高性能javascript》 --- in case of odd number of items(奇怪的条目的数量)
- Count the number of alphabets, spaces, digits and other characters in one line character
- 1. 找出数组中的单身狗OddOccurrencesInArray Find value that occurs in odd number of elements.
- Number of Digit One
- leetcode -- Letter Combinations of a Phone Number
- Number Of Ones题解 codeEval
- leetcode-17. Letter Combinations of a Phone Number
- leetcode: Letter Combinations of a Phone Number
- mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法