com.zrx.authority.web.interceptor.shiro.ShiroRealm.java Source code

Java tutorial

Introduction

Here is the source code for com.zrx.authority.web.interceptor.shiro.ShiroRealm.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.zrx.authority.web.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;

/**
 * <p>Description  :</p>
 * <p>Title  :</p>
 * @author  <your.name at your.org>
 * @data 2015-8-28,23:41:10
 * @version 1.0
 */
public class ShiroRealm extends AuthorizingRealm {

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection pc) {
        System.out.println("========2");

        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken at) throws AuthenticationException {
        System.out.println("========  doGetAuthenticationInfo  ");
        String username = (String) at.getPrincipal(); //?? 
        String password = new String((char[]) at.getCredentials()); //?
        if (null != username && null != password) {
            return new SimpleAuthenticationInfo(username, password, getName());
        } else {
            return null;
        }

    }

}