nuclear kote
nuclear kote

Reputation: 500

How can I modify 401 tomcat error response?

I want to add several headers to error response. How can I do that?

I tried use Filter

<filter>
    <filter-name>Filter</filter-name>
    <filter-class>com.example.filter.Filter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

but it does not call. I use BASIC authentication.

Upvotes: 0

Views: 778

Answers (1)

Mark Thomas
Mark Thomas

Reputation: 16635

You can't use a filter to do this because authentication takes place before the filters are invoked.

You can specify a custom error page for 401 responses in web.xml and in that page you can set whatever headers you wish.

Upvotes: 1

Related Questions