/modules/core/portal-security-pacl/src/main/java/com/liferay/portal/security/pacl/checker/NetChecker.java

http://github.com/liferay/liferay-portal · Java · 87 lines · 50 code · 21 blank · 16 comment · 8 complexity · b8b292a493e612207dd4928d577dfd4b MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present 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 com.liferay.portal.security.pacl.Reflection;
  18. import java.security.Permission;
  19. /**
  20. * @author Brian Wing Shun Chan
  21. */
  22. public class NetChecker extends BaseChecker {
  23. @Override
  24. public void afterPropertiesSet() {
  25. }
  26. @Override
  27. public boolean implies(Permission permission) {
  28. String name = permission.getName();
  29. if (name.equals(NET_PERMISSION_GET_PROXY_SELECTOR)) {
  30. if (!hasGetProxySelector(permission)) {
  31. logSecurityException(_log, "Attempted to get proxy selector");
  32. return false;
  33. }
  34. }
  35. else if (name.equals(NET_PERMISSION_SPECIFY_STREAM_HANDLER)) {
  36. if (!hasSpecifyStreamHandler(permission)) {
  37. logSecurityException(
  38. _log, "Attempted to specify stream handler");
  39. return false;
  40. }
  41. }
  42. else {
  43. logSecurityException(
  44. _log, "Attempted " + name + " network operation");
  45. return false;
  46. }
  47. return true;
  48. }
  49. protected boolean hasGetProxySelector(Permission permission) {
  50. int stackIndex = Reflection.getStackIndex(4, 3);
  51. Class<?> callerClass = Reflection.getCallerClass(stackIndex);
  52. if (isTrustedCaller(callerClass, permission)) {
  53. return true;
  54. }
  55. return false;
  56. }
  57. protected boolean hasSpecifyStreamHandler(Permission permission) {
  58. int stackIndex = Reflection.getStackIndex(4, 3);
  59. Class<?> callerClass = Reflection.getCallerClass(stackIndex);
  60. if (isTrustedCaller(callerClass, permission)) {
  61. return true;
  62. }
  63. return false;
  64. }
  65. private static final Log _log = LogFactoryUtil.getLog(NetChecker.class);
  66. }