1. package com.ufinity.spring;
2.
3. import java.lang.reflect.InvocationHandler;
4. import java.lang.reflect.Method;
5. import java.lang.reflect.Proxy;
6.
7. public class SecurityHandler implements InvocationHandler{
8.
9. private Object targetObj;
10.
11.
12. public Object newProxy(Object targetObj) {
13. this.targetObj = targetObj;
14. return Proxy.newProxyInstance(targetObj.getClass().getClassLoader() ,
15. targetObj.getClass().getInterfaces() ,
16. this);
17. }
18.
19. //实现了IncocationHandler接口,里面的一个方法.
20. public Object invoke(Object proxy, Method method, Object[] args)
21. throws Throwable {
22. this.checkSecurity();
23. Object result = null;
24. result = method.invoke(this.targetObj, args);
25. return result;
26. }
27.
28. //check security method
29. private void checkSecurity() {
30. System.out.println("-----------------SecurityHandler.checkSecurity()--------------");
31. }
32. }