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

« back to all changes in this revision

Viewing changes to src/org/jboss/remoting/callback/CallbackStoreWrapper.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.callback;
24
 
 
25
 
import java.io.IOException;
26
 
import java.io.Serializable;
27
 
import java.security.AccessController;
28
 
import java.security.PrivilegedAction;
29
 
import java.security.PrivilegedActionException;
30
 
import java.security.PrivilegedExceptionAction;
31
 
import java.util.Map;
32
 
 
33
 
import org.jboss.remoting.SerializableStore;
34
 
import org.jboss.remoting.util.SecurityUtility;
35
 
 
36
 
/**
37
 
 * A CallbackStoreWrapper is used to wrap an MBean proxy that implements
38
 
 * org.jboss.remoting.SerializableStore.  If necessary, each call will go 
39
 
 * through an AccessController.doPrivileged() call.
40
 
 * 
41
 
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
42
 
 * @version $Revision: 1.1 $
43
 
 * <p>
44
 
 * Copyright May 5, 2008
45
 
 * </p>
46
 
 */
47
 
public class CallbackStoreWrapper implements SerializableStore
48
 
{
49
 
   private SerializableStore proxy;
50
 
 
51
 
 
52
 
   public CallbackStoreWrapper(SerializableStore proxy)
53
 
   {
54
 
      this.proxy = proxy;
55
 
   }
56
 
   
57
 
   public void add(final Serializable object) throws IOException
58
 
   {
59
 
      if (SecurityUtility.skipAccessControl())
60
 
      {
61
 
         proxy.add(object);
62
 
         return;
63
 
      }
64
 
      
65
 
      try
66
 
      {
67
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
68
 
         {
69
 
            public Object run() throws IOException
70
 
            {
71
 
               proxy.add(object);
72
 
               return null;
73
 
            }
74
 
         });
75
 
      }
76
 
      catch (PrivilegedActionException e)
77
 
      {
78
 
         throw (IOException) e.getCause();
79
 
      }
80
 
   }
81
 
 
82
 
   public void create() throws Exception
83
 
   {
84
 
      if (SecurityUtility.skipAccessControl())
85
 
      {
86
 
         proxy.create();
87
 
         return;
88
 
      }
89
 
      
90
 
      try
91
 
      {
92
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
93
 
         {
94
 
            public Object run() throws Exception
95
 
            {
96
 
               proxy.create();
97
 
               return null;
98
 
            }
99
 
         });
100
 
      }
101
 
      catch (PrivilegedActionException e)
102
 
      {
103
 
         throw (Exception) e.getCause();
104
 
      }
105
 
   }
106
 
 
107
 
   public void destroy()
108
 
   {
109
 
      if (SecurityUtility.skipAccessControl())
110
 
      {
111
 
          proxy.destroy();
112
 
          return;
113
 
      }
114
 
 
115
 
      AccessController.doPrivileged( new PrivilegedAction()
116
 
      {
117
 
         public Object run()
118
 
         {
119
 
            proxy.destroy();
120
 
            return null;
121
 
         }
122
 
      });
123
 
   }
124
 
 
125
 
   public Object getNext() throws IOException
126
 
   {
127
 
      if (SecurityUtility.skipAccessControl())
128
 
      {
129
 
         return proxy.getNext();
130
 
      }
131
 
      
132
 
      try
133
 
      {
134
 
         return AccessController.doPrivileged( new PrivilegedExceptionAction()
135
 
         {
136
 
            public Object run() throws IOException
137
 
            {
138
 
               return proxy.getNext();
139
 
            }
140
 
         });
141
 
      }
142
 
      catch (PrivilegedActionException e)
143
 
      {
144
 
         throw (IOException) e.getCause();
145
 
      }
146
 
   }
147
 
 
148
 
   public boolean getPurgeOnShutdown()
149
 
   {
150
 
      if (SecurityUtility.skipAccessControl())
151
 
      {
152
 
          return proxy.getPurgeOnShutdown();
153
 
      }
154
 
 
155
 
      return ((Boolean) AccessController.doPrivileged( new PrivilegedAction()
156
 
      {
157
 
         public Object run()
158
 
         {
159
 
            return new Boolean(proxy.getPurgeOnShutdown());
160
 
         }
161
 
      })).booleanValue();
162
 
   }
163
 
 
164
 
   public void purgeFiles()
165
 
   {
166
 
      if (SecurityUtility.skipAccessControl())
167
 
      {
168
 
          proxy.purgeFiles();
169
 
          return;
170
 
      }
171
 
 
172
 
      AccessController.doPrivileged( new PrivilegedAction()
173
 
      {
174
 
         public Object run()
175
 
         {
176
 
            proxy.purgeFiles();
177
 
            return null;
178
 
         }
179
 
      });
180
 
   }
181
 
 
182
 
   public void setConfig(final Map config)
183
 
   {
184
 
      if (SecurityUtility.skipAccessControl())
185
 
      {
186
 
          proxy.setConfig(config);
187
 
          return;
188
 
      }
189
 
 
190
 
      AccessController.doPrivileged( new PrivilegedAction()
191
 
      {
192
 
         public Object run()
193
 
         {
194
 
            proxy.setConfig(config);
195
 
            return null;
196
 
         }
197
 
      });
198
 
   }
199
 
 
200
 
   public void setPurgeOnShutdown(final boolean purgeOnShutdown)
201
 
   {
202
 
      if (SecurityUtility.skipAccessControl())
203
 
      {
204
 
          proxy.setPurgeOnShutdown(purgeOnShutdown);
205
 
          return;
206
 
      }
207
 
 
208
 
      AccessController.doPrivileged( new PrivilegedAction()
209
 
      {
210
 
         public Object run()
211
 
         {
212
 
            proxy.setPurgeOnShutdown(purgeOnShutdown);
213
 
            return null;
214
 
         }
215
 
      });
216
 
   }
217
 
 
218
 
   public int size()
219
 
   {
220
 
      if (SecurityUtility.skipAccessControl())
221
 
      {
222
 
          return proxy.size();
223
 
      }
224
 
 
225
 
      return ((Integer) AccessController.doPrivileged( new PrivilegedAction()
226
 
      {
227
 
         public Object run()
228
 
         {
229
 
            return new Integer(proxy.size());
230
 
         }
231
 
      })).intValue();
232
 
   }
233
 
 
234
 
   public void start() throws Exception
235
 
   {
236
 
      if (SecurityUtility.skipAccessControl())
237
 
      {
238
 
          proxy.start();
239
 
          return;
240
 
      }
241
 
 
242
 
      try
243
 
      {
244
 
         AccessController.doPrivileged( new PrivilegedExceptionAction()
245
 
         {
246
 
            public Object run() throws Exception
247
 
            {
248
 
               proxy.start();
249
 
               return null;
250
 
            }
251
 
         });
252
 
      }
253
 
      catch (PrivilegedActionException e)
254
 
      {
255
 
         throw (Exception) e.getCause();
256
 
      }
257
 
   }
258
 
 
259
 
   public void stop()
260
 
   {
261
 
      if (SecurityUtility.skipAccessControl())
262
 
      {
263
 
          proxy.stop();
264
 
          return;
265
 
      }
266
 
 
267
 
      AccessController.doPrivileged( new PrivilegedAction()
268
 
      {
269
 
         public Object run()
270
 
         {
271
 
            proxy.stop();
272
 
            return null;
273
 
         }
274
 
      });
275
 
   }
276
 
}
 
 
b'\\ No newline at end of file'