Page セキュリティ
onSecurityCheckメソッドが用意され、securityの拡張ポイントがある。
実際のコードは用意してあるものを利用すればよい。
Application Authentication
ログインページで、認証を行い、成功した場合はsessionを作成するアプリケーションがあるとする。ログインページ以外では、sessionの有無をチェックする。
public class Secure extends Page { _/** * @see Page#onSecurityCheck() */ public boolean onSecurityCheck() { if (getContext().hasSession()) { return true; } else ( setRedirect("login.htm"); return false; } } }
Container Authentication
コンテナの認証を利用するのであれば、以下のようにすればよい
public class Secure extends Page { _/** * @see Page#onSecurityCheck() */ public boolean onSecurityCheck() { if (getContext().getRequest().getRemoteUser() != null) { return true; } else ( setRedirect("login.htm"); return false; } } }
Container Access Control
ロールによるアクセス制限を利用するのであれば、以下のようにすればよい
public class AdminPage extends Page { _/** * @see Page#onSecurityCheck() */ public boolean onSecurityCheck() { if (getContext().getRequest().isUserInRole("admin")) { return true; } else ( setRedirect("login.htm"); return false; } } }
LogOut
ログイン成功したらsessionを作成するようなアプリケーションのモデルにした場合、ログアウトは以下のようにすればよい
public class Logout extends Page { _/** * @see Page#onInit() */ public boolean onInit() { getContext().getSession().invalidate(); } }