What's the best way to control access to a page and also using error-pages

UI Components for JSF
Post Reply
guibernardi
Posts: 16
Joined: 19 Aug 2015, 15:16

20 Apr 2018, 22:57

Hi,

Maybe this is not the right place to do this question, if not I'm sorry, but maybe someone could help me.

First I created a Filter to control access page:

Code: Select all

@WebFilter(filterName = "AppAuthFilter", urlPatterns = {"*.jsf"})
public class AppAuthFilter extends AppController implements Filter {
...
...
}
But I have to check in my database if the view is in maintenance-mode or if the user doesn't have access. So I put some queries in this filter and I started to have performance problems, because I'm using "*.jsf" as pattern and the application execute this filter at least 10 times for a simple page passing by css files, js files and icons, because all of them came with .jsf in the end.

So I search a little bit and find about PhaseListener and sounds really better because it only pass one time for each page request.

But when I was using the Filter, when the page is in maintenance-mode for example, I just send a error:

Code: Select all

response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
And this redirect the application to the error-page, like error-500 or 404.xhtml, but in the PhaseListener it doesn't work.

I tried like this, inside the afterPhase method.

Code: Select all

HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
But the application shows the default error of the browser.

So what is the best practice to do this?

Thanks in advance.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

21 Apr 2018, 14:17

Not a PrimeFaces question this question belongs on StackOverflow.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 17 guests