
package shiro;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.SimpleAccountRealm;
import org.apache.shiro.subject.Subject;
import org.junit.Before;import org.junit.Test;
public class shirotest {
SimpleAccountRealm sar =new SimpleAccountRealm();
@Before
public void adduser(){ sar.addAccount("wyc", "123456"); }
@Test
public void testshiro(){
DefaultSecurityManager dsm = new DefaultSecurityManager();
dsm.setRealm(sar);
SecurityUtils.setSecurityManager(dsm);
Subject sj = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken("wyc","123456");
sj.login(token);
//sj.checkRoles("admin");
System.out.println(sj.isAuthenticated());
}}