class ShiroDbRealm extends AuthorizingRealm {

	@Autowired
	protected AccountManager accountManager;

	public ShiroDbRealm() {
		setCredentialsMatcher(new HashedCredentialsMatcher("SHA-1"));
	}

	/**
	 * 认证回调函数,登录时调用.
	 */
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {<FILL_FUNCTION_BODY>}

	/**
	 * 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用.
	 */
	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
		String username = (String) principals.fromRealm(getName()).iterator().next();
//		User user = accountManager.findUserByLoginName(username);
		User user = accountManager.findUserByLoginNameOrEmail(username);
		if(user!=null){
			SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
			if ("1".equals(user.getId())) {
				info.addRole(RoleCode.DWSURVEY_SUPER_ADMIN);
			}
			return info;
		}
		return null;
	}

	/**
	 * 更新用户授权信息缓存.
	 */
	public void clearCachedAuthorizationInfo(String principal) {
		SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, getName());
		clearCachedAuthorizationInfo(principals);
	}

}

		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
//		User user = accountManager.findUserByLoginName(token.getUsername());

		//根据loginToken 看能不查到当前token token有效期就1分钟

		String tokenPassword=new String(token.getPassword());

		User user = accountManager.findUserByLoginNameOrEmail(token.getUsername());

		//user.getStandardLock()==1
		if (user != null && user.getStatus().intValue()!=0 && (user.getVisibility()==null || user.getVisibility()==1 )) {
			 return new SimpleAuthenticationInfo(user.getLoginName(), user.getShaPassword() , getName());
		} else {
			return null;
		}
	
<methods>public void <init>() ,public void <init>(org.apache.shiro.cache.CacheManager) ,public void <init>(org.apache.shiro.authc.credential.CredentialsMatcher) ,public void <init>(org.apache.shiro.cache.CacheManager, org.apache.shiro.authc.credential.CredentialsMatcher) ,public void checkPermission(org.apache.shiro.subject.PrincipalCollection, java.lang.String) throws org.apache.shiro.authz.AuthorizationException,public void checkPermission(org.apache.shiro.subject.PrincipalCollection, org.apache.shiro.authz.Permission) throws org.apache.shiro.authz.AuthorizationException,public transient void checkPermissions(org.apache.shiro.subject.PrincipalCollection, java.lang.String[]) throws org.apache.shiro.authz.AuthorizationException,public void checkPermissions(org.apache.shiro.subject.PrincipalCollection, Collection<org.apache.shiro.authz.Permission>) throws org.apache.shiro.authz.AuthorizationException,public void checkRole(org.apache.shiro.subject.PrincipalCollection, java.lang.String) throws org.apache.shiro.authz.AuthorizationException,public void checkRoles(org.apache.shiro.subject.PrincipalCollection, Collection<java.lang.String>) throws org.apache.shiro.authz.AuthorizationException,public transient void checkRoles(org.apache.shiro.subject.PrincipalCollection, java.lang.String[]) throws org.apache.shiro.authz.AuthorizationException,public Cache<java.lang.Object,org.apache.shiro.authz.AuthorizationInfo> getAuthorizationCache() ,public java.lang.String getAuthorizationCacheName() ,public org.apache.shiro.authz.permission.PermissionResolver getPermissionResolver() ,public org.apache.shiro.authz.permission.RolePermissionResolver getRolePermissionResolver() ,public boolean hasAllRoles(org.apache.shiro.subject.PrincipalCollection, Collection<java.lang.String>) ,public boolean hasRole(org.apache.shiro.subject.PrincipalCollection, java.lang.String) ,public boolean[] hasRoles(org.apache.shiro.subject.PrincipalCollection, List<java.lang.String>) ,public boolean isAuthorizationCachingEnabled() ,public boolean isPermitted(org.apache.shiro.subject.PrincipalCollection, java.lang.String) ,public boolean isPermitted(org.apache.shiro.subject.PrincipalCollection, org.apache.shiro.authz.Permission) ,public transient boolean[] isPermitted(org.apache.shiro.subject.PrincipalCollection, java.lang.String[]) ,public boolean[] isPermitted(org.apache.shiro.subject.PrincipalCollection, List<org.apache.shiro.authz.Permission>) ,public transient boolean isPermittedAll(org.apache.shiro.subject.PrincipalCollection, java.lang.String[]) ,public boolean isPermittedAll(org.apache.shiro.subject.PrincipalCollection, Collection<org.apache.shiro.authz.Permission>) ,public void setAuthorizationCache(Cache<java.lang.Object,org.apache.shiro.authz.AuthorizationInfo>) ,public void setAuthorizationCacheName(java.lang.String) ,public void setAuthorizationCachingEnabled(boolean) ,public void setName(java.lang.String) ,public void setPermissionResolver(org.apache.shiro.authz.permission.PermissionResolver) ,public void setRolePermissionResolver(org.apache.shiro.authz.permission.RolePermissionResolver) <variables>private static final java.lang.String DEFAULT_AUTHORIZATION_CACHE_SUFFIX,private static final java.util.concurrent.atomic.AtomicInteger INSTANCE_COUNT,private Cache<java.lang.Object,org.apache.shiro.authz.AuthorizationInfo> authorizationCache,private java.lang.String authorizationCacheName,private boolean authorizationCachingEnabled,private static final org.slf4j.Logger log,private org.apache.shiro.authz.permission.PermissionResolver permissionResolver,private org.apache.shiro.authz.permission.RolePermissionResolver permissionRoleResolver