Sing applet in a web app

hi all,
i'm programming a web app that shows a jasperreport in a jsp code and it has an option to print that report showing to the user the print dialog, so i programmed that the print button was an applet and the print dialog arise at the client and not in the server side. until here everethig is ok and all sounds good but when i'm trying to sign the applet to access to the .jrprint from the jasper report and trying to print i jave to sent to the applet two .jar's files: one to the jasper library and the other to the applet certification. Does any body knwos how can i sen two .jar's to the same applet?

i really apreciate if someone can takes a minute to help me with this problem.

Thanks a lot,

Viviana
aggelos's picture
209
Joined: Aug 4 2006 - 12:59am
Last seen: 8 years 5 months ago

9 Answers:

You need to refer to the other library jar files in your applet tag for the print applet.

<applet code=Animator.class
archive="jars/animator.jar, jars/jasperreports.jar"
width=460 height=160>
<param name=foo value="bar">
</applet>

etc. etc. The archive tag will point to the relevant jar files. To print you will also need to sign your applet for appropriate security abilities. Do a google on this for more info.
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 16 years 10 months ago
Hi all,

First of all, rsilver thanks for ur help, it was just on time... well, now i have other problem... When i want to print, i do the following steps:
1. Load the .jasper report
2. Fill the report
3. print
but when i try to load the .jasper, it returns me null.
I tryed to insert the .jasper file in the .jar and put it in the applet package, but nothing works...

please, Does any body knows how can i solve it? :(

Thanks,

Viviana
aggelos's picture
209
Joined: Aug 4 2006 - 12:59am
Last seen: 8 years 5 months ago
I havn't loaded the report from within a jar file yet, although I am sure there is some mechanism to do so.

However, another option is to place the .jrxml file in the same folder on your web server as your APPLET jar... and then in the applet class you can call the getCodeBase() method which will return that folder as a URL. Then append the filename to it and it should work.
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 16 years 10 months ago
Hi rsilver,
Thanks again for ur help :blush: ... I really like ur option and i implemmented it in my project, then i signed the applet like this:
jar cvf imprimir.jar *.class
keytool -genkey -alias signFiles -keystore appletstore -keypass XXX -dname "cn=echarry" -storepass XXX
jarsigner -keystore appletstore -storepass XXX -keypass XXX -signedjar impresion.jar imprimir.jar signFiles
keytool -export -keystore appletstore -storepass XXX -alias signFiles -file AppletImpresion.cer
keytool -import -alias viviana -file AppletImpresion.cer -keystore raystore -storepass viviana

and finylly i modified the .java.policy file with:
keystore "\\C:\\Documents and Settings\\echarry.YCSA\\jbproject\\Applet\\arte\\applets\\raystore";
grant signedBy "viviana", codeBase "fiel:{tomcat.home}/arte/applets"{
permission java.io.FilePermission "reportes/*","read";
};

but when i try the applet, it still shows me de message : java.security.AccessControlException: access denied (java.io.FilePermission arte\applets\reportes\Computador.jasper read)

Do u know how can i configure my .java.policy correctly?:S

THANKS A LOT,

Viviana

rsilver@bfm.bm wrote:
I havn't loaded the report from within a jar file yet, although I am sure there is some mechanism to do so.

However, another option is to place the .jrxml file in the same folder on your web server as your APPLET jar... and then in the applet class you can call the getCodeBase() method which will return that folder as a URL. Then append the filename to it and it should work.
:blush:
aggelos's picture
209
Joined: Aug 4 2006 - 12:59am
Last seen: 8 years 5 months ago
I think you may have incorrectly signed the jar file. Your applet's web browser it is being run in should just read the jar file signature and take the authorization confirmation from there... if I was going to sign a jar file I would....

1. Generate a key:
c:\\keytool -genkey -alias <ALIAS> -keystore <KEYSTORE FILE>

where <ALIAS> is alias for your cert... anything really.
<KEYSTORE_FILE> is file that the cert will be stored in... I prefer to use a .jks extension just for conventions sake.

2. Sign your jar file:
c:\\jarsigner -keystore <KEYSTORE_FILE> -signedjar <FINAL_JAR_NAME> [UNSIGNED_JARFILE] <ALIAS>

3. Verify signature: jarsigner -verify <FINAL_JAR_NAME>

The example is a bit basic, but you should be able to follow through start to finish if you follow these basic guidelines.
Post edited by: rsilver@bfm.bm, at: 2006/09/26 18:10
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 16 years 10 months ago
Hi rsilver,
i'm following the same steps showed in the sun web, here is the url http://java.sun.com/developer/technicalArticles/Security/Signed/ ... it's very similar to your steps, but i really don't understand where i give the rigth permissions to a specific file....

i really, really appreciate ur help
THANKS a LOT

Viviana
aggelos's picture
209
Joined: Aug 4 2006 - 12:59am
Last seen: 8 years 5 months ago
When I used the methods above, I never really worried about signing permissions... since I am signing my applet I wanted the applet to be able to print and do File IO so I just signed for all permissions I guess. As for implementing specific permissions I am not sure... why not just implement them all?
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 16 years 10 months ago
i just did it, but it doesn't work yet :S:(
aggelos's picture
209
Joined: Aug 4 2006 - 12:59am
Last seen: 8 years 5 months ago
Try following the steps in that article up to where it talks about exporting a public key. If you do that, does it let you run your applet, but with first prompting for permission? That is what I usually did... prompts the user to approve the applet rather than an automatic approval. This is more feasible since you don't want to distribute the cert "always".

If you require more assistance lets take this offline till we resolve it, email me and we can start working on it.
rsilver@ns.sympatico.ca's picture
Joined: Aug 4 2006 - 3:46am
Last seen: 16 years 10 months ago
Feedback
randomness