欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ShiroWeb 基础框架搭建

程序员文章站 2022-03-27 07:55:53
MyRealm.javapackage com.dym.shiroweb.config;import org.apache.shiro.authc.AuthenticationException;import org.apache.shiro.authc.AuthenticationInfo;import org.apache.shiro.authc.AuthenticationToken;import org.apache.shiro.authz.AuthorizationInfo;im...

MyRealm.java

package com.dym.shiroweb.config;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class MyRealm extends AuthorizingRealm {
    private Logger logger=  LoggerFactory.getLogger(MyRealm.class);
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        logger.info("------entered MyRealm doGetAuthorizationInfo method");
        return null;
    }

    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        logger.info("+++++++entered MyRealm doGetAuthenticationInfo method");
        return null;
    }
}

ShiroConfig.java

package com.dym.shiroweb.config;

import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.servlet.ShiroFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ShiroConfig {

    // 1 Realm  代表系统资源
    @Bean
    public Realm myRealm(){
        return new MyRealm();
    }
    // 2 SecurityManager 流程控制
    @Bean
    public DefaultWebSecurityManager mySecurityManager(Realm myRealm){
        DefaultWebSecurityManager securityManager=new DefaultWebSecurityManager();
        securityManager.setRealm(myRealm);
        return securityManager;
    }
    // 3 ShiroFilterFactoryBean  请求过滤器
    @Bean
    public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultWebSecurityManager mySecurityManager){
        ShiroFilterFactoryBean factoryBean=new ShiroFilterFactoryBean();
        factoryBean.setSecurityManager(mySecurityManager);
        return factoryBean;
    }

}

 

本文地址:https://blog.csdn.net/qq_39368007/article/details/112001046

相关标签: shiro