aspectj

How to implement annotation based security using Spring AOP?

假装没事ソ 提交于 2019-12-10 15:59:20
问题 I'm new to Spring AOP (and AOP in general), need to implement the following: @HasPermission(operation=SecurityOperation.ACTIVITY_EDIT, object="#act") public Activity updateActivity(Activity act) { ... } @HasPermission is my custom annotation, which will be used to mark all methods requiring pre-authorization. I'm using my custom implementation of security checks based on Apache Shiro. Generally, I guess that I will need to define pointcut which matches all annotated methods and also provide

nullpointer exception in aspectJ example

我只是一个虾纸丫 提交于 2019-12-10 15:25:25
问题 I am trying to implement one of the suggestion given by our stackoverflow member here Logging entry, exit and exceptions for methods in java using aspects . Since this is different question in itself, posting here again. I have tried to search but looks like different versions have different ways of doing it and unable to figure out an example online. I have tried the following simple example since I am new to aspect oriented programming and couldn't figure out how to implement. This example

Spring Boot AOP load time weaving

China☆狼群 提交于 2019-12-10 14:54:19
问题 Not sure what is going wrong, but AOP just doesn't seem to be working in my setup with spring boot (v1.1.6). @Configuration @ComponentScan @EnableJpaRepositories @EnableTransactionManagement @EnableAutoConfiguration @EnableCaching @EnableLoadTimeWeaving public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } And in the aspect class @Aspect public class MyAspect { @AfterReturning(pointcut = "execution(private * com.myapp.service

How to mock an aspect

老子叫甜甜 提交于 2019-12-10 14:34:05
问题 I am currently working on some monitoring tool using aspectj. Because this tool should be technology independent (as far as possible), I am not using Spring for injection. But I want my aspects to be unit-tested. Aspect example: @Aspect public class ClassLoadAspect { private Repository repository; public ClassLoadAspect() { repository = OwlApiRepository.getInstance(); } @After("anyStaticInitialization()") public void processStaticInitilization(JoinPoint jp) { Class type = jp.getSourceLocation

Load time weaving in AspectJ using aop.xml

心已入冬 提交于 2019-12-10 13:36:42
问题 From what I understand, for load time weaving to work using an aop.xml file, it must be placed in META-INF. Is there a way to get around this and use an aop.xml (or any xml file) in any directory? Thanks. 回答1: You can use the system property org.aspectj.weaver.loadtime.configuration to point to another AspectJ config file. For example: -D org.aspectj.weaver.loadtime.configuration=META-INF/myaop.xml 来源: https://stackoverflow.com/questions/3314953/load-time-weaving-in-aspectj-using-aop-xml

using Spring @Profile in @Aspect

风流意气都作罢 提交于 2019-12-10 13:33:23
问题 So what i want is to apply an specific Spring Aspect to my classes when an profile is active, but i can't find a solution, i try the way proposed in http://city81.blogspot.com/2012/05/using-spring-profile-with.html but is quite old and don't work in my case, i have a Spring Started project for testing and i do the following based on the link: configuring the Application: @Configuration @ComponentScan(basePackages= { "demo", "demo.aspect" }) @EnableAutoConfiguration(exclude

AspectJ - why “advice defined in XYZ has not been applied”?

 ̄綄美尐妖づ 提交于 2019-12-10 12:40:33
问题 I just started playing with AspectJ (1.6.11). I'm sending emails via commons-email libary and I'd like to know how long it takes to send a message. So this is my email sending code: import org.apache.commons.mail.Email; import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; public class EmailTest { public static void main(String[] args) throws EmailException { Email e = new SimpleEmail(); e.setHostName("localhost"); e.setFrom("foo@localhost"); e.addTo(

aspectj: How to weave aspects from a library into user code?

a 夏天 提交于 2019-12-10 11:57:09
问题 I have a library with some classes and a few aspects in it. Say AspectedLib.jar is the file that contains such definitions (created in eclipse, with "export jar file with aspectj support"). If I import the AspectedLib.jar file, and even use some of the classes defined in it, it works, but none of the joinpoints is triggered, i.e., the aspects are not executed. How can I make this work? Ideally, how can I set this up in eclipse*? * Version: Juno Service Release 2; Build id: 20130225-0426 回答1:

Logging user actions

我怕爱的太早我们不能终老 提交于 2019-12-10 11:08:24
问题 The customer wants us to "log" the "actions" that a user performs on our system: creation, deletion and update, mostly. I already have an aspect that logs the trace, but that works at a pretty low level logging every method call. So if a user clicked on the button "open medical file" the log would read: closePreviousFiles("patient zero") createMedicalFile("patient zero") --> file #001 changeStatus("#001") --> open while the desired result is: opened medical file #001 for patient zero I'm

Spring MVC + Before Advice check security

天涯浪子 提交于 2019-12-10 10:57:11
问题 I'm testing Spring AOP framework and have the following question. I have the following code: package danny.test.controllers; @Controller public class MyController{ @Autowired private DaoService service; @RequestMapping(value="/save",method = RequestMethod.POST) public String addUser(@Valid MyClass myClass, BindingResult result){ service.save(myClass); return "Ok"; } I would like to create before Advice aspect to check user security in user session. @Aspect public class Profiler { @Pointcut(