本人使用IDEA平台
1.org.apache.shiro.authc.UnknownAccountException: Realm [org.apache.shiro.realm.SimpleAccountRealm@763d9750] was unable to find account data for the submitted AuthenticationToken [org.apache.shiro.authc.UsernamePasswordToken - Mark, rememberMe=false].
分析:检查用户名是否一致,若一致,在创建的账户密码方法上加上@ Before
public class AuthenticationTest {
SimpleAccountRealm simpleAccountRealm=new SimpleAccountRealm();
@Before
public void addUser(){
simpleAccountRealm.addAccount("Mark","123456");
}
@Test
public void testAuthentication(){
//1.构建SecurityManager环境
DefaultSecurityManager defaultSecurityManager=new DefaultSecurityManager();
defaultSecurityManager.setRealm(simpleAccountRealm);
//2.主体提交认证请求
SecurityUtils.setSecurityManager(defaultSecurityManager);
Subject subject= SecurityUtils.getSubject();
UsernamePasswordToken token=new UsernamePasswordToken("Mark1","123456");
subject.login(token);
System.out.println("isAuthenticatede:"+subject.isAuthenticated());
// subject.isAuthenticated();
}
}
2.org.apache.shiro.authc.IncorrectCredentialsException: Submitted credentials for token [org.apache.shiro.authc.UsernamePasswordToken - Mark, rememberMe=false] did not match the expected credentials.
分析:错误的凭证异常,检查密码是否一致
3.org.apache.shiro.config.ConfigurationException: java.io.FileNotFoundException: classspath:user.ini (系统找不到指定的文件。)
分析:
1、检查是否存在user.ini文件;
2、检查文件名和路径名是否一致;
3、检查classpath的拼写是否正确。
我这里报错的问题是classpath拼写错误。
4.The security manager does not implement the WebSecurityManager interface.
分析:可能是导包错误,修改即可。org.apache.shiro.web.mgt.DefaultWebSecurityManager。web容易被忽视掉
修改前:
<!--创建SecurityManager对象-->
<bean class="org.apache.shiro.mgt.DefaultWebSecurityManager" id="securityManager"/>
修改后:
<!--创建SecurityManager对象-->
<bean class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" id="securityManager"/>