public class ShiroTest {
SimpleAccountRealm simpleAccountRealm =new SimpleAccountRealm();
@Before
public void addUser(){
simpleAccountRealm.addAccount("mark","123456");
}
@Test
public void testAuthentication(){
//构建SecurityManager环境
DefaultSecurityManager defaultSecurityManager =new DefaultSecurityManager();
defaultSecurityManager.setRealm(simpleAccountRealm);
//主动提交认证请求
SecurityUtils.setSecurityManager(defaultSecurityManager);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken("mark","123456");
subject.login(usernamePasswordToken);
}
}