KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > SecurePermissionStorage


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.osgi.framework.internal.core;
13
14 import java.io.IOException JavaDoc;
15 import java.security.*;
16 import org.eclipse.osgi.framework.adaptor.PermissionStorage;
17
18 /**
19  * PermissionStorage privileged action class.
20  */

21
22 public class SecurePermissionStorage implements PermissionStorage, PrivilegedExceptionAction {
23     private PermissionStorage storage;
24     private String JavaDoc location;
25     private String JavaDoc[] data;
26     private String JavaDoc[] infos;
27     private int action;
28     private static final int GET = 1;
29     private static final int SET = 2;
30     private static final int LOCATION = 3;
31     private static final int GET_INFOS = 4;
32     private static final int SAVE_INFOS = 5;
33
34     public SecurePermissionStorage(PermissionStorage storage) {
35         this.storage = storage;
36     }
37
38     public Object JavaDoc run() throws IOException JavaDoc {
39         switch (action) {
40             case GET :
41                 return storage.getPermissionData(location);
42             case SET :
43                 storage.setPermissionData(location, data);
44                 return null;
45             case LOCATION :
46                 return storage.getLocations();
47             case SAVE_INFOS :
48                 storage.saveConditionalPermissionInfos(infos);
49                 return null;
50             case GET_INFOS :
51                 return storage.getConditionalPermissionInfos();
52         }
53
54         throw new UnsupportedOperationException JavaDoc();
55     }
56
57     public String JavaDoc[] getPermissionData(String JavaDoc location) throws IOException JavaDoc {
58         this.location = location;
59         this.action = GET;
60
61         try {
62             return (String JavaDoc[]) AccessController.doPrivileged(this);
63         } catch (PrivilegedActionException e) {
64             throw (IOException JavaDoc) e.getException();
65         }
66     }
67
68     public String JavaDoc[] getLocations() throws IOException JavaDoc {
69         this.action = LOCATION;
70
71         try {
72             return (String JavaDoc[]) AccessController.doPrivileged(this);
73         } catch (PrivilegedActionException e) {
74             throw (IOException JavaDoc) e.getException();
75         }
76     }
77
78     public void setPermissionData(String JavaDoc location, String JavaDoc[] data) throws IOException JavaDoc {
79         this.location = location;
80         this.data = data;
81         this.action = SET;
82
83         try {
84             AccessController.doPrivileged(this);
85         } catch (PrivilegedActionException e) {
86             throw (IOException JavaDoc) e.getException();
87         }
88     }
89
90     public void saveConditionalPermissionInfos(String JavaDoc[] infos) throws IOException JavaDoc {
91         this.action = SAVE_INFOS;
92         this.infos = infos;
93         try {
94             AccessController.doPrivileged(this);
95         } catch (PrivilegedActionException e) {
96             throw (IOException JavaDoc) e.getException();
97         }
98
99     }
100
101     public String JavaDoc[] getConditionalPermissionInfos() throws IOException JavaDoc {
102         this.action = GET_INFOS;
103         try {
104             return (String JavaDoc[]) AccessController.doPrivileged(this);
105         } catch (PrivilegedActionException e) {
106             throw (IOException JavaDoc) e.getException();
107         }
108     }
109 }
110
Popular Tags