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

« back to all changes in this revision

Viewing changes to src/org/jboss/remoting/network/NetworkRegistryWrapper.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110909140103-o8ucrolqt5g25k57
Tags: upstream-2.5.3.SP1
ImportĀ upstreamĀ versionĀ 2.5.3.SP1

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.network;
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.ListenerNotFoundException;
31
 
import javax.management.MBeanNotificationInfo;
32
 
import javax.management.MBeanServer;
33
 
import javax.management.NotificationFilter;
34
 
import javax.management.NotificationListener;
35
 
import javax.management.ObjectName;
36
 
 
37
 
import org.jboss.remoting.detection.ServerInvokerMetadata;
38
 
import org.jboss.remoting.ident.Identity;
39
 
import org.jboss.remoting.util.SecurityUtility;
40
 
 
41
 
 
42
 
/**
43
 
 * A NetworkRegistryWrapper is used to wrap an MBean proxy that implements
44
 
 * org.jboss.remoting.network.NetworkRegistryWrapper.  If necessary, each call
45
 
 * will go  through an AccessController.doPrivileged() call.
46
 
 * 
47
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
48
 
 * @version $Revision: 1.1 $
49
 
 * <p>
50
 
 * Copyright May 6, 2008
51
 
 * </p>
52
 
 */
53
 
public class NetworkRegistryWrapper implements NetworkRegistryMBean
54
 
{
55
 
   private NetworkRegistryMBean proxy;
56
 
   
57
 
   public NetworkRegistryWrapper(NetworkRegistryMBean proxy)
58
 
   {
59
 
      this.proxy = proxy;
60
 
   }
61
 
   
62
 
   public void addServer(final Identity identity, final ServerInvokerMetadata[] invokers)
63
 
   {
64
 
      if (SecurityUtility.skipAccessControl())
65
 
      {
66
 
          proxy.addServer(identity, invokers);
67
 
          return;
68
 
      }
69
 
 
70
 
      AccessController.doPrivileged( new PrivilegedAction()
71
 
      {
72
 
         public Object run()
73
 
         {
74
 
            proxy.addServer(identity, invokers);
75
 
            return null;
76
 
         }
77
 
      });
78
 
   }
79
 
 
80
 
   public void changeDomain(final String newDomain)
81
 
   {
82
 
      if (SecurityUtility.skipAccessControl())
83
 
      {
84
 
          proxy.changeDomain(newDomain);
85
 
          return;
86
 
      }
87
 
 
88
 
      AccessController.doPrivileged( new PrivilegedAction()
89
 
      {
90
 
         public Object run()
91
 
         {
92
 
            proxy.changeDomain(newDomain);
93
 
            return null;
94
 
         }
95
 
      });
96
 
   }
97
 
   
98
 
   public NetworkInstance[] getServers()
99
 
   {
100
 
      if (SecurityUtility.skipAccessControl())
101
 
      {
102
 
          return proxy.getServers();
103
 
      }
104
 
 
105
 
      return (NetworkInstance[]) AccessController.doPrivileged( new PrivilegedAction()
106
 
      {
107
 
         public Object run()
108
 
         {
109
 
            return proxy.getServers();
110
 
         }
111
 
      });
112
 
   }
113
 
 
114
 
   public boolean hasServer(final Identity identity)
115
 
   {
116
 
      if (SecurityUtility.skipAccessControl())
117
 
      {
118
 
          return proxy.hasServer(identity);
119
 
      }
120
 
 
121
 
      return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
122
 
      {
123
 
         public Object run()
124
 
         {
125
 
            return new Boolean(proxy.hasServer(identity));
126
 
         }
127
 
      })).booleanValue();
128
 
   }
129
 
 
130
 
   public NetworkInstance[] queryServers(final NetworkFilter filter)
131
 
   {
132
 
      if (SecurityUtility.skipAccessControl())
133
 
      {
134
 
          return proxy.queryServers(filter);
135
 
      }
136
 
 
137
 
      return (NetworkInstance[]) AccessController.doPrivileged( new PrivilegedAction()
138
 
      {
139
 
         public Object run()
140
 
         {
141
 
            return proxy.queryServers(filter);
142
 
         }
143
 
      });
144
 
   }
145
 
 
146
 
   public void removeServer(final Identity identity)
147
 
   {
148
 
      if (SecurityUtility.skipAccessControl())
149
 
      {
150
 
          proxy.removeServer(identity);
151
 
          return;
152
 
      }
153
 
 
154
 
      AccessController.doPrivileged( new PrivilegedAction()
155
 
      {
156
 
         public Object run()
157
 
         {
158
 
            proxy.removeServer(identity);
159
 
            return null;
160
 
         }
161
 
      });
162
 
   }
163
 
 
164
 
   public void updateServer(final Identity identity, final ServerInvokerMetadata[] invokers)
165
 
   {
166
 
      if (SecurityUtility.skipAccessControl())
167
 
      {
168
 
          proxy.updateServer(identity, invokers);
169
 
          return;
170
 
      }
171
 
 
172
 
      AccessController.doPrivileged( new PrivilegedAction()
173
 
      {
174
 
         public Object run()
175
 
         {
176
 
            proxy.updateServer(identity, invokers);
177
 
            return null;
178
 
         }
179
 
      });
180
 
   }
181
 
   
182
 
   public void addNotificationListener(final NotificationListener listener,
183
 
                                       final NotificationFilter filter,
184
 
                                       final Object handback)
185
 
   throws IllegalArgumentException
186
 
   {
187
 
      if (SecurityUtility.skipAccessControl())
188
 
      {
189
 
          proxy.addNotificationListener(listener, filter, handback);
190
 
          return;
191
 
      }
192
 
 
193
 
      try
194
 
      {
195
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
196
 
         {
197
 
            public Object run() throws IllegalArgumentException
198
 
            {
199
 
               proxy.addNotificationListener(listener, filter, handback);
200
 
               return null;
201
 
            }
202
 
         });
203
 
      }
204
 
      catch (PrivilegedActionException e)
205
 
      {
206
 
         throw (IllegalArgumentException) e.getCause();
207
 
      }
208
 
   }
209
 
 
210
 
   public MBeanNotificationInfo[] getNotificationInfo()
211
 
   {
212
 
      if (SecurityUtility.skipAccessControl())
213
 
      {
214
 
          return proxy.getNotificationInfo();
215
 
      }
216
 
 
217
 
      return (MBeanNotificationInfo[]) AccessController.doPrivileged( new PrivilegedAction()
218
 
      {
219
 
         public Object run()
220
 
         {
221
 
            return proxy.getNotificationInfo();
222
 
         }
223
 
      });
224
 
   }
225
 
 
226
 
   public void removeNotificationListener(final NotificationListener listener)
227
 
   throws ListenerNotFoundException
228
 
   {
229
 
      if (SecurityUtility.skipAccessControl())
230
 
      {
231
 
          proxy.removeNotificationListener(listener);
232
 
          return;
233
 
      }
234
 
 
235
 
      try
236
 
      {
237
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
238
 
         {
239
 
            public Object run() throws ListenerNotFoundException
240
 
            {
241
 
               proxy.removeNotificationListener(listener);
242
 
               return null;
243
 
            }
244
 
         });
245
 
      }
246
 
      catch (PrivilegedActionException e)
247
 
      {
248
 
         throw (ListenerNotFoundException) e.getCause();
249
 
      }
250
 
   }
251
 
   
252
 
   public void postDeregister()
253
 
   {
254
 
      if (SecurityUtility.skipAccessControl())
255
 
      {
256
 
          proxy.postDeregister();
257
 
          return;
258
 
      }
259
 
 
260
 
      AccessController.doPrivileged( new PrivilegedAction()
261
 
      {
262
 
         public Object run()
263
 
         {
264
 
            proxy.postDeregister();
265
 
            return null;
266
 
         }
267
 
      });
268
 
   }
269
 
 
270
 
   public void postRegister(final Boolean registrationDone)
271
 
   {
272
 
      if (SecurityUtility.skipAccessControl())
273
 
      {
274
 
          proxy.postRegister(registrationDone);
275
 
          return;
276
 
      }
277
 
 
278
 
      AccessController.doPrivileged( new PrivilegedAction()
279
 
      {
280
 
         public Object run()
281
 
         {
282
 
            proxy.postRegister(registrationDone);
283
 
            return null;
284
 
         }
285
 
      });
286
 
   }
287
 
 
288
 
   public void preDeregister() throws Exception
289
 
   {
290
 
      if (SecurityUtility.skipAccessControl())
291
 
      {
292
 
          proxy.preDeregister();
293
 
          return;
294
 
      }
295
 
 
296
 
      try
297
 
      {
298
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
299
 
         {
300
 
            public Object run() throws Exception
301
 
            {
302
 
               proxy.preDeregister();
303
 
               return null;
304
 
            }
305
 
         });
306
 
      }
307
 
      catch (PrivilegedActionException e)
308
 
      {
309
 
         throw (Exception) e.getCause();
310
 
      }
311
 
   }
312
 
 
313
 
   public ObjectName preRegister(final MBeanServer server, final ObjectName name)
314
 
   throws Exception
315
 
   {
316
 
      if (SecurityUtility.skipAccessControl())
317
 
      {
318
 
          return proxy.preRegister(server, name);
319
 
      }
320
 
 
321
 
      try
322
 
      {
323
 
         return (ObjectName) AccessController.doPrivileged( new PrivilegedExceptionAction()
324
 
         {
325
 
            public Object run() throws Exception
326
 
            {
327
 
               return proxy.preRegister(server, name);
328
 
            }
329
 
         });
330
 
      }
331
 
      catch (PrivilegedActionException e)
332
 
      {
333
 
         throw (Exception) e.getCause();
334
 
      }
335
 
   }
336
 
}
 
 
b'\\ No newline at end of file'