未调用安全域(工作)

时间:2016-06-30 20:14:15

标签: java wildfly wildfly-8 securitydomain

我尝试使用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并尝试了我能找到的每种方法如果有人可以提供帮助,那将非常感激。提前致谢

2 个答案:

答案 0 :(得分:1)

将配置文件放在src / main / webapp / WEB-INF文件夹中。

答案 1 :(得分:0)

是的,我还将其添加为默认域名,因为其他一些帖子指出了这一点。似乎野生动物根本没有调用它 编辑:我注意到我回答了我的问题而不是@Alfś评论...请忽略这一个:)