| 1 |
|
package org.trails.security; |
| 2 |
|
|
| 3 |
|
import java.beans.Introspector; |
| 4 |
|
import java.beans.PropertyDescriptor; |
| 5 |
|
import java.lang.reflect.Field; |
| 6 |
|
import java.lang.reflect.Method; |
| 7 |
|
import java.util.ArrayList; |
| 8 |
|
import java.util.Iterator; |
| 9 |
|
import java.util.List; |
| 10 |
|
|
| 11 |
|
import ognl.Ognl; |
| 12 |
|
import org.trails.descriptor.IClassDescriptor; |
| 13 |
|
import org.trails.descriptor.IPropertyDescriptor; |
| 14 |
|
import org.trails.security.annotation.SecurityAnnotationHandler; |
| 15 |
|
|
| 16 |
|
public class TrailsSecurityService implements SecurityService |
| 17 |
|
{ |
| 18 |
|
|
| 19 |
|
public TrailsSecurityService() |
| 20 |
|
{ |
| 21 |
10 |
super(); |
| 22 |
|
|
| 23 |
10 |
} |
| 24 |
|
|
| 25 |
|
public List buildRestrictions(IClassDescriptor classDescriptor) |
| 26 |
|
{ |
| 27 |
41 |
ArrayList restrictions = new ArrayList(); |
| 28 |
41 |
SecurityAnnotationHandler annotationHandler = new SecurityAnnotationHandler(); |
| 29 |
41 |
restrictions.addAll(annotationHandler.buildClassRestrictions(classDescriptor.getType())); |
| 30 |
41 |
for (Iterator iter = classDescriptor.getPropertyDescriptors().iterator(); iter.hasNext();) |
| 31 |
|
{ |
| 32 |
250 |
IPropertyDescriptor propertyDescriptor = (IPropertyDescriptor) iter.next(); |
| 33 |
|
try |
| 34 |
|
{ |
| 35 |
250 |
Field field = classDescriptor.getType().getDeclaredField( |
| 36 |
|
propertyDescriptor.getName()); |
| 37 |
226 |
restrictions.addAll(annotationHandler.buildPropertyRestrictions( |
| 38 |
|
field, propertyDescriptor.getName()) ); |
| 39 |
|
} |
| 40 |
24 |
catch (Exception ex) |
| 41 |
|
{ |
| 42 |
|
|
| 43 |
226 |
} |
| 44 |
|
try |
| 45 |
|
{ |
| 46 |
250 |
PropertyDescriptor beanPropDescriptor = (PropertyDescriptor) Ognl.getValue("propertyDescriptors.{? name == '" + propertyDescriptor.getName() + "'}[0]", |
| 47 |
|
Introspector.getBeanInfo(classDescriptor.getType())); |
| 48 |
249 |
Method readMethod = beanPropDescriptor.getReadMethod(); |
| 49 |
249 |
restrictions.addAll(annotationHandler.buildPropertyRestrictions( |
| 50 |
|
readMethod, propertyDescriptor.getName()) ); |
| 51 |
|
} |
| 52 |
1 |
catch (Exception ex) |
| 53 |
|
{ |
| 54 |
|
|
| 55 |
249 |
} |
| 56 |
250 |
} |
| 57 |
41 |
return restrictions; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
public List findRestrictions(IClassDescriptor classDescriptor) |
| 61 |
|
{ |
| 62 |
|
|
| 63 |
40 |
return buildRestrictions(classDescriptor); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
} |