Friday, July 27, 2007

Java permissions and the signed applet

As we know that by default, applets have no access to system resources outside the directory from which they were launched, but a signed applet can access local system resources as allowed by the local system's security policy. The JDK provides security tools so end users and system administrators can sign applets and applications, and define their local security policy by specifying in a policy file (placed in the user home directory plus the default one in the JRE_HOME\lib\security) how much access to local system resources a signed applet or application can have.

Work in steps:-
  1. Set Applet Permissions
  2. You can set the permissions that your applet wants to run correctly in its init method, those are a sample permissions:

    private void setPolicyPermissions() throws MalformedURLException {
    Policy policy = Policy.getPolicy();
    PermissionCollection permissions = policy.getPermissions(new CodeSource(new URL(getParameter("CODE_SOURCE_URL")),
    new Certificate[0]));
    RuntimePermission accessClassPermission = new RuntimePermission("accessClassInPackage.sun.awt.windows");
    permissions.add(accessClassPermission);
    }

    You can see the available permissions in Java. and choose the suitable for your mission.


  3. Compile the Applet
  4. In your working directory, use the javac command to generate the class file:

    javac MyApplet.java


  5. Generate the Jar file
  6. Now it's the time to generate a jar file to contain the .class files, so we'll use the jar command to finish this task:

    jar -cvf MyApplet.jar *.class


  7. Generate Keys
  8. Here we'll generate the needed keys to sign the jar file to be enabled to run at the client and use his machine resources safely using the keytool command. the prompt will ask you for a password to the key and another one for the store... handle that:

    keytool -genkey -alias MyKey -keypass KeyPass


  9. Self certify
  10. we'll use the keytool command again to make our key self certify. (i think that command used instead of using the private and public key):

    keytool -selfcert -alias MyKey


  11. Sign the JAR File
  12. JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, jarsigner to make a signed copy of the MyApplet.jar file:

    jarsigner -storepass StroePass -keypass KeyPass MyApplet.jar MyKey

Now you have a signed applet jar which has the suitable permissions to use the client machine resources ;)

Monday, May 21, 2007

Using pojos as a data source for the jasper report


Using pojos as a data source for the jasper report

Here we'll know how to use the pojo as a data source instead of writing a SQL query inside the report.

  1. Create the report pojo.

  2. Create a pojo that represents your report data.

    if your report contains another subReport, your pojo will contains a list of the pojo that maps to the subReport data. so you will be in a need to add a function that returns the subReport list like the following one:


    public Object getSubReportArticlesList(){

    if (articlesList == null){

    articlesList = new ArrayList();

    }

    return new JRBeanCollectionDataSource( (ArrayList) articlesList , true);

    }



  3. Design you report.

  4. Now open your design tool and after finishing the static data, add data fields into your report but insure that this fields has the same name and type as your pojo attributes.

    if your report contains a subReport as we said before there will be a function inside the main pojo that will return the subReport data source, now we will handle it inside the design. create a field with the name of the method that returns the subReport data source like that subReportArticlesList it'll be handled by the jasper report framework as an ordinary attribute (name >> getName(), subReportArticlesList >> getSubReportArticlesList(), ....) and set that field as a data source for the subReport.


  5. Inside the report initialization method.

  6. you must specify the data source as a JRBeanCollectionDataSource.

Sunday, May 13, 2007

what is JasperReport?...

JasperReport is a very useful reporting tool, which give the developers the ability to generate reports with rich content in many formats like PDF, HTML, RTF, JPG, PING and XML files.

JasperReport API is entirely written in Java code so it'll be very easy to be used in a variety of java enabled applications( J2EE, or J2EE), to generate dynamic reports.

The main purpose is to help creating page oriented, ready to print documents in a simple and flexible manner.

Download the API

Sunday, May 6, 2007

Quotes

"It's all about time..."

"A man who stands for nothing will fall for anything."

"The future belongs to those who prepare for it today."

"If you do not hope, you will not find what is beyond your hopes."

"To get what we have never had we must do what we have never done."

"Success is the ability to go from one failure to another with no loss of enthusiasm."

"There is no better than adversity. Every defeat, every heartbreak, every loss, contains its own seed, its own lesson on how to improve your performance next time."