zoukankan      html  css  js  c++  java
  • shiro初探,最简单的认证,通过ini文件。

    一共分三大组件 subject(主题,主要是认证的用户密码),securityManager(安全管理器),realm(数据桥梁)

    在resource 里建立shiro.ini 文件

    #用户
    [users]
    zhangsan=123456
    lisi=12345

    然后写test类

    package cn.taotao;
    
    import org.apache.commons.collections.bag.SynchronizedSortedBag;
    import org.apache.shiro.SecurityUtils;
    import org.apache.shiro.authc.AuthenticationToken;
    import org.apache.shiro.authc.UsernamePasswordToken;
    import org.apache.shiro.config.IniSecurityManagerFactory;
    import org.apache.shiro.mgt.SecurityManager;
    import org.apache.shiro.subject.Subject;
    import org.apache.shiro.util.Factory;
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    
    @SpringBootTest
    class ActivitiApplicationTests {
    
        @Test
        void contextLoads() {
        }
    
    
        @Test
        void testShiro(){
            String username="zhangsan";
            String  password = "123456";
            // 创建工厂,注意引入的包名,SecurityManager 是shiro的包
            Factory<SecurityManager>  factory =  new IniSecurityManagerFactory("classpath:shiro.ini");
            // 取得安全管理器实例
            SecurityManager securityManager = factory.getInstance();
            //  把当前SecurityManager 绑定到当前线程
            SecurityUtils.setSecurityManager(securityManager);
            // 取出当前的subject
            Subject subject = SecurityUtils.getSubject();
    
            // 
            AuthenticationToken authenticationToken = new UsernamePasswordToken(username,password);
            subject.login(authenticationToken);
    
            System.out.println("是否认证成功"+subject.isAuthenticated());
    
    
        }
    
    }
  • 相关阅读:
    Js中的变量
    flash读取XML 背景自动适应大小
    Ajax.NET Professional
    JS事件大全
    (转)SharePoint社区工具包中文版发布!!
    .iOS APP Project or Mac APP Project编译错误提示: My Mac 64bit is not valid for Running the scheme
    NSAssert断言
    iphone手机appstore地区更改
    自定义UITableView Section 的title样式字体
    从项中复制值
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/15236905.html
Copyright © 2011-2022 走看看