美文网首页
SpringBoot与Shiro整合

SpringBoot与Shiro整合

作者: gurlan | 来源:发表于2021-12-11 14:13 被阅读0次

    1.导入maven依赖

     <dependency>
                <groupId>org.apache.shiro</groupId>
                <artifactId>shiro-spring</artifactId>
                <version>1.7.1</version>
     </dependency>
    

    2.编写Realm类

    package com.gitlay.jadmin.common.shiro;
    
    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;
    
    public class MyShiroRealm extends AuthorizingRealm {
        /**
         * 执行授权逻辑
         * @param principalCollection
         * @return
         */
        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
            System.out.println("执行授权逻辑");
            return null;
        }
    
        /**
         * 执行认证逻辑
         * @param authenticationToken
         * @return
         * @throws AuthenticationException
         */
        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
            System.out.println("执行认证逻辑");
            return null;
        }
    }
    

    相关文章

      网友评论

          本文标题:SpringBoot与Shiro整合

          本文链接:https://www.haomeiwen.com/subject/oqkdrltx.html