java – Apache Shiro:登录时出现IllegalArgumentException
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Apache Shiro:登录时出现IllegalArgumentException,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3216字,纯文字阅读大概需要5分钟。
内容图文
![java – Apache Shiro:登录时出现IllegalArgumentException](/upload/InfoBanner/zyjiaocheng/804/678198e378a949a9ad01cba06e4c2721.jpg)
使用Apache Shiro时,登录时会出现以下异常:
java.lang.IllegalArgumentException: Configuration error. Configuration error. Specified object [authc] with property [loginUrl] without first defining that object’s class. Please first specify the class property first, e.g. myObject = fully_qualified_class_name and then define additional properties.
shiro.ini
# -----------------------------------------------------------------------------
[main]
authc.loginUrl=/login.xhtml
authc.successUrl=/hello.xhtml
logout.redirectUrl=/hello.xhtml
# Users and their (optional) assigned roles
# username = password, role1, role2, ..., roleN
# -----------------------------------------------------------------------------
[users]
root = secret, admin
guest = guest, guest
# -----------------------------------------------------------------------------
# Roles with assigned permissions
# roleName = perm1, perm2, ..., permN
-----------------------------------------------------------------------------
[roles]
admin = *
schwartz = lightsaber:*
goodguy = winnebago:drive:eagle5
#------------------------------------------------------------------------------
[urls]
/hello.xhtml= authc
调节器
public void login() {
Factory<SecurityManager> factory = new IniSecurityManagerFactory();
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
Subject currentUser=SecurityUtils.getSubject();
if(!currentUser.isAuthenticated()){
UsernamePasswordToken token=new UsernamePasswordToken("root","secret");
token.setRememberMe(true);
try{
currentUser.login(token);
}catch(UnknownAccountException e){
System.out.println("username is incorrect");
}catch (IncorrectCredentialsException e) {
System.out.println("password is incorrect");
}catch (LockedAccountException e) {
System.out.println("account was locked");
}catch (AuthenticationException e) {
System.out.println("there are some error");
}
}
}
web.xml中
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
</listener>
<filter>
<filter-name>ShiroFilter</filter-name>
<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ShiroFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
解决方法:
尝试使用PassThruAuthenticationFilter从控制器执行登录尝试.将此行添加到shiro.ini:
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
接下来,当您从web.xml文件启动Shiro Security Manager时,可以从login()方法中删除以下代码行:
Factory<SecurityManager> factory = new IniSecurityManagerFactory();
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
请注意,FormAuthenticationFilter是另一种类型的身份验证筛选器,它还可以帮助处理登录请求.
内容总结
以上是互联网集市为您收集整理的java – Apache Shiro:登录时出现IllegalArgumentException全部内容,希望文章能够帮你解决java – Apache Shiro:登录时出现IllegalArgumentException所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。