How to restrict access to JSF pages that are not login

I have implemented a simple login on a JSF. I am suppose to see a restricted pages after I login. However, I can also access the restricted page without going through the login process. How do I lock direct access to these restricted pages so that they can only be reached after a login process.
 I need to implement this in JSF for my school project.

What are my options to implemnt this?
dovobAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrcoffee365Commented:
If you are not using the login controls available from your servlet engine (e.g., Tomcat has security contraints which can be built in) then you have to implement the login security yourself.

You can check in the page whether the user has logged in, and if they have not, redirect them to the login page.
0
dovobAuthor Commented:
How can I check if the user is login in JSF?
0
mrcoffee365Commented:
In your simple login in JSF, write a value to the user session which indicates that your user is logged in.  Then check that value on every page which you are protecting with login.  For example:

After successful login:

session.setAttribute("loggedIn", "true");

Check on protected pages:

String checkLogin = (String) session.getAttribute("loggedIn");
if( "true".equalsIgnoreCase(checkLogin) ) {
  // okay
}
else {
  response.sendRedirect("/myloginpage.jsp");
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

dovobAuthor Commented:
Thanks for your patience. I have some knowledge on servlet and JSP but I am pretty new to the concept of JSF.

I would like to find out if there is a more sophisticated way of defining this in JSF without implementing the whole chunk of code on this page?

Is there anything I can include in face-config.xml?
0
mrcoffee365Commented:
0
dovobAuthor Commented:
I have tried them but none of them have the function of restricting access to restricted pages and logging out.

0
mrcoffee365Commented:
This example:
http://amateras.sourceforge.jp/docs/FacesIDE/SampleJSFApp.html

specifically restricts access to index.jsp with the login.  What didn't work for you?
0
dovobAuthor Commented:
I would like to restrict access to the successful.jsp in the example from
http://amateras.sourceforge.jp/docs/FacesIDE/SampleJSFApp.html

User who are not login cannot access the successful.jsp page directly from the url
http://localhost:8080/login/success.jsp
instead they have to go through the normal login process from
http://localhost:8080/login/login.jsp
in order to reach the successful page.
How do I implement such a restriction of the successfl.jsp page. That's my question.
0
mrcoffee365Commented:
What does your web.xml look like?  Did you follow the directions at the bottom of the page, which explains what to change?
0
mrcoffee365Commented:
The answers were correct, so I think points should be awarded.
0
mrcoffee365Commented:
Okay.   I was the only one who answered, and my answers were correct.  They would also be useful to others using JSF (as beginners, as in this case).  So any of my answers, from the first through the 4th above, could be marked as the accepted answer.  

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.