I'd like to make some page "protected" i.e. if a user hasn't been logged in then such a page must not be displayed. The solution was found here: found ergcser

T5 - Authentication filter
T5:Login and session
So, I added one new page class (abstract), LoginProtected it should serve as a base for all "protected" pages://incomplete listing
public abstract class LoginProtected {
@ApplicationState
private SessionData _session;
Object onActivate() {
if(!_session.isSessionExists()){
return "Login";
}
return null;
}
SessionData is a "value" object to store userName and sessionExists flag between pages, so if a session doesn't exist then user will be redirected to Login page.
Also, I changed the Home page, now it extends LoginProtected:
public class Home extends LoginProtected {
Another change - Login.java, new private variable _session was added, see the code.
So, now, if a user tries to open /home page without logging in , the navigation will go to the Login page.
8. Step 08, Simple authentication
7. SimpleTapestry 5 CRUD application -Step 07, Cancel button, variant 1.
6. SimpleTapestry 5 CRUD application -Step 06, tweaking a grid a bit.
5. Simple Tapestry 5 CRUD application - BeanEditForm and Grid screencasts aprobation.
4. SimpleTapestry 5 CRUD application -Step 04 Adding some basic Hibernate features into the project.
3. SimpleTapestry 5 CRUD application -Step 03, "user" bean creation.
2. SimpleTapestry 5 CRUD application -Step 02, adding a service.
1. SimpleTapestry 5 CRUD application -Step 01.
3 comments:
Post a Comment