Hi Guys,
<div><br></div><div>I try implement solution for custom my page error 401 with autentication opencms, but dont work, a see this, I dont understand change, the file in opencms for put this filter.</div><div><br></div><div>
Here is how you can create a custom 401 (Not Authorized) error response<br>in Tomcat.  Putting a directive like this:<br><br><error-page><br>  <error-code>401</error-code><br>  <location>/errors/401.html</location><br>
</error-page><br><br>in web.xml will not work.  If you put that in web.xml, it will deny all<br>authorization.<br><br>The thing to do is to create a filter for the resources you want to<br>protect.  Do the conventional basic authentication in the filter. <br>
However, here is the part which is different:<br><br></div><div>THIS QUESTION IS, WHERE I PLACE THIS CODEIN OPENCMS:</div><div><br>   String errorFile = "/errors/401.html";<br>        response.addHeader("WWW-Authenticate", "BASIC realm=\"" + realm<br>
+ "\"");<br>        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);<br>        RequestDispatcher rd = request.getRequestDispatcher(errorFile);<br>        try { rd.forward(request,response); }<br><br>
So instead of letting the container generate the html for the 401<br>response, you always generate it using the RequestDispatcher.  The<br>RequestDispatcher can of course be an html or jsp file.<br><br>So that is the solution to custom 401 errors in Tomcat.<br>
</div><div><br></div><div>Best Regards,</div><div><br></div><div>Deiverson</div>