VMAccessControlState.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* VMAccessControlState.java -- per-thread state for the access controller.
  2. Copyright (C) 2006 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING. If not, write to the
  13. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  14. 02110-1301 USA.
  15. Linking this library statically or dynamically with other modules is
  16. making a combined work based on this library. Thus, the terms and
  17. conditions of the GNU General Public License cover the whole
  18. combination.
  19. As a special exception, the copyright holders of this library give you
  20. permission to link this library with independent modules to produce an
  21. executable, regardless of the license terms of these independent
  22. modules, and to copy and distribute the resulting executable under
  23. terms of your choice, provided that you also meet, for each linked
  24. independent module, the terms and conditions of the license of that
  25. module. An independent module is a module which is not derived from
  26. or based on this library. If you modify this library, you may extend
  27. this exception to your version of the library, but you are not
  28. obligated to do so. If you do not wish to do so, delete this
  29. exception statement from your version. */
  30. package java.security;
  31. import java.util.LinkedList;
  32. class VMAccessControlState
  33. {
  34. /**
  35. * A list of {@link AccessControlContext} objects (which can be
  36. * null) for each call to {@link AccessController#doPrivileged()} in
  37. * the thread's call stack.
  38. */
  39. private LinkedList contexts = new LinkedList();
  40. /**
  41. * A flag indicating that we are within a call to {@link
  42. * VMAccessController#getContext()}.
  43. */
  44. private boolean inGetContext = false;
  45. /**
  46. * Not directly instantiable: use getThreadState() instead.
  47. */
  48. private VMAccessControlState() {}
  49. /**
  50. * Return an object representing the access control state of this
  51. * thread.
  52. *
  53. * @return The access control state of this thread, or
  54. * <code>null</code> if the VM is not initialized to the point of
  55. * being able to return this.
  56. */
  57. static native VMAccessControlState getThreadState();
  58. /**
  59. * Indicate whether this thread is within a call to {@link
  60. * VMAccessController#getContext()}.
  61. *
  62. * @return <code>true</code> if this thread is within a call to
  63. * {@link VMAccessController#getContext()}.
  64. */
  65. boolean isInGetContext()
  66. {
  67. return inGetContext;
  68. }
  69. /**
  70. * Specify whether this thread is within a call to {@link
  71. * VMAccessController#getContext()}.
  72. */
  73. void setInGetContext(boolean inGetContext)
  74. {
  75. this.inGetContext = inGetContext;
  76. }
  77. /**
  78. * Return a list of {@link AccessControlContext} objects (which can
  79. * be null) for each call to {@link AccessController#doPrivileged()}
  80. * in the thread's call stack.
  81. *
  82. * @return a list of {@link AccessControlContext} objects.
  83. */
  84. LinkedList getContexts()
  85. {
  86. return contexts;
  87. }
  88. }