Wildfly数据库表单登录模块生产失败

时间:2015-04-05 21:28:02

标签: jsf wildfly managed-bean wildfly-8

有一段时间我在localhost(Windows 8.1)上开发了我的Wildfly 8.1 Web应用程序,并希望将我的Ubuntu Server部署到Wildfly 8.2。

本地表单登录与ManagedBean一起使用,但在我的生产服务器上它失败。为什么呢?

  • 数据库连接有效。

因此,我暗示它与我的standalone.xml文件中配置的表单登录有关。这显然与我的localhost standalone.xml文件非常相似。我查了一下,生产的Wildfly 8.2真的使用了这个standalone.xml文件!对生产数据库执行主体查询(与我的localhost上的供应商和版本相同)只返回1行。与我当地的开发环境相同。

但是为什么这个principalsQuery登录模块在生产中不起作用?有人知道吗?

<login-module code="Database" flag="required">
    <module-option name="dsJndiName" value="java:jboss/datasources/CcmsDS"/>
    <module-option name="principalsQuery" value="SELECT password FROM User WHERE username=?"/>
    <module-option name="rolesQuery" value="SELECT role, 'Roles' FROM User JOIN User_Role ON User.id = User_Role.users_id JOIN role ON User_Role.roles_id = Role.id WHERE username=?"/>
</login-module>

我能不能在我的生产服务器日志中输出确切原因?

这是ManagedBean代码:

        try {
            request.login(getUsername(), getPassword());            
        } catch (ServletException e) {
            LOGGER.info("Failed to login with username " + username + " and password. " + e.getMessage() + ". ");
            e.printStackTrace();
            facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Login failed",
                    "Login failed when trying to authenticate with user " + getUsername() + "."));
            // If this fails, return null.
            return null;
        }

...这里是来自HttpServletRequestImpl的错误消息:

2015-04-05 23:03:06,320 ERROR [stderr] (default task-12) L:71 javax.servlet.ServletException: UT010031: Login failed
2015-04-05 23:03:06,320 ERROR [stderr] (default task-12) L:71   at io.undertow.servlet.spec.HttpServletRequestImpl.login(HttpServletRequestImpl.java:440)
2015-04-05 23:03:06,321 ERROR [stderr] (default task-12) L:71   at com.johndoe.controller.security.LoginController.login(LoginController.java:239)

1 个答案:

答案 0 :(得分:1)

解决方案:rolesQuery不区分大小写(Windows - &gt; Ubuntu)。我纠正了它,并且原则查询有效。不知道为什么他们互相联系。希望这也有助于其他人。