I want a page has to appear to user after logged in. But if we use that link we can see the page and its content only thing is that it wont be having user data. what to do to prevent this. what can be done in this scenario ?
views:
33answers:
3
A:
I'm not familiar with JSF or if it has built in authentication/authorization. But you should be able to apply authentication/access rules directly on your web server.
jkyle
2010-04-06 06:14:12
+1
A:
Use a ServletFilter to check existence of UserData in Session.
If "yes: then forward else forward to error page.
Another option is to use the rendered
attribute on tags to check the existence of UserData object.
Padmarag
2010-04-06 06:16:46
+2
A:
You can declare a PhaseListener
where to redirect to the homepage instead the user is not logged
public void afterPhase(PhaseEvent evt) {
User user =
evt.getFacesContext().getExternalContext().getSessionMap().get(USER_KEY);
if (user == null) {
FacesContext.getExternalContext().redirect("home.xhtml");
}
}
The phase listener can be defined globally, or at view-level with:
<f:view afterPhase="#{bean.afterPhase}">...</f:view>
(in facelets the attribute is called afterPhaseListener
)
Bozho
2010-04-06 10:12:48
I think you would rather like to redirect if the `user` is **not** logged in.
BalusC
2010-04-06 11:32:48
indeed .. fixed.
Bozho
2010-04-06 11:40:49