我正在尝试在 JBoss 7.1 应用程序服务器上实现基于数据库的 JAAS 身份验证,但出现以下错误。任何指针都会有所帮助。
我已共享配置详细信息。
14:46:03,807 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] (http-localhost/127.0.0.1:8080-2)获得用户密码14:46:03,808 DEBUG [org.jboss.jca.core. connectionmanager.pool.strategy.OnePool] (http-localhost/127.0.0.1:8080-2) AppDS: returnConnection(40c2d8ac, false) [1/9] 14:46:03,808 TRACE [org.jboss.security.auth.spi .DatabaseServerLoginModule] (http-localhost/127.0.0.1:8080-2) resumeAnyTransaction 14:46:03,808 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] (http-localhost/127.0.0.1:8080-2)用户'test_user' 已通过身份验证,loginOk=true14:46:03,808 TRACE [org.jboss.security.auth.spi.DatabaseServerLoginModule] (http-localhost/127.0.0.1:8080-2) 中止 14:46:03,809 错误 [org.jboss.security.authentication.JBossCachedAuthenticationManager] (http-localhost/127.0.0.1:8080-2)登录失败:javax.security.auth.login.FailedLoginException:密码不正确/需要密码 org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:293) [picketbox-4.0.9.Final-redhat-1.jar:4.0.9.Final-redhat-1] 在 sun.reflect。 NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.7.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [ rt.jar:1.7.0_25] 在 java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.7.0_25] at javax.security.auth.login.LoginContext.invoke(Unknown Source) [rt.jar:1.7.0_25] jar:1.7.0_25] 在 javax.security.auth.login.LoginContext.access$000(Unknown Source) [rt.jar:1.7.0_25] at javax.security.auth.login.LoginContext$4.run(Unknown Source) [ rt.jar:1.7.0_25] 在 javax.security.auth.login.LoginContext$4.run(Unknown Source) [rt.jar:1.7.0_25] 在 java。security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_25] at javax.security.auth.login.LoginContext.invokePriv(Unknown Source) [rt.jar:1.7.0_25] at javax.security.auth。 login.LoginContext.login(Unknown Source) [rt.jar:1.7.0_25] at org.jboss.security.authentication.JBossCachedAuthenticationManager.defaultLogin(JBossCachedAuthenticationManager.java:449) [picketbox-infinispan-4.0.9.Final-redhat- 1.jar:4.0.9.Final-redhat-1] 在 org.jboss.security.authentication.JBossCachedAuthenticationManager.proceedWithJaasLogin(JBossCachedAuthenticationManager.java:383) [picketbox-infinispan-4.0.9.Final-redhat-1.jar: 4.0.9.Final-redhat-1] 在 org.jboss.security.authentication.JBossCachedAuthenticationManager.authenticate(JBossCachedAuthenticationManager.java:371) [picketbox-infinispan-4.0.9.Final-redhat-1.jar:4.0.9。Final-redhat-1] 在 org.jboss.security.authentication.JBossCachedAuthenticationManager.isValid(JBossCachedAuthenticationManager.java:160) [picketbox-infinispan-4.0.9.Final-redhat-1.jar:4.0.9.Final-redhat- 1] 在 org.jboss.as.web.security.JBossWebRealm.authenticate(JBossWebRealm.java:214) [jboss-as-web-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat- 1] 在 org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:280) [jbossweb-7.0.16.Final-redhat-1.jar:] 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke( AuthenticatorBase.java:381) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa- 7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1] 在 org.jboss.as.web.security.SecurityContextAssociationValve。在 org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:155) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final- redhat-1.jar:] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.catalina.connector .CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0 .16.Final-redhat-1.jar:] 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final-redhat-1.jar:] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final-redhat-1.jar:] at java .lang.Thread.run(未知来源)[rt.jar:1.7.0_25]
jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 2.4//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
<!-- <security-domain>java:/jaas/apsapp</security-domain> -->
<security-domain>other</security-domain>
<context-root>/app</context-root>
</jboss-web>
web.xml
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Secured Content</web-resource-name>
<url-pattern>/auth/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>ADMINISTRATOR</role-name>
<role-name>AUTHENTICATED</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>ADMINISTRATOR</role-name>
</security-role>
<security-role>
<role-name>AUTHENTICATED</role-name>
</security-role>
独立的.xml
<subsystem xmlns="urn:jboss:domain:security:1.2">
<security-domains>
<security-domain name="other" cache-type="default">
<authentication>
<login-module code="Remoting" flag="optional">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
<login-module code="RealmDirect" flag="required">
<module-option name="password-stacking" value="useFirstPass"/>
</login-module>
<login-module code="Database" flag="required">
<module-option name="dsJndiName" value="java:jboss/datasources/appPgDS"/>
<module-option name="principalsQuery" value="select passwd from app.user where username=?"/>
<module-option name="rolesQuery" value="select role,'Roles' from app.userrole where username=?"/>
<module-option name="hashAlgorithm" value="MD5"/>
<module-option name="hashEncoding" value="base64"/>
<module-option name="hashCharset" value="UTF-8"/>
<module-option name="unauthenticatedIdentity" value="guest"/>
</login-module>
</authentication>
</security-domain>
登录.xhtml
<form id="loginForm" action="j_security_check" method="post">
<input type="text" name="j_username" value="test_user" maxlength="22" />
<input type="password" name="j_password" value="password" maxlength="22" />
<input type="submit" />
</form>
密码生成
import org.jboss.security.auth.spi.*;
String passwordHash = Util.createPasswordHash("MD5", "base64", null, null, "password");
//Value generated and stored in DB: X03MO1qnZdYdgyfeuILPmQ==