01: package org.osbl.client;
02:
03: import org.conform.*;
04: import org.wings.session.SessionManager;
05: import org.osbl.ServiceProvider;
06:
07: class AuthorizationModifier implements Modifier {
08: private BeanMetaProvider beanMetaProvider;
09: private org.osbl.authorization.Authorization authorization;
10:
11: public AuthorizationModifier(BeanMetaProvider beanMetaProvider) {
12: this .beanMetaProvider = beanMetaProvider;
13: }
14:
15: public void modify(BeanMeta beanMeta) throws ModifierException {
16: for (int i = 0; i < beanMeta.getProperties().length; i++) {
17: PropertyMeta propertyMeta = beanMeta.getProperties()[i];
18: PropertyMeta inheritPropertyMeta = getInheritPropertyMeta(propertyMeta);
19: performAuthorization(propertyMeta,
20: inheritPropertyMeta != null ? inheritPropertyMeta
21: : propertyMeta);
22: }
23: }
24:
25: private PropertyMeta getInheritPropertyMeta(
26: PropertyMeta propertyMeta) {
27: Class beanClass = (Class) propertyMeta
28: .getAttribute("inheritBean");
29: if (beanClass == null)
30: return null;
31:
32: String propertyName = (String) propertyMeta
33: .getAttribute("inheritProperty");
34: BeanMeta inheritBeanMeta = beanMetaProvider
35: .getBeanMeta(beanClass);
36: return inheritBeanMeta.getProperty(propertyName);
37: }
38:
39: private void performAuthorization(PropertyMeta toPropertyMeta,
40: PropertyMeta fromPropertyMeta) {
41: String permission = fromPropertyMeta.getBeanMeta().getName()
42: + "." + fromPropertyMeta.getName();
43: String userid = SessionManager.getSession().getServletRequest()
44: .getUserPrincipal().getName();
45:
46: toPropertyMeta.setReadable(toPropertyMeta.isReadable()
47: & getAuthorization().checkPermission(userid,
48: permission, "r"));
49: toPropertyMeta.setWritable(toPropertyMeta.isWritable()
50: & getAuthorization().checkPermission(userid,
51: permission, "w"));
52: }
53:
54: protected org.osbl.authorization.Authorization getAuthorization() {
55: if (authorization == null)
56: authorization = (org.osbl.authorization.Authorization) ServiceProvider
57: .getInstance().getService("AuthorizationService");
58: return authorization;
59: }
60: }
|