001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.invocation;
023:
024: import java.security.PrivilegedAction;
025: import java.security.AccessController;
026:
027: /**
028: * Package privileged actions
029: *
030: * @author Scott.Stark@jboss.org
031: * @version $Revision: 57209 $
032: */
033: class SecurityActions {
034: interface TCLAction {
035: class UTIL {
036: static TCLAction getTCLAction() {
037: return System.getSecurityManager() == null ? NON_PRIVILEGED
038: : PRIVILEGED;
039: }
040:
041: static ClassLoader getContextClassLoader() {
042: return getTCLAction().getContextClassLoader();
043: }
044:
045: static ClassLoader getContextClassLoader(Thread thread) {
046: return getTCLAction().getContextClassLoader(thread);
047: }
048:
049: static void setContextClassLoader(ClassLoader cl) {
050: getTCLAction().setContextClassLoader(cl);
051: }
052:
053: static void setContextClassLoader(Thread thread,
054: ClassLoader cl) {
055: getTCLAction().setContextClassLoader(thread, cl);
056: }
057: }
058:
059: TCLAction NON_PRIVILEGED = new TCLAction() {
060: public ClassLoader getContextClassLoader() {
061: return Thread.currentThread().getContextClassLoader();
062: }
063:
064: public ClassLoader getContextClassLoader(Thread thread) {
065: return thread.getContextClassLoader();
066: }
067:
068: public void setContextClassLoader(ClassLoader cl) {
069: Thread.currentThread().setContextClassLoader(cl);
070: }
071:
072: public void setContextClassLoader(Thread thread,
073: ClassLoader cl) {
074: thread.setContextClassLoader(cl);
075: }
076: };
077:
078: TCLAction PRIVILEGED = new TCLAction() {
079: private final PrivilegedAction getTCLPrivilegedAction = new PrivilegedAction() {
080: public Object run() {
081: return Thread.currentThread()
082: .getContextClassLoader();
083: }
084: };
085:
086: public ClassLoader getContextClassLoader() {
087: return (ClassLoader) AccessController
088: .doPrivileged(getTCLPrivilegedAction);
089: }
090:
091: public ClassLoader getContextClassLoader(final Thread thread) {
092: return (ClassLoader) AccessController
093: .doPrivileged(new PrivilegedAction() {
094: public Object run() {
095: return thread.getContextClassLoader();
096: }
097: });
098: }
099:
100: public void setContextClassLoader(final ClassLoader cl) {
101: AccessController.doPrivileged(new PrivilegedAction() {
102: public Object run() {
103: Thread.currentThread()
104: .setContextClassLoader(cl);
105: return null;
106: }
107: });
108: }
109:
110: public void setContextClassLoader(final Thread thread,
111: final ClassLoader cl) {
112: AccessController.doPrivileged(new PrivilegedAction() {
113: public Object run() {
114: thread.setContextClassLoader(cl);
115: return null;
116: }
117: });
118: }
119: };
120:
121: ClassLoader getContextClassLoader();
122:
123: ClassLoader getContextClassLoader(Thread thread);
124:
125: void setContextClassLoader(ClassLoader cl);
126:
127: void setContextClassLoader(Thread thread, ClassLoader cl);
128: }
129:
130: static ClassLoader getContextClassLoader() {
131: return TCLAction.UTIL.getContextClassLoader();
132: }
133:
134: }
|