Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / August 2005

Tip: Looking for answers? Try searching our database.

applet -- new to security issues...

Thread view: 
Frances - 24 Aug 2005 20:11 GMT
nothing has ever frustrated me more than trying to connect to a server
(in this case a jabber server..)  with an applet.. I'm importing smack
package to write an applet client (http://www.jivesoftware.org/smack/,
http://www.jivesoftware.org/builds/smack/docs/latest/javadoc/)

just to test I wrote a jsp, can connect to jabber.org server fine
w/jsp.. but with an applet it's been like pulling teeth, I swear...  we
signed all three smack jars, but still can't connect to server..  (get
SocketPermission error..)

so someone told me I need to put some code in applet from here..

http://java.sun.com/j2se/1.5.0/docs/api/java/security/AccessController.html

does this sound about right?

SocketPermission perm = new SocketPermission("jabber.org:5222", "connect");
    AccessController.checkPermission(perm);

can't even figure out if this is right b/c, even though I'm importing
java.net.* (and java.security.*), I get a can't-find-symbol error on var
'perm'...

would appreciate some help here..  thank you very much..
Joel Kamentz - 29 Aug 2005 15:33 GMT
Applets normally have few privileges and cannot connect to machines other
than the one which they came from.

Even if you sign your applet code to grant it privileges, it doesn't mean
that all operations should necessarily succeed.

1) Another applet, etc. could call your code or your library, etc. and make
use of you being signed to do malicious stuff.

There are a few exceptions (optimizations, perhaps), but generally, code
which is designed to run with a security manager must sort of declare that
it was designed to do so, knows what it's doing, and won't let itself be
abused to grant undue access to other (perhaps untrusted) code which calls
it.

What you're looking for is the AccessController.doPrivileged methods.  The
take either PrivilegedAction or PrivilegedExceptionAction, which are similar
to java.lang.Runnable, except that they have return values.  Invoking
AccessController.doPrivileged means I know what I'm doing, don't worry about
the privileges of my callers, only check the security access of my own code
and the code which I [in]directly call.

So, for example (and this is just writing as I go), you want to do something
like:

Socket s = (Socket) AccessController.doPrivileged(new PrivilegedAction() {
   public Object run() {
       try {
           return new Socket("some server", somePort);
       } catch (Exception e) {    return null;    }
   }
});

You mentioned AccessController.checkPermission.  This is how you force a
security check.  The Socket class constructor will (at least indirectly)
call checkPermission with a SocketPermission to _enforce_ these rules that
code which creates a socket must have permission to do so.

Rarely would one need to do such permission checks -- usually it's already
built in to the other stuff you call -- like opening sockets, or into your
superclass.  Even rarer would be the need to create new permissions to
protect some new type of resource which you provide.

Joel

> nothing has ever frustrated me more than trying to connect to a server (in
> this case a jabber server..)  with an applet.. I'm importing smack package
[quoted text clipped - 21 lines]
>
> would appreciate some help here..  thank you very much..


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.