I need to allow only logged-in users to most of the pages of my application. I am developing a Java Enterprise application with JSF 2. Does anyone know how I can do that? maybe with a config file?
I have a login component in the home page and I would like the users to be redirected to the home page when they click any other items of the page except a few.
There are many ways to achieve that. The easiest and probably the most popular way would be to use servlet filter, you can find more information about such a mechanism here: Basic Security in JSF
There are different ways to do that . Firstly you can use filters to control page access or you can use phase listeners that listens jsf phases .
I wanna give you two examples for them ;
And you should add this filter to web.xml;
Phase Listener example ;
So if you want to use listener you should add this to your faces-config.xml ; Note : "logout" is a navigation rule which is defined in faces-config
Edit : The navigation rule ;
You can put your user to session in login method like that ;