zoukankan      html  css  js  c++  java
  • shiro框架---bug调试(账号错误)

     1 package cn.lqp.shrio.test;
     2 
     3 import org.apache.shiro.SecurityUtils;
     4 import org.apache.shiro.authc.AuthenticationException;
     5 import org.apache.shiro.authc.UsernamePasswordToken;
     6 import org.apache.shiro.config.IniSecurityManagerFactory;
     7 import org.apache.shiro.mgt.SecurityManager;
     8 import org.apache.shiro.subject.Subject;
     9 
    10 public class ShrioTest {
    11     
    12     public static void main(String[] args) {
    13         
    14         //读取配置文件
    15         IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    16         SecurityManager securityManager = factory.createInstance();
    17         
    18         //第二步 L构建验证信息Token
    19         UsernamePasswordToken token = new UsernamePasswordToken("admin-ERROR","1234567");
    20         
    21         //第三步:获得一个没有权限信息的身份对象
    22         SecurityUtils.setSecurityManager(securityManager);
    23         Subject subject = SecurityUtils.getSubject();
    24         
    25         //第四步 : 校验
    26         try {
    27             Subject resultSubject = securityManager.login(subject, token);
    28             System.out.println("获得校验后的用户名:"+resultSubject.getPrincipal());
    29             System.out.println("判断校验是否通过:"+resultSubject.isAuthenticated());
    30             
    31             
    32         } catch (AuthenticationException e) {
    33             // TODO Auto-generated catch block
    34             e.printStackTrace();
    35         }
    36     
    37     }
    38 
    39 }

  • 相关阅读:
    [loj3364]植物比较
    [loj3366]嘉年华奖券
    [atARC105F]Lights Out on Connected Graph
    [atARC105D]Let's Play Nim
    [atARC058F]Lroha Loves Strings
    [loj3347]有趣的旅途
    [atAGC001F]Wide Swap
    [cf1392I]Kevin and Grid
    [loj3340]命运
    [loj3046]语言
  • 原文地址:https://www.cnblogs.com/meizhoulqp/p/11140642.html
Copyright © 2011-2022 走看看