007 shiro實現登錄
阿新 • • 發佈:2018-04-05
exce ride == true then turn public body word
一 .概述
首先自定我們的realm.
public class ShiroRealm extends AuthorizingRealm{ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { return null; } @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throwsAuthenticationException { return null; } }
現在我們加入我們的業務邏輯.
首先是認證部分:
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken utoken = (UsernamePasswordToken) token; String username= utoken.getUsername(); String password = new String(utoken.getPassword()); User user = userdao.selectUserByUsername(username); if(user == null) { throw new UnknownAccountException("賬號不正確!"); } if(user.getLocked()==Boolean.TRUE) { thrownew LockedAccountException("賬號被鎖定!"); } //密碼校驗 SimpleHash hash = new SimpleHash("MD5",username , user.getSalt(),1); if(!user.getPassword().equals(hash.toString())) { throw new IncorrectCredentialsException("密碼不正確"); } SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(username ,password ,getName() ); return info; }
以上的部分我們就可以完成shiro的登錄了.
007 shiro實現登錄