如何授予小程序访问其所需资源的权限?

发布于 2024-08-04 03:41:30 字数 312 浏览 3 评论 0原文

我在为我的小程序定义权限时遇到问题,该权限将访问空间资源,例如获取 user.name 属性或文件系统命令,例如创建、读取、写入目录或文件...

小程序必须写入任何数据 -ex。图像-从临时目录中的此类文件中的网络应用程序接收到的图像,并使用 user.name 为这些文件创建一个文件夹...

我想签署小程序并为其授予权限,以便每个运行我的小程序的客户端都允许它访问资源需要访问权限,我该怎么做? 是否可以?

这是一种没有客户端授予权限的方法吗? 我知道这不是好的安全策略,而且可能是不正确的想法,但是根据我的问题陈述,您的想法是什么? 我怎样才能做到这一点?

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...

the applet must write any data -ex. images- that received from a web application in such files in temp directory with using user.name to make a folder to these...

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?
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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬心 2024-08-11 03:41:30

一旦您的小程序被签名,任何需要文件权限的代码都需要包装在特权块中,如下所示。

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;
}
});

为了获取系统属性,您需要再次使用特权块。像这样的东西。

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;
    }
}
});

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;
    }
}
});
悲喜皆因你 2024-08-11 03:41:30

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

From 6u10, without being signed you can use FileSaveService to allow files to be saved under control of the user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文