01: package simpleorm.simplewebapp.core;
02:
03: import simpleorm.simplewebapp.core.WMenuItemGlobal;
04: import simpleorm.simplewebapp.core.WPage;
05: import simpleorm.simplewebapp.context.WPageContext;
06:
07: /**
08: * Peer to WPage (one to one) providing Authorizaiton and Authentication methods.
09: */
10: public class WPageSecurity {
11: WPage page;
12:
13: /** Is the current user authorized to call this page at all.
14: * Checked by WPage Security, right at the top.
15: */
16: public boolean isAuthorized() {
17: WMenuItemGlobal myItem = page.getPageItem();
18: return isAccessible(myItem);
19: }
20:
21: public boolean isAccessible(WMenuItemGlobal item) {
22: boolean userInRole = isUserInRole(item.getRole());
23: //page.logger.debug("isAccessible user: "+ getRemoteUser() + ";" + item.getRole() + userInRole);
24: return userInRole;
25: }
26:
27: public String getRemoteUser() {
28: return getPageContext().getRemoteUser();
29: }
30:
31: public boolean isUserInRole(String role) {
32: if (role == null)
33: return true;
34: return getPageContext().isUserInRole(role);
35: }
36:
37: WPageContext getPageContext() {
38: return page.getPageContext();
39: }
40:
41: //////////////////////////////////////////
42:
43: WPageSecurity(WPage page) {
44: this.page = page;
45: }
46:
47: }
|