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

https://github.com/christine-huang/liferay-portal · Java · 48 lines · 19 code · 13 blank · 16 comment · 1 complexity · a989080d787f1501749ad097e67ab26f MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-2013 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.log.Log;
  16. import com.liferay.portal.kernel.log.LogFactoryUtil;
  17. import java.security.Permission;
  18. import sun.reflect.Reflection;
  19. /**
  20. * @author Brian Wing Shun Chan
  21. */
  22. public class ReflectChecker extends BaseChecker {
  23. public void afterPropertiesSet() {
  24. }
  25. public boolean implies(Permission permission) {
  26. int stackIndex = getStackIndex(10, 9);
  27. Class<?> callerClass = Reflection.getCallerClass(stackIndex);
  28. if (isTrustedCaller(callerClass, permission)) {
  29. return true;
  30. }
  31. logSecurityException(_log, "Attempted to reflect");
  32. return false;
  33. }
  34. private static Log _log = LogFactoryUtil.getLog(ReflectChecker.class);
  35. }