kli*_*ind 4 jboss login wildfly
JBoss Wildfly 8.0.0-最终
JSF 2.2.4
首先,我使用application-users.properties和application-roles.properties创建了登录.使用add-user.bat添加了用户
在web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin Resource</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)
Standalone.xml
<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>
Run Code Online (Sandbox Code Playgroud)
login.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<div class="center">
<form method="POST" action="j_security_check" id="">
<h:panelGrid id="panel" columns="2" border="1" cellpadding="4" cellspacing="4">
<h:outputLabel for="j_username" value="Username:" />
<input type="text" name="j_username" />
<h:outputLabel for="j_password" value="Password:" />
<input type="password" name="j_password" />
<h:panelGroup>
<input type="submit" value="Login" />
</h:panelGroup>
</h:panelGrid>
</form>
</div>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
这样工作正常..现在我想使用数据库身份验证..所以我更改了standalone.xml.
<login-module code="Database" flag="sufficient">
<module-option name="dsJndiName" value="java:jboss/jsi/GarageXADataSource"/>
<module-option name="principalsQuery" value="select encode(password, 'hex') from principal where username=?"/>
<module-option name="rolesQuery" value="select r.role, r.role_group from role r inner join principal p on r.role = p.role where p.username=?"/>
<module-option name="hashAlgorithm" value="SHA-512"/>
<module-option name="hashEncoding" value="hex"/>
</login-module>
Run Code Online (Sandbox Code Playgroud)
我用这个sql在数据库中插入一个角色和一个用户(PostgreSQL 9.3)
INSERT INTO角色(role,role_group)VALUES('admin','Roles');
INSERT INTO校长(用户名,电子邮件,密码,角色)VALUES('Kris','xx @ gmail.com',digest('pass','sha512'),'admin');
但登录不起作用.我在日志中看不到任何错误.我之前在AS 7.1.1上使用过这种方法.
谢谢你的帮助.
首先,DatabaseServerLoginModule记录到跟踪级别,因此您应将org.jboss.security日志级别设置为在standalone.xml中进行跟踪,如下所示.现在您应该在server.log中看到错误
<logger category="org.jboss.security">
<level name="TRACE"/>
</logger>
Run Code Online (Sandbox Code Playgroud)
您还需要在jboss-web.xml中添加域名
<jboss-web>
<security-domain>java:/jaas/MyRealm</security-domain>
</jboss-web>
Run Code Online (Sandbox Code Playgroud)
您尚未在登录模块配置代码段周围提供周围的标记.你应该在下面有这样的东西.领域名称需要与web.xml中的名称匹配
<subsystem xmlns="urn:jboss:domain:security:1.0">
<security-domains>
<security-domain name="MyRealm">
<authentication>
<login-module code="Database" flag="required">
....
</authentication>
</security-domain>
</security-domains>
</subsystem>
Run Code Online (Sandbox Code Playgroud)
完成后,您可以从server.log发布任何错误.