| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.chenillekit.access.services.impl; |
| 20 | |
|
| 21 | |
import org.apache.tapestry5.annotations.OnEvent; |
| 22 | |
import org.apache.tapestry5.model.MutableComponentModel; |
| 23 | |
import org.apache.tapestry5.services.ClassTransformation; |
| 24 | |
import org.apache.tapestry5.services.ComponentClassTransformWorker; |
| 25 | |
import org.apache.tapestry5.services.TransformMethodSignature; |
| 26 | |
import org.chenillekit.access.ChenilleKitAccessConstants; |
| 27 | |
import org.chenillekit.access.ChenilleKitAccessException; |
| 28 | |
import org.chenillekit.access.annotations.Restricted; |
| 29 | |
import org.chenillekit.access.internal.ChenillekitAccessInternalUtils; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | 1 | public class RestrictedWorker implements ComponentClassTransformWorker |
| 36 | |
{ |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public void transform(ClassTransformation transformation, MutableComponentModel model) |
| 45 | |
{ |
| 46 | 23 | processPageRestriction(transformation, model); |
| 47 | |
|
| 48 | 23 | processEventHandlerRestrictions(transformation, model); |
| 49 | |
|
| 50 | |
|
| 51 | 23 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
private void processPageRestriction(ClassTransformation transformation, MutableComponentModel model) |
| 62 | |
{ |
| 63 | 23 | Restricted pageRestricted = transformation.getAnnotation(Restricted.class); |
| 64 | 23 | if (pageRestricted != null) |
| 65 | |
{ |
| 66 | 2 | String roleWeigh = Integer.toString(pageRestricted.role()); |
| 67 | 2 | String[] groups = pageRestricted.groups(); |
| 68 | |
|
| 69 | 2 | model.setMeta(ChenilleKitAccessConstants.RESTRICTED_PAGE_ROLE, roleWeigh); |
| 70 | |
|
| 71 | 2 | if (groups.length > 0) |
| 72 | 0 | model.setMeta(ChenilleKitAccessConstants.RESTRICTED_PAGE_GROUP, |
| 73 | |
ChenillekitAccessInternalUtils.getStringArrayAsString(groups)); |
| 74 | |
} |
| 75 | 23 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
private void processEventHandlerRestrictions(ClassTransformation transformation, MutableComponentModel model) |
| 86 | |
{ |
| 87 | 23 | for (TransformMethodSignature method : transformation.findMethodsWithAnnotation(Restricted.class)) |
| 88 | |
{ |
| 89 | 2 | String methodName = method.getMethodName(); |
| 90 | 2 | Restricted restricted = transformation.getMethodAnnotation(method, Restricted.class); |
| 91 | 2 | OnEvent event = transformation.getMethodAnnotation(method, OnEvent.class); |
| 92 | 2 | if (methodName.startsWith("on") || event != null) |
| 93 | |
{ |
| 94 | 2 | String componentId = ChenillekitAccessInternalUtils.extractComponentId(method, event); |
| 95 | 2 | String eventType = ChenillekitAccessInternalUtils.extractEventType(method, event); |
| 96 | |
|
| 97 | 2 | String groupMeta = ChenillekitAccessInternalUtils.buildMetaForHandlerMethod(componentId, |
| 98 | |
eventType, |
| 99 | |
ChenilleKitAccessConstants.RESTRICTED_EVENT_HANDLER_GROUPS_SUFFIX); |
| 100 | |
|
| 101 | 2 | String roleMeta = ChenillekitAccessInternalUtils.buildMetaForHandlerMethod(componentId, |
| 102 | |
eventType, |
| 103 | |
ChenilleKitAccessConstants.RESTRICTED_EVENT_HANDLER_ROLE_SUFFIX); |
| 104 | |
|
| 105 | 2 | model.setMeta(groupMeta, ChenillekitAccessInternalUtils.getStringArrayAsString(restricted.groups())); |
| 106 | 2 | model.setMeta(roleMeta, Integer.toString(restricted.role())); |
| 107 | 2 | } |
| 108 | |
else |
| 109 | |
{ |
| 110 | 0 | throw new ChenilleKitAccessException("Cannot put Restricted annotation on a non event handler method"); |
| 111 | |
} |
| 112 | 2 | } |
| 113 | 23 | } |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
private void processComponentsRestrictions(ClassTransformation transformation, MutableComponentModel model) |
| 124 | |
{ |
| 125 | 0 | throw new RuntimeException("NOT YET IMPLEMENTED"); |
| 126 | |
} |
| 127 | |
} |