~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to src/main/org/jboss/remoting/ServerInvocationHandlerWrapper.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
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.
 
7
*
 
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.
 
12
*
 
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.
 
17
*
 
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.
 
22
*/
 
23
package org.jboss.remoting;
 
24
 
 
25
import java.security.AccessController;
 
26
import java.security.PrivilegedAction;
 
27
import java.security.PrivilegedActionException;
 
28
import java.security.PrivilegedExceptionAction;
 
29
 
 
30
import javax.management.MBeanServer;
 
31
 
 
32
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
33
import org.jboss.remoting.util.SecurityUtility;
 
34
 
 
35
/**
 
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.
 
39
 * 
 
40
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
41
 * @version $Revision: 1.1 $
 
42
 * <p>
 
43
 * Copyright May 4, 2008
 
44
 * </p>
 
45
 */
 
46
public class ServerInvocationHandlerWrapper implements ServerInvocationHandler
 
47
{
 
48
   private ServerInvocationHandler proxy;
 
49
   
 
50
   public ServerInvocationHandlerWrapper(ServerInvocationHandler proxy)
 
51
   {
 
52
      this.proxy = proxy;
 
53
   }
 
54
   
 
55
   public void addListener(final InvokerCallbackHandler callbackHandler)
 
56
   {
 
57
      if (SecurityUtility.skipAccessControl())
 
58
      {
 
59
         proxy.addListener(callbackHandler);
 
60
         return;
 
61
      }
 
62
 
 
63
      AccessController.doPrivileged( new PrivilegedAction()
 
64
      {
 
65
         public Object run()
 
66
         {
 
67
            proxy.addListener(callbackHandler);
 
68
            return null;
 
69
         }
 
70
      });
 
71
   }
 
72
 
 
73
   public Object invoke(final InvocationRequest invocation) throws Throwable
 
74
   {
 
75
      if (SecurityUtility.skipAccessControl())
 
76
      {
 
77
         return proxy.invoke(invocation);
 
78
      }
 
79
 
 
80
      try
 
81
      {
 
82
         return AccessController.doPrivileged( new PrivilegedExceptionAction()
 
83
         {
 
84
            public Object run() throws Exception
 
85
            {
 
86
               try
 
87
               {
 
88
                  return proxy.invoke(invocation);
 
89
               }
 
90
               catch (Throwable t)
 
91
               {
 
92
                  throw new Exception(t);
 
93
               }
 
94
            }
 
95
         });
 
96
      }
 
97
      catch (PrivilegedActionException e)
 
98
      {
 
99
         Throwable cause = e.getCause();
 
100
         if (cause.getCause() == null)
 
101
            throw cause;
 
102
         else
 
103
            throw cause.getCause();
 
104
      }
 
105
   }
 
106
 
 
107
   public void removeListener(final InvokerCallbackHandler callbackHandler)
 
108
   {
 
109
      if (SecurityUtility.skipAccessControl())
 
110
      {
 
111
         proxy.removeListener(callbackHandler);
 
112
         return;
 
113
      }
 
114
 
 
115
      AccessController.doPrivileged( new PrivilegedAction()
 
116
      {
 
117
         public Object run()
 
118
         {
 
119
            proxy.removeListener(callbackHandler);
 
120
            return null;
 
121
         }
 
122
      });
 
123
   }
 
124
 
 
125
   public void setInvoker(final ServerInvoker invoker)
 
126
   {
 
127
      if (SecurityUtility.skipAccessControl())
 
128
      {
 
129
         proxy.setInvoker(invoker);
 
130
         return;
 
131
      }
 
132
 
 
133
      AccessController.doPrivileged( new PrivilegedAction()
 
134
      {
 
135
         public Object run()
 
136
         {
 
137
            proxy.setInvoker(invoker);
 
138
            return null;
 
139
         }
 
140
      });
 
141
   }
 
142
 
 
143
   public void setMBeanServer(final MBeanServer server)
 
144
   {
 
145
      if (SecurityUtility.skipAccessControl())
 
146
      {
 
147
         proxy.setMBeanServer(server);
 
148
         return;
 
149
      }
 
150
 
 
151
      AccessController.doPrivileged( new PrivilegedAction()
 
152
      {
 
153
         public Object run()
 
154
         {
 
155
            proxy.setMBeanServer(server);
 
156
            return null;
 
157
         }
 
158
      });
 
159
   }
 
160
}
 
 
b'\\ No newline at end of file'