Tuesday, October 26, 2010

Issuing the own private certificate lik

http://www.linford.se/temp/How%20to%20issue%20your%20own%20free%20certificate.pdf

Since a lot of people have asked about this in the past, I just wanted to give you an alternative to buying a certificate from for example Thawte or Verisign. If you only need a cert for your own users, i.e. no public certificate, then this way is a ok. The difference is that Thawte and Verisign (among others) are trusted by most web browsers by default. Your own issued one will not be by default, but you can add it to trusted root CA's and it'll work just as good.

This is a PDF document that I put together, and it focuses on creating a certificate for use with mail access, i.e. Outlook Web Access or between Outlook client and Exchange on the local network.





Thursday, October 14, 2010

Embedding SSL on Tomcat For Web application.

Setting Up SSL on Tomcat In 3 Easy Steps


Setting up SSL on Tomcat is easy and you don't have to do much for converting your web application to work with the Https protocol. But however, the problem you would find to set up SSL is the documentation available over the web. The documentation source is available on the Apache site but it starts off good and ends with a lot of confusion. Especially I was confused on the OpenSSL part where it says to use OpenSSL.

It might be good in a production environment to use OpenSSL but if you just want to test out SSL with Tomcat alone then it is more than enough to just have your JDK and Tomcat setups. So I would make you walk through the same steps which I did while getting SSL up and running and building a secured web app within a matter of minutes.

The things which I have used to setup SSL consists of:

  • JDK 1.6
  • Tomcat 6

Even though I have used the latest version I don't see any problems which you might face in carrying out the same set of steps for JDK 1.5 which I am about to explain. JDK comes shipped with a keytool executable which is required to generate a keystore. The keytool can be found in the earlier version of JDK too. The 3 steps which would make you to get started with setting up SSL are:

  1. Generating the Keystore file
  2. Configuring Tomcat for using the Keystore file
  3. Configuring your web application to work with SSL

Let's get this party started now.

1. Generating the KeyStore file

The keystore file is the one which would store the details of the certificates necessary to make the protocol secured. Certificates contain the information as to who is the source from which you are receiving the application data and to authenticate whether it is the intended party or not. To make this keystore you would have to use the keytool. So open command prompt in Windows or the shell in Linux and type:

cd %JAVA_HOME%/bin on Windows

cd $JAVA_HOME/bin on Linux

You would land up in the Java bin directory. Now time to run the keytool command. You have to provide some parameters to the command as follows :

keytool -genkey -alias techtracer -keypass ttadmin -keystore techtracer.bin -storepass ttadmin

The highlighted words are the ones which you would have to change according to your requirements. But keep one thing in mind that both the keypass and storepass passwords should be the same. The .bin file is actually your keystore file. It would now start a questionnaire. So fill in the relevant details accordingly. Look below for a reference as to what to answer for the questions.

What is your first and last name?
[Unknown]: nitin pai
What is the name of your organizational unit?
[Unknown]: home
What is the name of your organization?
[Unknown]: techtracer
What is the name of your City or Locality?
[Unknown]: mumbai
What is the name of your State or Province?
[Unknown]: maharashtra
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?
[no]: yes

The command would then conclude. It would make a .bin file with the name you had provided inside the bin directory itself. In my case it was techtracer.bin which was located in

C:\Program Files\Java\jdk1.6.0_02\bin\

Put the .bin file in the webapps directory of Tomcat. This is required to avoid the need to give an absolute path of the file in the next step.

2. Configuring Tomcat for using the Keystore file

Here we would be making some changes to the server.xml file inside tomcat to tell it to use the keystore which was created in the earlier step for configuring SSL. Open the file server.xml which can be found as:

<CATALINA_HOME>/conf/server.xml

Now you have to modify it. Find the Connector element which has port="8443″ and uncomment it if already not done. Add two lines. The highlighted lines are the newly added ones.

<Connector port="8443″
maxThreads="150″ minSpareThreads="25″ maxSpareThreads="75″
enableLookups="true" disableUploadTimeout="true"
acceptCount="100″ debug="0″ scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="../webapps/techtracer.bin"
keystorePass="ttadmin" />

You can notice that I have given the path to the keystoreFile property as relative to tomcat bin directory because the startup command will look for the .bin file. Now all you have to do is start your server and check the working of SSL by pointing your browser to the URL to:

https://localhost:8443/

Now that you have your tomcat running in the SSL mode you are ready to deploy an application to test its working. You must note that still your tomcat can run in normal mode too at the same time i.e on port 8080 with http. So it is but obvious that any application deployed to the server will be running on http and https at the same time. This is something that we don't want. We want our application to run only in the secured mode.

3. Configuring your web application to work with SSL

In order to do this for our test, take any application which has already been deployed successfully in Tomcat and first access it through http and https to see if it works fine. If yes, then open the web.xml of that application and just add this XML fragment before web-app ends i.e </web-app>

<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

Explanation of the fragment is beyond the scope of this tutorial but all you should notice is that the /* indicates that now, any resource in your application can be accessed only with https be it Servlets or JSP's. The term CONFIDENTIAL is the term which tells the server to make the application work on SSL. If you want to turn the SSL mode for this application off then just turn don't delete the fragment. Just put the value as NONE instead of CONFIDENTIAL. That's it!

Conclusion

These were the 3 easy steps in which you can make Tomcat to work in the SSL mode and also it tells you how easily you can turn the SSL mode on and off. If you find any difficulty or are not clear on any of the above steps feel free to drop in your queries. If you like this tutorial it would be nice of you to drop in a comment of appreciation or feedback as to how this tutorial can be improved.

Sunday, October 10, 2010

multiple instances of the same view be made to appear at the same time

Can multiple instances of the same view be made to appear at the same time?

Yes. See IWorkbenchPage.showView(String primaryId, String secondaryId, int mode).
The <view> element in the plugin.xml must also specify allowMultiple="true".
Be sure to use a different secondaryId for each instance, otherwise showView will find any existing view with the same primaryId and secondaryId rather than showing a new one.
To pass instance-specific data to the view, you will need to cast the resulting IViewPart down to the concrete view class and call your own setData method.
Note that views with a secondaryId will not match placeholders specifying just the primaryId. In a perspective factory, placeholders can be added for multi-instance views using the format primaryId + ':' + secondaryId, where '*' wildcards are supported.

Friday, October 8, 2010

Why Developers Should Not Write Programs That Call 'sun' Packages

Why Developers Should Not Write Programs
That Call 'sun' Packages


In general, writing java programs that rely on sun.* is risky: they are not portable, and are not supported.

The classes that Sun includes with the Java 2 SDK, Standard Edition, fall into package groups java.*, javax.*, org.* and sun.*. All but the sun.* packages are a standard part of the Java platform and will be supported into the future. In general, packages such as sun.*, that are outside of the Java platform, can be different across OS platforms (Solaris, Windows, Linux, Macintosh, etc.) and can change at any time without notice with SDK versions (1.2, 1.2.1, 1.2.3, etc). Programs that contain direct calls to the sun.* packages are not 100% Pure Java. In other words:
The java.*, javax.* and org.* packages documented in the Java 2 Platform Standard Edition API Specification make up the official, supported, public interface.
If a Java program directly calls only API in these packages, it will operate on all Java-compatible platforms, regardless of the underlying OS platform.
The sun.* packages are not part of the supported, public interface.
A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
For these reasons, there is no documentation available for the sun.* classes. Platform-independence is one of the great advantages of developing in the Java programming language. Furthermore, Sun and our licensees of Java technology are committed to maintaining backward compatibility of the APIs for future versions of the Java platform. (Except for code that relies on serious bugs that we later fix.) This means that once your program is written, the class files will work in future releases.

Each company that implements the Java platform will do so in their own private way. The classes in sun.* are present in the SDK to support the Sun implementation of the Java platform: the sun.* classes are what make the Java platform classes work "under the covers" for the Sun Java 2 SDK. These classes will not in general be present on another vendor's Java platform. If your Java program asks for a class "sun.package.Foo" by name, it may fail with ClassNotFoundError, and you will have lost a major advantage of developing in Java.

Technically, nothing prevents your program from calling into sun.* by name. From one release to another, these classes may be removed, or they may be moved from one package to another, and it's fairly likely that their interface (method names and signatures) will change. (From the Sun point of view, since we are committed to maintaining the Java platform, we need to be able to change sun.* to refine and enhance the platform.) In this case, even if you are willing to run only on the Sun implementation, you run the risk of a new version of the implementation breaking your program.

In general, writing java programs that rely on sun.* is risky: they are not portable, and are not supported.

Wednesday, October 6, 2010

Fwd: Creates a tabbed display in Eclipse RCP application


Creates a tabbed display in Eclipse RCP application

Tabbed.bmp
step-----------
1. Create View in the project.
2. Assign the view Id in the perspective addView(4 parameter...); method and add the  this(Member View);



package com.magnus.tabbedpane;

import org.eclipse.swt.SWT;
import java.io.*;


import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.part.ViewPart;

public class MemberTabView extends ViewPart {
   
    public static final String MEM_VIEW_ID="com.magnus.tabbedPane.MemberTab";

    public MemberTabView() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void createPartControl(Composite parent) {
       
        // Create the containing tab folder
        final TabFolder tabFolder = new TabFolder(parent, SWT.NONE);

        // Create each tab and set its text, tool tip text,
        // image, and control
        TabItem one = new TabItem(tabFolder, SWT.NONE);
        one.setText("General Info");
        one.setToolTipText("Member General Informaion");       
        one.setControl(getTabOneControl(tabFolder));

        TabItem two = new TabItem(tabFolder, SWT.NONE);
        two.setText("Financial Info");
        two.setToolTipText("Enter Financial Information");
      
        two.setControl(getTabTwoControl(tabFolder));

        TabItem three = new TabItem(tabFolder, SWT.NONE);
        three.setText("Education Info");
        three.setToolTipText("Edutaion Information");
   
        three.setControl(getTabThreeControl(tabFolder));

        // Select the third tab (index is zero-based)
        tabFolder.setSelection(0);

        // Add an event listener to write the selected tab to stdout
        tabFolder.addSelectionListener(new SelectionAdapter() {
          public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
            System.out.println(tabFolder.getSelection()[0].getText() + " selected");
          }
        });
       
    }
   
    /**
       * Gets the control for tab one
       *
       * @param tabFolder the parent tab folder
       * @return Control
       */
      private Control getTabOneControl(TabFolder tabFolder) {
        // Create some labels and text fields
            Composite composite = new Composite(tabFolder, SWT.NONE);
            composite.setLayout(new RowLayout());
            new Label(composite, SWT.LEFT).setText("Label One:");
            new Text(composite, SWT.BORDER);
            new Label(composite, SWT.RIGHT).setText("Label Two:");
            new Text(composite, SWT.BORDER);
            return composite;
       
      }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }
    /**
       * Gets the control for tab two
       *
       * @param tabFolder the parent tab folder
       * @return Control
       */
      private Control getTabTwoControl(TabFolder tabFolder) {
        // Create a multi-line text field
        return new Text(tabFolder, SWT.BORDER | SWT.MULTI | SWT.WRAP);
      }

      /**
       * Gets the control for tab three
       *
       * @param tabFolder the parent tab folder
       * @return Control
       */
      private Control getTabThreeControl(TabFolder tabFolder) {
       
       
     // Create a composite and add four buttons to it
        Composite composite = new Composite(tabFolder, SWT.NONE);
        composite.setLayout(new FillLayout(SWT.VERTICAL));
        new Button(composite, SWT.PUSH).setText("Button one");
        new Button(composite, SWT.PUSH).setText("Button two");
        new Button(composite, SWT.PUSH).setText("Button three");
        new Button(composite, SWT.PUSH).setText("Button four");
        return composite;
      }

}



Perspective Vs IPerspectiveDescriptor RCP

Difference Between Perspective  and   IPerspectiveDescriptor RCP

org.eclipse.ui
Interface IPerspectiveDescriptor


public interface IPerspectiveDescriptor

A perspective descriptor describes a perspective in an IPerspectiveRegistry.

A perspective is a template for view visibility, layout, and action visibility within a workbench page. There are two types of perspective: a predefined perspective and a custom perspective.

  • A predefined perspective is defined by an extension to the workbench's perspective extension point ("org.eclipse.ui.perspectives"). The extension defines a id, label, and IPerspectiveFactory. A perspective factory is used to define the initial layout for a page.
  • A custom perspective is defined by the user. In this case a predefined perspective is modified to suit a particular task and saved as a new perspective. The attributes for the perspective are stored in a separate file in the workbench's metadata directory.

Within a page the user can open any of the perspectives known to the workbench's perspective registry, typically by selecting one from the workbench's Open Perspective menu. When selected, the views and actions within the active page rearrange to reflect the perspective.

This interface is not intended to be implemented by clients.

See Also:
IPerspectiveRegistry
Restriction:
This interface is not intended to be implemented by clients.

Method Summary
 String getDescription()
          Returns the description of this perspective.
 String getId()
          Returns this perspective's id.
 ImageDescriptor getImageDescriptor()
          Returns the descriptor of the image to show for this perspective.
 String getLabel()
          Returns this perspective's label.
 

Method Detail

getDescription

String getDescription()
Returns the description of this perspective. This is the value of its "description" attribute.

Returns:
the description
Since:
3.0

getId

String getId()
Returns this perspective's id. For perspectives declared via an extension, this is the value of its "id" attribute.

Returns:
the perspective id

getImageDescriptor

ImageDescriptor getImageDescriptor()
Returns the descriptor of the image to show for this perspective. If the extension for this perspective specifies an image, the descriptor for it is returned. Otherwise a default image is returned.

Returns:
the descriptor of the image to show for this perspective

getLabel

String getLabel()
Returns this perspective's label. For perspectives declared via an extension, this is the value of its "label" attribute.

Returns:
the label