~ubuntu-branches/ubuntu/natty/icedtea-web/natty-proposed

« back to all changes in this revision

Viewing changes to netx/net/sourceforge/jnlp/services/ServiceUtil.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-11-24 13:23:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101124132328-2xb9z39vxga63vr9
Tags: 1.0~20101124-0ubuntu1
* Update to hg 20101124.
* Fix xulrunner dependencies for natty.
* Build-depend on pkg-config and libgtk2.0-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
import net.sourceforge.jnlp.JNLPFile;
41
41
import net.sourceforge.jnlp.runtime.ApplicationInstance;
 
42
import net.sourceforge.jnlp.runtime.DeploymentConfiguration;
42
43
import net.sourceforge.jnlp.runtime.JNLPRuntime;
43
 
import net.sourceforge.jnlp.security.SecurityWarningDialog;
 
44
import net.sourceforge.jnlp.security.SecurityWarning;
 
45
import net.sourceforge.jnlp.security.SecurityWarning.AccessType;
44
46
 
45
47
/**
46
48
 * Provides static methods to interact useful for using the JNLP
52
54
 */
53
55
public class ServiceUtil {
54
56
 
55
 
    private static String R(String key) {
56
 
        return JNLPRuntime.getMessage(key);
57
 
    }
58
 
 
59
57
    /**
60
58
     * Returns the BasicService reference, or null if the service is
61
59
     * unavailable.
182
180
                        System.err.println("           arg: "+args[i]);
183
181
            }
184
182
 
185
 
            PrivilegedExceptionAction invoker = new PrivilegedExceptionAction() {
 
183
            PrivilegedExceptionAction<Object> invoker = new PrivilegedExceptionAction<Object>() {
186
184
                public Object run() throws Exception {
187
185
                    return method.invoke(receiver, args);
188
186
                }
211
209
    };
212
210
 
213
211
    /**
214
 
     * Returns whether the app requesting a service is signed. If the app is
215
 
     * unsigned, the user is prompted with a dialog asking if the action
216
 
     * should be allowed.
 
212
     * Returns whether the app requesting a JNLP service has the right permissions.
 
213
     * If it doesn't, user is prompted for permissions. This method should only be
 
214
     * used for JNLP API related permissions.
 
215
     *
217
216
     * @param type the type of access being requested
218
217
     * @param extras extra Strings (usually) that are passed to the dialog for
219
218
     * message formatting.
220
219
     * @return true if the access was granted, false otherwise.
221
220
     */
222
 
    public static boolean checkAccess(SecurityWarningDialog.AccessType type,
223
 
            Object... extras) {
 
221
    public static boolean checkAccess(AccessType type, Object... extras) {
224
222
        return checkAccess(null, type, extras);
225
223
    }
226
224
 
227
225
    /**
228
 
     * Returns whether the app requesting a service has the right permissions.
229
 
     * If it doesn't, user is prompted for permissions.
 
226
     * Returns whether the app requesting a JNLP service has the right permissions.
 
227
     * If it doesn't, user is prompted for permissions. This method should only be
 
228
     * used for JNLP API related permissions.
230
229
     *
231
230
     * @param app the application which is requesting the check. If null, the current
232
231
     * application is used.
235
234
     * message formatting.
236
235
     * @return true if the access was granted, false otherwise.
237
236
     */
238
 
    public static boolean checkAccess(ApplicationInstance app,
239
 
            SecurityWarningDialog.AccessType type,
 
237
    public static boolean checkAccess(ApplicationInstance app, AccessType type,
240
238
                Object... extras) {
241
239
 
242
240
        if (app == null)
270
268
        }
271
269
 
272
270
        if (!codeTrusted) {
273
 
                final SecurityWarningDialog.AccessType tmpType = type;
 
271
 
 
272
                if (!shouldPromptUser()) {
 
273
                    return false;
 
274
                }
 
275
 
 
276
                final AccessType tmpType = type;
274
277
                final Object[] tmpExtras = extras;
275
278
                final ApplicationInstance tmpApp = app;
276
279
 
279
282
                //from resources.jar.
280
283
                Boolean b = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
281
284
                    public Boolean run() {
282
 
                        boolean b = SecurityWarningDialog.showAccessWarningDialog(tmpType,
 
285
                        boolean b = SecurityWarning.showAccessWarningDialog(tmpType,
283
286
                                tmpApp.getJNLPFile(), tmpExtras);
284
287
                        return new Boolean(b);
285
288
                    }
290
293
 
291
294
        return true; //allow
292
295
    }
 
296
 
 
297
    /**
 
298
     * Returns whether the current runtime configuration allows prompting the
 
299
     * user for JNLP permissions.
 
300
     *
 
301
     * @return true if the user should be prompted for JNLP API related permissions.
 
302
     */
 
303
    private static boolean shouldPromptUser() {
 
304
        return Boolean.valueOf(JNLPRuntime.getConfiguration()
 
305
                .getProperty(DeploymentConfiguration.KEY_SECURITY_PROMPT_USER_FOR_JNLP));
 
306
    }
 
307
 
293
308
}