简体   繁体   English

如何授予applet权限以访问所需的资源?

[英]how to grant an applet permission for the resource accesses it needs?

i have a problem with define permission for my applet that would to spacial resource access like get user.name property or file system command like create,read, write directory or files... 我对我的applet定义权限存在问题,该权限将用于空间资源访问,例如get user.name属性或文件系统命令,例如创建,读取,写入目录或文件...

the applet must write any data -ex. 小程序必须写入任何数据-ex。 images- that received from a web application in such files in temp directory with using user.name to make a folder to these... 图像-从Web应用程序收到的临时目录中此类文件中的文件,使用user.name来为这些文件创建文件夹

i want to sign applet and grant permission for it so that every client which runs my applet permission it to resource access that is needed, how i can do it? 我想签署applet并为其授予权限,以便每个运行我applet的客户端都可以对其进行所需的资源访问,我该怎么做? is it possible? 可能吗?

is it a method without client side grant permission? 这是没有客户端授予权限的方法吗? i know that's not good security policy and maybe incorrect idea , but with my problem statement what's your idea? 我知道这不是一个好的安全策略,也许是错误的主意,但是根据我的问题陈述,您的主意是什么? how i can do this? 我该怎么做?

Once your applet is signed, any code that needs file permissions needs to be wrapped in a privileged block as follows. 对小程序进行签名后,需要文件权限的所有代码都必须包装在特权块中,如下所示。

final String location = locationVal;

File f = (File) AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
  System.out.println("Getting File : " + location);
  File outputFile1 = new File(location);
  return outputFile1;
}
});

For getting a system property you need to use the privileged block again. 为了获得系统属性,您需要再次使用特权块。 Something like this. 这样的事情。

String javaVersion = (String) AccessController.doPrivileged(new PrivilegedAction()
{
    public Object run()
    {
        try
        {
            return System.getProperty("java.version");
        } 
        catch (Exception e)
        {
        System.out.println("Exception caught:" + e.toString());
    return null;
    }
}
});

从6u10开始,无需签名即可使用FileSaveService允许在用户控制下保存文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM