Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java Security  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 在web上jaas的声明性授权,出措???
neweagle



发贴: 0
积分: 0
于 2003-08-06 11:25 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jaas中授权问题??各位老大,现身拉
在web上做jaas的授权,可是老通不过,在命令下又可以,郁闷??
策略文件如下:
grant {
permission javax.security.auth.AuthPermission "createLoginContext";
permission javax.security.auth.AuthPermission "doAs";
permission javax.security.auth.AuthPermission "doAsPrivileged";
permission javax.security.auth.AuthPermission "modifyPrincipals";
permission javax.security.auth.AuthPermission "getSubject";
};
/**grant codebase "file:/D:/JBuilder8/myjbproject/JaasDemo805/classes/jaas/JaasDemo.jar"**/
grant Principal jaas.PrincipalImpl "Brad" {
permission jaas.PersonnelPermission "access";
};

主要用到类:
package jaas;

import java.security.*;
import javax.security.auth.*;
import javax.security.auth.callback.*;
import javax.security.auth.login.*;
//
// This is the main program in the JAAS Example. It creates a Login Context,
// logs the user in based on the settings in the Login Configuration file,
// and calls two sensitive pieces of code, the first using programmatic
// authorization, and the second using declaritive authorization.
public class JAASExample {

static LoginContext lc = null;

public static void main( String[] args) {
//
// Create a login context
try {
lc = new LoginContext("JAASExample",
new UsernamePasswordCallbackHandler());
} catch (LoginException le) {
System.out.println( "Login Context Creation Error" );
System.exit(1);
}
//
// Login
try {
lc.login();
} catch (LoginException le) {
System.out.println( "\nOVERALL AUTHENTICATION FAILED\n" );
System.exit(1);
}
System.out.println( "\nOVERALL AUTHENTICATION SUCCEEDED\n" );
System.out.println( lc.getSubject() );
//
// Call the sensitive PayrollAction code, which uses programmatic
// authorization.
try {
Subject.doAs( lc.getSubject(), new PayrollAction() );
} catch (AccessControlException e) {
System.out.println( "Payroll Access DENIED" );
}
//
// Call the sensitive PersonnelAction code, which uses declarative
// authorization.
try {
System.out.println("start here");
Subject.doAsPrivileged( lc.getSubject(), new PersonnelAction(), null );

} catch (AccessControlException e) {
System.out.println( "Personnel Access DENIED" );
}
try {
lc.logout();
} catch (LoginException le) {
System.out.println( "Logout FAILED" );
System.exit(1);
}
System.exit(0);
}
}
×××××××××××××××PersonnelAction.java
package jaas;

import java.io.*;
import java.security.*;
//
// This class is a sensitive Personnel function that demonstrates
// the use of declarative authorization using the user defined
// permission PersonnelPermission, which throws an exception
// if it not granted
public class PersonnelAction implements PrivilegedAction {
public Object run() {

try{
AccessController.checkPermission(new PersonnelPermission("access"));
System.out.println( "Subject has Personnel access\n");
}catch(Exception e){
System.out.println("error:" +e.getMessage());
}

return new Integer(0);
}
}
××××××××××××PersonnelPermission.java
package jaas;

import java.security.*;
//
// Implement a user defined permission for access to the personnel
// code for this example
public class PersonnelPermission extends BasicPermission {

public PersonnelPermission(String name) {
super(name);
}

public PersonnelPermission(String name, String action) {
super(name);
}
}

系统报错为:
error:access denied (jaas.PersonnelPermission access)

请指教阿,各位老大???????




话题树型展开
人气 标题 作者 字数 发贴时间
13908 在web上jaas的声明性授权,出措??? neweagle 3615 2003-08-06 11:25
12069 Re:在web上jaas的声明性授权,出措??? menzy 29 2003-08-06 16:02
11771 Re:在web上jaas的声明性授权,出措??? neweagle 198 2003-09-01 21:18
14337 Re:在web上jaas的声明性授权,出措??? jeez 181 2003-09-02 10:44
11761 Re:在web上jaas的声明性授权,出措??? neweagle 1209 2003-08-06 16:12
11841 Re:在web上jaas的声明性授权,出措??? jprobe 110 2003-08-27 18:49
12302 Re:在web上jaas的声明性授权,出措??? jsmile 754 2003-08-27 22:26
12289 Re:在web上jaas的声明性授权,出措??? richardluopeng 34 2003-08-28 19:50
11772 Re:在web上jaas的声明性授权,出措??? floater 75 2003-08-29 11:41
12508 Re:在web上jaas的声明性授权,出措??? jsmile 1023 2003-08-29 22:30
11694 Re:在web上jaas的声明性授权,出措??? jeez 53 2003-09-01 17:36
11886 Re:在web上jaas的声明性授权,出措??? BlurEyes 259 2003-09-01 20:48

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923