package com.dcit.authority.shiro.realm;

import java.util.LinkedList;
import java.util.List;

import org.apache.shiro.realm.Realm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dcit.authority.shiro.matcher.JwtMatcher;
import com.dcit.authority.shiro.matcher.PasswordMatcher;
import com.dcit.authority.shiro.provider.ShiroAuthProvider;
import com.dcit.authority.shiro.token.JwtToken;
import com.dcit.authority.shiro.token.PasswordToken;



/**
* <p>Title: RealmManager</p>
* <p>Description: realm管理器</p>
* <p>Company: SJZ DC-IT co. LTD</p> 
* @author ZZZ
* @date 2018年9月6日 下午7:01:12
*/
@Component
public class RealmManager {

	private PasswordMatcher passwordMatcher;
	
    private JwtMatcher jwtMatcher;
    
    private ShiroAuthProvider shiroAuthProvider;
    
    @Autowired
    public RealmManager(PasswordMatcher passwordMatcher,JwtMatcher jwtMatcher,ShiroAuthProvider shiroAuthProvider){
    	this.passwordMatcher = passwordMatcher;
    	this.jwtMatcher = jwtMatcher;
    	this.shiroAuthProvider = shiroAuthProvider;
    }
    
    public List<Realm> initRealm(){
    	List<Realm> realmList = new LinkedList<>();
    	
    	PasswordRealm passwordRealm = new PasswordRealm();
    	passwordRealm.setCredentialsMatcher(passwordMatcher);
    	passwordRealm.setShiroAuthProvider(shiroAuthProvider);
    	passwordRealm.setAuthenticationTokenClass(PasswordToken.class);
    	realmList.add(passwordRealm);
    	
    	JwtRealm jwtRealm = new JwtRealm();
    	jwtRealm.setCredentialsMatcher(jwtMatcher);
    	jwtRealm.setAuthenticationTokenClass(JwtToken.class);
    	
    	realmList.add(jwtRealm);
    	
    	return realmList;
    }
	
}
