How to load signed applet from local disc with full permissions? - java

I have an application where javascript code is accessing java applet methods that write on local disk (just to note - this is not directly possibly, but there is a workaround for it that enables to do so). Applet is self-signed applet, so users have to allow it to run first.
If applet's codebase is set to "http://..." everything works fine, in FF, Chrome and Opera as well. However, I would like to put this applet on local file system. However, if I use codebase "file://..." (I also tried to not use codebase at all and write directly full jar path to archive) it does not work, applet does not load with Warning-Security pop-up that enable user to allow running the applets.
I only tested it in FF (3.6.1.4) so far, Java version is 1.6.0.21.
Are signed applets limited only for HTTP use? Or is there some workaround?

..is there some workaround?
Perhaps using the JNLP API services in an unsigned applet will work better. I have a demo. of the JNLP FileContents object.
For details on using the JNLP services in an embedded applet see the links to the 'next generation plug-in' in the applet information page.

Applets loaded from the local filesystem are allowed to write files only in, or below, the directory containing the applet. So, if the applet is in C:\MyProjects\MyAppletTest it will be able to read and write files in that directory and its subdirectories, but not in C:\MyProjects. You can override this behavior with a policy files as explained in Quick Tour of Controlling Applets

Related

Run a java class file from a webpage on the visitor computer?

I coded a Java program to read and modify a file on the computer. The program is based only on 1 class.
At the moment who want to use it has to run it from terminal, I'm looking on how to insert it on a webpage and make it run on the visitor's computer. It would be fine to have a file chooser (the user will want this modification).
I searched on internet and found Java applets, but I read that they aren't downloaded and executed locally so the program won't work.
How to provide a Java class file from a webpage, for use on the computer of the end-user?
If you really want to download a Java program and run it locally, you should check out Java Web Start.
Briefly, it allows the user to download and run a Java program locally on their machine. It does clever stuff like identify if an updated version is available for download, and will run the cached version if that's the current version.
Here's a tutorial.
..it would be fine to have a file chooser ..
In that case, there are basically the two options as I've outlined in comments throughout this question & the answers. I'll collect them together here:
Digitally sign the applet, get the user to accept the digitally signed code when prompted (before the applet is loaded), then offer a JFileChooser to browse to the file.
If the user has a plugin 2 JRE (chase the links in the JWS info. page for more details), it is possible to deliver the applet to the user unprompted, then leverage the JNLP API to produce a file chooser. The user will be prompted before the dialog appears, this time with a more specific warning.
JWS
For an example, see my applet based GIF animation tool which uses the JNLP API when the user goes to load image frames or save the animated GIF.
That applet is not open source (mostly because of my laziness in not wanting to revisit & tidy the code) but there is a much better example of using the JNLP file services that comes complete with source.
Digital signatures
I don't have any great links about the process of digitally signing code, but note that the 'example of using the JNLP file services' listed above provides one set of signed Jars for 2 different security environments. It also (hopefully obviously) demonstrates how to digitally sign code using Ant (it all happens by invoking the default task in the build.xml).
Applets can modify files locally, if they are signed and the user allows them to.
Read up on signed applets.
I read that they aren't downloaded and excuted locally
Whereever you read that, it is 100% incorrect. Applets are downloaded into the browser and executed at the client host.

Is it possible to read/write a file from an applet

I've trying to read and write a file from an applet so if I run the applet from my appletviewer it is possible for me to read/write a file but when I try to do it from my browser I get a security exception. Any idea how to do this?
Is it possible to read/write a file from an applet
Yes, but you need to sign the applet and get approval from the user.
Some useful links:
How can an Applet read files on the local file system (from coderanch.com)
Essentials, Part 1, Lesson 6: File Access and Permissions (from oracle)
Chapter 10: Signed Applets (from oracle)
A sand-boxed JWS app. can read and write to files on the local file system using the JNLP API services. Here is a demo. of the JNLP API file services. The downloadable Zip file contains the source, launch file and build script.
it's actually not that difficult. You can self sign an applet and then it will be able to read/write to/from the local file system outside the sandbox constraints. take look at the link below. it will show you how to sign your applet using the keytool and the example actually does read/write to the filesystem. no need to muck about the policy files and such.
Note that as #aioobe mentioned, the user will be prompted to accept the certificate though.

How to upload files with java applet?

I know similar questions have been asked but i have searched for hours and as of yet have not come up with a workable solution.
I have a Java applet which will be a "paint" like application. So, I need the user to be able to upload images from their file system. I first tried using a JFileChooser which works great in the eclipse environment. However, when put online i get a "java.security.AccessControlException: access denied" exception.
I was thinking that perhaps within the applet i could call a script (located on my server) which would prompt the user to select a file - but i have no idea how to do this. I am using zymic web hosting, so the only supported scripting language is PHP.
I also tried signing the applet. Since i don't want to spend money on certificates, i self signed the applet. When i tried running it, I got an error stating "The Publisher Cannot Be Verified By A Trusted Source".
Any help would be greatly appreciated. - Thanks:)
A trusted applet can most certainly load files from the local file-system. The "Publisher Cannot Be Verified By A Trusted Source" message that is produced by self-signed applets is onerous & scary (for good reason), but if the user OKs it, it works just fine.
Here is a small demo. of exactly that.
Since the 'Next Generation' Plug-In, even sand-boxed applets can access the local file system. See the last 2 links on the Applet tag info page for further details.
Here is an applet that uses the Next Generation file abilities.
Unsigned applets can not access the file system for security reasons.
There is a tutorial about uploading files using PHP here
Maybe you can work that into your page in order to allow the file to be uploaded and then load it from your web server with the applet.
Do keep in mind the warning at the end of that example under the section "php - file upload: safe practices"

Ways to open a folder/explorer client side from a web page.... Java applet?

I have a need to "pop up" operating system folders from my web app, mostly to locate files in them. My users don’t want to use a conventional web upload/download paradigm. I have 7 or 8 static folders that need to be opened in explorer on a PC or in Finder on a mac. These folders are all network available, but are buried, and for convenience need to be shown on a web page.
There are IE tricks to do this, and I've written a sample flash app that only allows the browser to open, but I know most browsers sandbox this, and keep me from calling these folders. I am aware that some Java libraries deal with the opening of folders, does anyone have any thoughts or samples for this?
The only way I can imagine is to create a Signed Java Applet.
Applets cannot access the filesystem (and a lot of other ressources) if they are not valid signed. Maybe you can also grant the permission by a policyfile.
There ist a tutorial at JavaRanch.
But I am not sure, if this solution will be very helpful, because the JavaPlugin will be removed from a lott of browsers in near future. (I think FireFox already removed it).
I think there is actually NO solution to this problem.
There may be some workarrounds:
Put a Batch-File onto the server, which opens the folder, if executed
Can you create a local service, which handles requests from you webpage and opens the folder.
Create a webapplication, which opens the folder at serverside, and create a webpage, which displays the content in you website.

Java applet doesn't run on my local machine

I'm writing my own Java applet that can write to /tmp on my local unix machine.
this applet is only going to run on a html page, inside my machine only. No server involved.
But when I try to open my page inside Firefox, the applet doesn't seem to work at all. I don't understand why, since all the .class, .html and .jar files are on the same directory.
Need help.
A normal applet can't access the filesystem, as they are by default not trusted.
To enable filesystem access and other things (like native librarys) for an applet it has to be signed.
When a signed applet is loaded into the browser the first time, a notification pops up requesting the user to confirm that the applets signature is trusted.
More information here.
I don't know very much about applets, but I remember that one basic constraint is that they can't access the local filesystem.
If you want to do that one good option is to use Javascript. EDIT: But it will not work directly!

Categories

Resources