/portal-impl/src/com/liferay/portal/security/pacl/checker/CheckerUtil.java

https://github.com/lululiferay/liferay-portal · Java · 54 lines · 22 code · 16 blank · 16 comment · 3 complexity · 29153be8c6f17f0f296f439cdc3ef462 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.portal.security.pacl.checker;
  15. import com.liferay.portal.kernel.util.JavaDetector;
  16. import java.security.AccessController;
  17. import sun.reflect.Reflection;
  18. /**
  19. * @author Brian Wing Shun Chan
  20. */
  21. public class CheckerUtil {
  22. public static boolean isAccessControllerDoPrivileged(int frame) {
  23. frame++;
  24. Class<?> callerClass = Reflection.getCallerClass(frame);
  25. if (callerClass != AccessController.class) {
  26. return false;
  27. }
  28. Thread currentThread = Thread.currentThread();
  29. StackTraceElement[] stackTraceElements = currentThread.getStackTrace();
  30. if (JavaDetector.isIBM()) {
  31. frame++;
  32. }
  33. StackTraceElement stackTraceElement = stackTraceElements[frame];
  34. String methodName = stackTraceElement.getMethodName();
  35. return methodName.equals(_METHOD_NAME_DO_PRIVILEGED);
  36. }
  37. private static final String _METHOD_NAME_DO_PRIVILEGED = "doPrivileged";
  38. }