Blame view

src/com/fh/interceptor/shiro/ShiroRealm.java 1.6 KB
ad5081d3   孙向锦   初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  package com.fh.interceptor.shiro;
  
  
  import org.apache.shiro.authc.AuthenticationException;
  import org.apache.shiro.authc.AuthenticationInfo;
  import org.apache.shiro.authc.AuthenticationToken;
  import org.apache.shiro.authc.SimpleAuthenticationInfo;
  import org.apache.shiro.authz.AuthorizationInfo;
  import org.apache.shiro.realm.AuthorizingRealm;
  import org.apache.shiro.subject.PrincipalCollection;
  
  
  /**
   * @author fh
   *  2015-3-6
   */
  public class ShiroRealm extends AuthorizingRealm {
  
  	/*
  	 * 登录信息和用户验证信息验证(non-Javadoc)
  	 * @see org.apache.shiro.realm.AuthenticatingRealm#doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken)
  	 */
  	@Override
  	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  		 String username = (String)token.getPrincipal();  				//得到用户名 
  	     String password = new String((char[])token.getCredentials()); 	//得到密码
  	     //身份证认证授权转移到 com.fh.controller.system.login  LoginController类下的login()方法中
  	     if(null != username && null != password){
  	    	 return new SimpleAuthenticationInfo(username, password, getName());
  	     }else{
  	    	 return null;
  	     }
  	}
  	
  	/*
  	 * 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用,负责在应用程序中决定用户的访问控制的方法(non-Javadoc)
  	 * @see org.apache.shiro.realm.AuthorizingRealm#doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
  	 */
  	@Override
  	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection pc) {
  		return null;
  	}
  
  }