我尝试在 Wildfly 8.2.0.Final 中使用 Databaselogin 来保护我的应用程序。
我在standalone.xml中配置了我的数据源,它似乎可以访问数据库:
<datasource jndi-name="java:/jdbc/Racoonda" pool-name="RacoondaDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/racoonda</connection-url>
<driver>mysql</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>Gracefully</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>10000</background-validation-millis>
</validation>
<timeout>
<idle-timeout-minutes>10</idle-timeout-minutes>
</timeout>
<statement>
<prepared-statement-cache-size>10</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
而且我还在standalone.xml中配置了我的安全域,如下所示:
<security-domain name="racoondaAdmin" cache-type="default">
<authentication>
<login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
<module-option name="dsJndiName" value="java:/jdbc/Racoonda"/>
<module-option name="principalsQuery" value="SELECT password FROM Admin WHERE id=?"/>
<module-option name="rolesQuery" value="SELECT 'Admin', 'Roles' FROM dual"/>
</login-module>
</authentication>
</security-domain>
我在我的资源/WEB-INF/jboss-web中添加了域.xml:
`<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<security-domain>racoondaAdmin</security-domain>
</jboss-web>`
然后我尝试在资源/WEB-INF/web.xml 中保护我的应用程序:
`<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<distributable/>
<security-constraint>
<display-name>racoonda</display-name>
<web-resource-collection>
<web-resource-name>racoonda</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<context-param>
<param-name>resteasy.role.based.security</param-name>
<param-value>true</param-value>
</context-param>
<security-role>
<role-name>Admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Application</realm-name>
</login-config>
</web-app>`
数据库访问有效,因为我可以从我试图保护的服务中获取值(它从数据库中获取它们)。
但是我可以在不输入任何凭据的情况下访问它。我将安全日志级别放在 TRACE 中,并尝试了我能找到的所有方法,如果有人可以提供帮助,我将不胜感激。提前致谢