# About doPrivileged() method.

Chosho Kyo - Nihon Sun JCTC (Chosho.Kyo@japan.sun.com)
Fri, 19 Mar 1999 16:30:55 +0900 (JST)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Jan Luehe: "Re: About doPrivileged() method."
- Previous message: Sohan Mendis: "Applet Security ?"
- Next in thread: Jan Luehe: "Re: About doPrivileged() method."

    Message-Id: <199903190730.QAA06158@speed.Japan.Sun.COM>

    Date: Fri, 19 Mar 1999 16:30:55 +0900 (JST)

    From: Chosho Kyo - Nihon Sun JCTC <Chosho.Kyo@japan.sun.com>

    Subject: About doPrivileged() method.

    To: java-security@java.sun.com

Hi,

I wrote a source GetProperty.java to test doPrivileged() method
according to the explanation of access control mechanisms on the web.

But when I run it with the following command,
java -Djava.security.manager GetProperty

I got the exception message like that:
"Exception in thread "main" java.security.AccessControlException:
access denied (java.util.PropertyPermission user.home read)
........".

In my understanding, GetProperty.java needs not the .java.policy file
to grant {java.util.PropertyPermission "user.home", "read"}.

Is my understanding wrong?
Could you please give me any hint or tell me how to get
a completed source sample which uses the doPrivileged() method?

Regards.

//--------------GetProperty.java start--------------------
import java.security.*;
import java.net.*;
import java.io.*;
import java.util.*;

public class GetProperty {
AccessControlContext getAccessControlContext(){
PermissionCollection perms = new Permissions();
perms.add(new AllPermission());
ProtectionDomain domain = new ProtectionDomain(new CodeSource(null,
null), perms);
AccessControlContext acc = new AccessControlContext(new
ProtectionDomain[] {domain});
return acc;
}
void go(){
AccessControlContext acc = getAccessControlContext();
System.out.println(acc.toString());
AccessController.doPrivileged( new PrivilegedAction(){
public Object run(){
System.out.println(System.getProperty("user.home"));
return null;
}
}, acc);
}
public static void main(String a[]) throws Throwable{
new GetProperty().go();
}
}

//--------------GetProperty.java End--------------------

Chosho Kyo
Nihon Sun Microsystems K.K.
SBS Tower, 4-10-1 Yoga, Setagaya-ku
Tokyo, 158 Japan
Tel:03-5717-5041
Fax:03-5717-2582
chosho.kyo@Japan.Sun.COM

- Next message: Jan Luehe: "Re: About doPrivileged() method."
- Previous message: Sohan Mendis: "Applet Security ?"
- Next in thread: Jan Luehe: "Re: About doPrivileged() method."