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

https://github.com/christine-huang/liferay-portal · Java · 86 lines · 48 code · 22 blank · 16 comment · 8 complexity · ddf7f644f2d1ac3295edf095cca3f887 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 NetChecker extends BaseChecker {
  23. public void afterPropertiesSet() {
  24. }
  25. public boolean implies(Permission permission) {
  26. String name = permission.getName();
  27. if (name.equals(NET_PERMISSION_GET_PROXY_SELECTOR)) {
  28. if (!hasGetProxySelector(permission)) {
  29. logSecurityException(_log, "Attempted to get proxy selector");
  30. return false;
  31. }
  32. }
  33. else if (name.equals(NET_PERMISSION_SPECIFY_STREAM_HANDLER)) {
  34. if (!hasSpecifyStreamHandler(permission)) {
  35. logSecurityException(
  36. _log, "Attempted to specify stream handler");
  37. return false;
  38. }
  39. }
  40. else {
  41. logSecurityException(
  42. _log, "Attempted " + name + " network operation");
  43. return false;
  44. }
  45. return true;
  46. }
  47. protected boolean hasGetProxySelector(Permission permission) {
  48. int stackIndex = getStackIndex(11, 10);
  49. Class<?> callerClass = Reflection.getCallerClass(stackIndex);
  50. if (isTrustedCaller(callerClass, permission)) {
  51. return true;
  52. }
  53. return false;
  54. }
  55. protected boolean hasSpecifyStreamHandler(Permission permission) {
  56. int stackIndex = getStackIndex(11, 10);
  57. Class<?> callerClass = Reflection.getCallerClass(stackIndex);
  58. if (isTrustedCaller(callerClass, permission)) {
  59. return true;
  60. }
  61. return false;
  62. }
  63. private static Log _log = LogFactoryUtil.getLog(NetChecker.class);
  64. }