This is my first post, so I apologize in advance for any stupidity on your behalf.
I need an annotation to limit the use of a service class in Java 6 / SPRING 3 that role.
I called an annotation RequiredPermission have to define one or more values as its value attribute of an enum is said Opreshntaip:
public @ interface Apekshitpradrshn {/ ** * One or more {@link OperationType} s that maps the necessary permissions to execute this method. * * @ Return * / Operation Type [] Price ();} Public Animate OperationType {TYPE1, TYPE2; } Package com.mycompany.myservice; Public Interface MyService {@RequiredPermission (OperationType.TYPE1) myMethod (MyParameterObject obj) Zero; } Package com.mycompany.myserviceimpl; Public class MyServiceImpl implements MyService {public MyMethod (MyParameterObject obj) {// do stuff here}}
I have the following aspect definition:
/ Security advice about methods annotated with ** * * {@link RequiredPermission}. * * @param PJP * @param param * @param requiredPermission * @return * @throws propellant * / @Around (value = "execution (public *" + "com.mycompany.myserviceimpl. * (..))" + "& amp; & amp; arg (ultimate)" + // parameter object "& amp; & amp; @annotation (requiredPermission)" // allow annotations, argNames = "absolute, requiredPermission") public object ProcessRequest (last ProceedingJoinPoint PJP last MyParameterObject ultimate, final RequiredPermission requiredPermission) throws propellant {if (userService.userHasRoles (param.getUsername (), requiredPermission.values ()) {return pjp.proceed ();} else {requiredPermission.value throw new SorryButYouAreNotAllowedToDoThatException (Param.getUsername (), ());}}
feet The meter object has a user's name and I want to see the required role for the user before allowing the use of the method.
When I put an annotation on the method in MySsebi, emplog, everything works fine The point is matched and the aspect comes in. However, I believe the annotation service is part of the contract and should be published in a separate API package with the interface. And of course, I do not want to comment on both service definition and implementation (dry).
I know there are cases where spring anoptions are triggered by an interaction method (eg transaction) in the AOP. Is there a special syntax here or it's just impossible to get out of the box.
PS: I have not posted my spring configuration, because it seems that it is working fine. And no, these are neither my original classes nor the names of the laws.
Thanks in advance, Sean
PPS: In fact, here is the relevant part of my spring configuration:
& lt; Aop: aspectj-autoproxy proxy-target-square = "wrong" /> & Lt; Bean class = "com.mycompany.aspect.MyAspect" & gt; & Lt; Property Name = "User Service" Reference = "User Service" / & gt; & Lt; / Bean & gt;
If I think you are right, you want to indicate a point which searches all the methods in classes
execution (public * com.mycompany.myserviceimpl. * (..)): I I propose the proposed argument. With
:
Execution (public * com.mycompany.myservice.MyService +. * (..))
plus symbol is used if you want to joinpoint to match the MyService class or that extension containing the square.
I hope it helps!
Comments
Post a Comment