shiro 修改验证
来源:互联网 发布:java实施工程师做什么 编辑:程序博客网 时间:2024/06/16 12:11
首先找到认证 ShiroDbRealm
这里是验证验证码、密码等信息
/** * 认证回调函数, 登录时调用 */@Overrideprotected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {UsernamePasswordToken token = (UsernamePasswordToken) authcToken;SimpleAuthenticationInfo authenticationInfo = null;User user = getSystemService().getUserByLoginName(token.getUsername());if (user != null) {byte[] salt = Encodes.decodeHex(user.getPassword());return new SimpleAuthenticationInfo(new Principal(user), user.getPassword(), ByteSource.Util.bytes(salt), getName());} else {return null;}}
Class SimpleAuthenticationInfo
api 是这样介绍的,这说本文用的方法:SimpleAuthenticationInfo(Object principal,Object hashedCredentials,ByteSource credentialsSalt, String realmName)
Constructor that takes in a single 'primary' principal of the account, its corresponding hashed credentials, the salt used to hash the credentials, and the name of the realm to associate with the principals.
意思是:构造函数,在一个“主”的账户,其相应的散列凭证,盐用于哈希凭据和域的名称关联的主体。说白了就是对你的身份认证.合法性认证,那shiro怎么知道我是怎么验证的呢
认证的方法通过initCredentialsMatcher设置;
这样我们就可以用自己的方式验证用户的合法性了
那接下来就需要写自己的验证方法
这样就将验证改成自己的方法了。
收工
意思是:构造函数,在一个“主”的账户,其相应的散列凭证,盐用于哈希凭据和域的名称关联的主体。说白了就是对你的身份认证.合法性认证,那shiro怎么知道我是怎么验证的呢
认证的方法通过initCredentialsMatcher设置;
@PostConstruct public void initCredentialsMatcher() { //该句作用是重写shiro的密码验证,让shiro用我自己的验证 setCredentialsMatcher(new CustomCM()); }
这样我们就可以用自己的方式验证用户的合法性了
那接下来就需要写自己的验证方法
import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authc.UsernamePasswordToken;import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;import org.apache.shiro.crypto.hash.Sha384Hash;import com.sicc.oa.common.pass.SHA1;/** * 自定义 密码验证类 * * @author q * */public class CustomCredentialsMatcher extends SimpleCredentialsMatcher { @Override public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; Object tokenCredentials = encrypt(String.valueOf(token.getPassword())); Object accountCredentials = getCredentials(info); return equals(tokenCredentials, accountCredentials); } // 将传进来密码加密方法 private String encrypt(String data) { String sha384Hex = new SHA1().getDigestOfString(String.valueOf(data) .getBytes()); ;// 这里可以选择自己的密码验证方式 比如 md5或者sha256等 return sha384Hex; }}
这样就将验证改成自己的方法了。
收工
0 0
- shiro 修改验证
- Apache Shiro 验证
- shiro 验证授权
- Apache Shiro 验证
- shiro权限验证标签
- shiro权限验证标签
- shiro权限验证标签
- shiro验证框架
- Shiro权限验证标签
- shiro权限验证标签
- shiro权限验证标签
- shiro权限验证标签
- shiro进行验证
- shiro权限验证标签
- shiro权限验证标签
- shiro验证相关
- Shiro连接数据库验证
- Shiro验证码检测
- 移动手机平台的HTML5前端优化指南
- 解密Redis持久化
- 防止普通用户 意外sudo passwd 改了root密码
- 深度学习研究理解10:Very Deep Convolutional Networks for Large-Scale Image Recognition
- JSF--BackingBean 业务方法
- shiro 修改验证
- 人最脆弱的地方是:舍不得
- 黑马程序员_java基础笔记(09)...HTML基本知识、CSS、JavaScript、DOM
- SQL Server中解决死锁的新方法介绍
- c语言三元运算符a:b?c你知道多少
- 黑马程序员_java基础笔记(10)...JDK1.5的新特性
- Anaconda装OpenCV
- Spring AOP四种创建通知(拦截器)类型实例
- Java之JDOM方式生成XML文件(学习笔记)