0

Using Wildfly 8.1.0.Final

I want to create a web app that requires basic authentication for access to /api/* but the rest of the application should be open. To accomplish this I have the following web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" version="3.0">
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Api access</web-resource-name>
            <url-pattern>/api/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>api</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <role-name>api</role-name>
    </security-role>

    <login-config>
        <auth-method>BASIC</auth-method>
        <realm-name>Authentication requires api access</realm-name>
    </login-config>
</web-app>

Testing with a browser, this works as expected.

http://localhost:8080/myapp/api

...requires authentication.

http://localhost:8080/myapp 

...does not require authentication.

Here comes the tricky part:

A third party accesses /myapp and includes an authorization header in the request:

Authorization: Basic ZGlsbDpkYWxs

This is not a user registered in wildfly, but that shouldnt matter because /myapp is open, and does not require authorization. However what happens is this:

401 Unauthorized

Why? I have not told undertow to use any security constraints for /myapp, yet it defaults to the security constraints I have registered for /myapp/api

This is new behaviour that was introduced with undertow, because with Jboss AS 7.1.1.Final this did not happen.

How can I tell undertow to not use authorization for an open resource when authorization is included in the request?

4

1 回答 1

0

我可以确认 WildFly 8.1.0.Final 的问题。GlassFish 4.0 在同一场景中不会响应 401。

我已经提交了一个问题: https ://issues.jboss.org/browse/WFLY-3590

于 2014-07-07T17:35:58.060 回答