shiro登录

shiro登录
1.获取当前的Subject,调用SecurityUtils.getSubject();
2.判断当前用户是否被认证(登录),调用Subject的isAuthenticated();
3.没有认证,把用户名和密码封装为UsernamePasswordToken对象;
   3.1创建表单页面;
   3.2将请求提交到springmvc的handle;
   3.3获取用户名和密码
4.执行登录调用Subject的login(AuthenticationToken token)
5.自定义的Realm的方法,从数据库中获取对应的记录,给shiro
   5.1继承org.apache.shiro.realm.AuthorizingRealm类;
   5.2实现doGetAuthenticationInfo(AuthenticationToken token)方法;
6.由shiro完成密码的比对;
    通过AuthenticationToken中的CredentialsMatcher属性来进行密码比对;
shiro 加密
1.如何把一个字符串加密;new SimpleHash("MD5", credential, ByteSource.Util.bytes(salt), 1024);
2.提供当前Reaml的CredentialsMatcher属性,直接使用HashedCredentialsMatcher对象,并设置加密算法即可.
盐值加密:
1.为什么要使用盐值加密
2.如何做到:
   1.在doGetAuthenticationInfo方法返回SimpleAuthenticationInfo对象时,
    使用new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, realmName)构造器;
   2.使用ByteSource.Util.bytes(salt)来计算盐值;
   3.盐值要唯一:一般为随机字符串或用户名
   4.使用new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, realmName);来计算盐值加密后的结果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章