@@ -0,0 +1,1999 @@
+package com.lance.shiro.config;%0A%0Aimport org.apache.shiro.authc.AuthenticationException;%0Aimport org.apache.shiro.authc.AuthenticationInfo;%0Aimport org.apache.shiro.authc.AuthenticationToken;%0Aimport org.apache.shiro.authc.SimpleAuthenticationInfo;%0Aimport org.apache.shiro.authc.UnknownAccountException;%0Aimport org.apache.shiro.authc.UsernamePasswordToken;%0Aimport org.apache.shiro.authc.credential.HashedCredentialsMatcher;%0Aimport org.apache.shiro.authz.AuthorizationInfo;%0Aimport org.apache.shiro.authz.SimpleAuthorizationInfo;%0Aimport org.apache.shiro.realm.AuthorizingRealm;%0Aimport org.apache.shiro.subject.PrincipalCollection;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport com.lance.shiro.domain.UserInfo;%0Aimport com.lance.shiro.service.UserService;%0A%0A/**%0A * %E9%AA%8C%E8%AF%81%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%0A * %0A * @author Administrator%0A */%0A@Component%0Apublic class UserRealm extends AuthorizingRealm %7B%0A%09@Autowired%0A%09private UserService userService;%0A%0A%09public UserRealm() %7B%0A%09%09setName(%22UserRealm%22);%0A%09%09// %E9%87%87%E7%94%A8MD5%E5%8A%A0%E5%AF%86%0A%09%09setCredentialsMatcher(new HashedCredentialsMatcher(%22md5%22));%0A%09%7D%0A%0A%09//%E6%9D%83%E9%99%90%E8%B5%84%E6%BA%90%E8%A7%92%E8%89%B2%0A%09@Override%0A%09protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) %7B%0A%09%09String username = (String) principals.getPrimaryPrincipal();%0A%09%09SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();%0A%09%09//add Permission Resources%0A%09%09info.setStringPermissions(userService.findPermissions(username));%0A%09%09//add Roles String%5BSet%3CString%3E roles%5D%0A%09%09//info.setRoles(roles);%0A%09%09return info;%0A%09%7D%0A%09%0A%09//%E7%99%BB%E5%BD%95%E9%AA%8C%E8%AF%81%0A%09@Override%0A%09protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException %7B%0A%09%09UsernamePasswordToken upt = (UsernamePasswordToken) token;%0A%09%09String userName = upt.getUsername();%0A%09%09UserInfo user = userService.findByAccount(userName);%0A%0A%09%09if (user == null) %7B%0A%09%09%09throw new UnknownAccountException();%0A%09%09%7D%0A%09%09SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(userName, user.getPassword(), getName());%0A%09%09return info;%0A%09%7D%0A%7D

add userreal