3
* JBoss, Home of Professional Open Source
4
* Copyright 2005, JBoss Inc., and individual contributors as indicated
5
* by the @authors tag. See the copyright.txt in the distribution for a
6
* full listing of individual contributors.
8
* This is free software; you can redistribute it and/or modify it
9
* under the terms of the GNU Lesser General Public License as
10
* published by the Free Software Foundation; either version 2.1 of
11
* the License, or (at your option) any later version.
13
* This software is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this software; if not, write to the Free
20
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.remoting;
25
import java.security.AccessController;
26
import java.security.PrivilegedAction;
27
import java.security.PrivilegedActionException;
28
import java.security.PrivilegedExceptionAction;
30
import javax.management.MBeanServer;
32
import org.jboss.remoting.callback.InvokerCallbackHandler;
33
import org.jboss.remoting.util.SecurityUtility;
36
* A ServerInvocationHandlerWrapper is used to wrap an MBean proxy that implements
37
* org.jboss.remoting.ServerInvocationHandler. If necessary, each call will go
38
* through an AccessController.doPrivileged() call.
40
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
41
* @version $Revision: 1.1 $
43
* Copyright May 4, 2008
46
public class ServerInvocationHandlerWrapper implements ServerInvocationHandler
48
private ServerInvocationHandler proxy;
50
public ServerInvocationHandlerWrapper(ServerInvocationHandler proxy)
55
public void addListener(final InvokerCallbackHandler callbackHandler)
57
if (SecurityUtility.skipAccessControl())
59
proxy.addListener(callbackHandler);
63
AccessController.doPrivileged( new PrivilegedAction()
67
proxy.addListener(callbackHandler);
73
public Object invoke(final InvocationRequest invocation) throws Throwable
75
if (SecurityUtility.skipAccessControl())
77
return proxy.invoke(invocation);
82
return AccessController.doPrivileged( new PrivilegedExceptionAction()
84
public Object run() throws Exception
88
return proxy.invoke(invocation);
92
throw new Exception(t);
97
catch (PrivilegedActionException e)
99
Throwable cause = e.getCause();
100
if (cause.getCause() == null)
103
throw cause.getCause();
107
public void removeListener(final InvokerCallbackHandler callbackHandler)
109
if (SecurityUtility.skipAccessControl())
111
proxy.removeListener(callbackHandler);
115
AccessController.doPrivileged( new PrivilegedAction()
119
proxy.removeListener(callbackHandler);
125
public void setInvoker(final ServerInvoker invoker)
127
if (SecurityUtility.skipAccessControl())
129
proxy.setInvoker(invoker);
133
AccessController.doPrivileged( new PrivilegedAction()
137
proxy.setInvoker(invoker);
143
public void setMBeanServer(final MBeanServer server)
145
if (SecurityUtility.skipAccessControl())
147
proxy.setMBeanServer(server);
151
AccessController.doPrivileged( new PrivilegedAction()
155
proxy.setMBeanServer(server);
b'\\ No newline at end of file'