简体   繁体   English

如何在策略中授予用户权限?

[英]How to grant user permission in Policy?

I am able to connect to a LDAP server and authenticating an user. 我能够连接到LDAP服务器并验证用户身份。 I am also using a policy file that looks like this: 我还使用了一个如下所示的策略文件:

grant codeBase "file:/C:/Codebase/-",
 principal java.security.Principal "john" {
  permission java.util.PropertyPermission "user.home", "read";
  permission java.util.PropertyPermission "java.home", "read";
  permission javax.security.auth.AuthPermission "createLoginContext.TestLdap";
};

If I remove the line principal java.security.Principal "john" , it works fine. 如果删除行principal java.security.Principal "john" ,它将正常工作。 But when I specify the Principal, then it stops working by throwing an AccessControlException (even I logged as "john"). 但是,当我指定Principal时,它将通过抛出AccessControlException停止工作(即使我以“ john”身份登录)。 I want to grant some users specific privileges such as granting an administrator read and write on files. 我想授予某些用户特定的特权,例如授予管理员对文件的读写权限。 Why does not it work? 为什么不起作用?

I am trying not to use certificate because I do not want the user interact with anything. 我试图不使用证书,因为我不希望用户与任何事物进行交互。

I found that I was logging out in java code (forgot to remove that part of the test) before reading personal info. 我发现我在阅读个人信息之前正在以Java代码注销(忘记删除测试的那一部分)。 Also, there is another mistake in the code above. 另外,上面的代码还有另一个错误。 It should have been like this: 应该是这样的:

grant codeBase "file:/C:/Codebase/-" {
   permission javax.security.auth.AuthPermission "doAsPrivileged";
   permission javax.security.auth.AuthPermission "createLoginContext.TestLdap";
};

grant codeBase "file:/C:/Deveop/Codebase2/-", 
principal com.sun.security.auth.UserPrincipal "john" {
  permission java.util.PropertyPermission "user.home", "read";
  permission java.util.PropertyPermission "java.home", "read";

};

Also, make sure you call Subject.doAsPrivileged(Subject subject, PrivilegedAction<Object> action, null) and implement PrivilegedAction as your action class. 另外,请确保调用Subject.doAsPrivileged(Subject subject, PrivilegedAction<Object> action, null)并将PrivilegedAction实现为您的操作类。

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

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