<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; JCA</title>
	<atom:link href="http://www.javabeat.net/category/java-j2ee/jca/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Tue, 21 May 2013 13:43:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Java Security Packages using JCA/JCE</title>
		<link>http://www.javabeat.net/2008/05/java-security-packages-using-jcajce/</link>
		<comments>http://www.javabeat.net/2008/05/java-security-packages-using-jcajce/#comments</comments>
		<pubDate>Fri, 23 May 2008 00:42:32 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JCA]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=330</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>In thistutorial, the author explains the cryptography-related concepts and packages in JDK,with code examples.Many of the concepts and technical terms thus learnt will be useful in understanding the Cryptography API in MFCalso. &#8212;&#8212;&#8212;&#8212;&#8211; There arethree security-related packages in JDK1.4, as follows: i)JCA/JCE(Java Cryptography Architecture &#38; JavaCryptography Extensions) ii)JSSE( Java Secure-Sockets Extension). iii)JAAS( Java Authentication &#38; [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p><b><span><span></span>In this<span></span>tutorial, the author explains the cryptography-related concepts and<br />
packages in <span class="SpellE">JDK<span class="GramE">,with</span></span> code <span class="SpellE">examples.Many</span> of the concepts and technical terms thus<br />
learnt will be useful in understanding the Cryptography API in MFC<span></span>also.</span></b></p>
<p class="MsoNormal"><b><span>&#8212;&#8212;&#8212;&#8212;&#8211;</span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span>There <span class="GramE">are<span></span>three</span><br />
security-related packages in JDK1.4, as follows:</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span>i)<span></span></span></span><b><span>JCA</span></b><span>/<b>JCE</b></span><span>(Java Cryptography<br />
Architecture &amp; Java<span></span>Cryptography<br />
Extensions)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>ii)<span></span><span class="GramE"><b>JSSE</b>(</span> Java<br />
Secure-Sockets Extension).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>iii)<span></span><span class="GramE"><b>JAAS</b>(</span> Java Authentication &amp; </span></p>
<p class="MsoNormal"><span><span></span><span class="SpellE">Auhorization</span><span></span>Service) </span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="GramE"><span>(<br />
Prior</span></span><span> to <b>JDK1.4</b>, many of these packages<br />
were not available within the JDK and had to be separately installed and used.<br />
But, JDK1.4 has incorporated all these within JDK itself).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>Understanding the terminology of these<br />
important packages requires that we <span class="GramE">have<span></span>some</span> familiarity with the technical<br />
terms used in<span></span>the field of Network<br />
Security. We can begin by saying that<span></span>secure <span class="GramE">communication ,should</span> ensure the<br />
following.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>a)<span></span>Integrity</span></p>
<p class="MsoNormal"><span><span></span>b)<span></span>Confidentiality</span></p>
<p class="MsoNormal"><span><span></span>c)<span></span>Authentication</span></p>
<p class="MsoNormal"><span><span></span>d)<span></span>Non-repudiation</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">[ There</span> is also<br />
another requirement (<span class="SpellE">ie</span>)</span></p>
<p class="MsoNormal"><b><span>Authorization</span></b><span><br />
and it is more to protect resources and programs from users, than with<br />
communicating the data. JAAS deals with that].</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>These are all standard terms used in<br />
Security. When<span></span>a person, say, Sam<span class="GramE">,<span></span>wants</span> to send some<br />
information to<span></span>Tom, it must be ensured that<br />
the information thus sent, is not tampered with or<span></span>altered on the way. This is known as Data <b>Integrity.<br />
</b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span>Secondly,<br />
the information is meant only for Tom and so <b>no one else </b>should be able<br />
to understand the message. This is known as <b>Confidentiality. </b>There<br />
should be some indication that the message came from Sam <span class="GramE">and<span></span>there</span> should be some proof for that.<br />
This is <span class="SpellE">Identification.Authentication<span class="GramE">,that</span></span><br />
the message came from Sam is provided by<span></span><b>Digital</b><span class="SpellE"><b>Signature</b>.There</span> should<br />
preferably be a trusted third party to vouchsafe for the identity and signature<br />
of Sam. This is achieved by <b>Digital <span class="SpellE">Certificate<span class="GramE">,<span style="font-weight: normal">which</span></span></span></b><br />
authenticates the signature of Sam. Besides these, <span class="GramE">sometimes<span></span>it</span> is equally important that<span></span>Sam should not be able to say later that he<br />
did not send the message to Tom and the message was actually sent by someone<br />
else ,in his name. This is<span></span>ensuring <b>Non-repudiation</b>.<br />
This purpose also is served <span class="GramE">by<span></span>Digital</span> signature. We will now see<br />
step-by-step development of these concepts. Except &#039;Authorization&#039;, other things<br />
can be understood in the context <span class="GramE">of<span></span>everyday</span> exchange of information. </span></p>
<p class="MsoNormal"><span>&#8212;<span></span></span></p>
<p class="MsoNormal"><span><span></span>Confidentiality is achieved <span class="GramE">by<span></span>using</span><b>Cryptography</b><br />
techniques. For the sake of simple illustration, let us assume that Sam wants<br />
to send <span class="GramE">a<span></span>message</span><br />
to Tom.( By convention, two persons Alice &amp; Bob are chosen for<br />
illustration, because the original thesis made use of these names. Let us use<br />
Sam and Tom instead).Sam does not want his message to be understood by anybody<br />
else except Tom. So, he <b>encrypts</b> it. When Tom receives the encrypted<br />
message, he &#039;<b>decrypts</b>&#039; it, so that he can read the original message. The<br />
original message is known as &#039;<b>plaintext</b>&#039;. After <b>Encryption</b>, it<br />
becomes <b>&#039;<span class="SpellE">ciphertext</span>&#039;</b>. The process of <span class="GramE">converting<span></span>the</span><span class="SpellE">ciphertext</span><span></span>into the<br />
original plaintext is known as <b>Decryption</b>. A <span class="GramE">&#039;<b>key&#039;</b><span></span>is</span> used for controlling<span></span>Encryption and Decryption.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>There are two types of key-based<br />
encryption algorithms, namely, Symmetric algorithm<br />
and Asymmetric Algorithm.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>a) <span class="GramE"><b>Symmetric<span></span>Algorithm</b></span><b>:<span></span></b>This algorithm<span></span>uses the same key for encryption and<br />
decryption.<b></b>This is also known as &#039;<b>Secret key&#039;</b>.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>In this scheme, when Sam wants to send a<br />
message to Tom, he encrypts the message by the mutually agreed secret-key and<br />
then sends the <span class="SpellE">ciphertext</span> to Tom. Tom uses the same<br />
secret key and decrypts the message and reads it.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>Symmetric key system is <b>faster </b>than the<br />
Asymmetric system but the problem of agreeing on mutual secret key<span></span>and preserving the secrecy of the<span></span>key while communicating it over the network,<br />
led to the <span></span>development of<span></span>Asymmetric key systems.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>Some of<br />
the Symmetric key Algorithms are as follows: (<span class="GramE">Most<span></span>of</span> them are implemented<span></span>in JCA/JCE).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="SpellE"><span>i</span></span><b><span>) <span class="GramE">DES<span style="font-weight: normal">(</span></span></span></b><span> Data-Encryption-Standard).. <span class="GramE">developed</span> in 1970 and recommended by US government. Though<br />
it is not fool-proof, it is considered to be sufficiently safe and is in wide<br />
use.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>It has different modes of operation.</span></p>
<p class="MsoNormal"><span>a)<br />
Electronic Cook book <span class="GramE">( ECB</span>)</span></p>
<p class="MsoNormal"><span>b) Cipher<br />
Block Chaining <span class="GramE">( CBC</span>)</span></p>
<p class="MsoNormal"><span>c) Output<br />
Feedback Mode (OFB)</span></p>
<p class="MsoNormal"><span>d) Cipher<br />
Feedback Mode <span class="GramE">( CFB</span>)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>11) <span class="SpellE"><span class="GramE"><b>TripleDES</b></span></span><span class="GramE">(</span> also known as <span class="SpellE">DESede</span>) ..</span></p>
<p class="MsoNormal"><span class="GramE"><span>An<br />
improved and very safe method of DES.</span></span><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>iii) <b>IDEA</b> (International Data Encryption<br />
Algorithm). This is used in PGP <span class="GramE">( Pretty</span>-Good-Privacy<span></span>method of secure Email).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>An<br />
important advantage of Secret-key algorithm is that a<b> hardware-approach </b>is<br />
possible. This results in very high speed encryption. The hardware<br />
implementation by a VLSI chip can be about <b>20 times faster </b>than the<br />
corresponding software <span class="SpellE">implementation<span class="GramE">!IDEA</span></span> has been implemented in<br />
hardware.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="GramE"><span>iv) <b>Blowfish</b></span></span><b><span>&#8230;</span></b><span>This<br />
algorithm was designed by Bruce <span class="SpellE">Schneier</span>. It is not<br />
patented and he has placed the implementation in public domain.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>v) There<br />
is also a method known as <b>Password-Based <span class="GramE">Encryption(</span>PBE).</b> We will have a brief description<br />
of this <span class="GramE">method ,with</span> code <span class="SpellE">example,shortly</span>.<br />
</span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span><span></span>Ready-<span class="GramE">made<span></span>implementations</span><br />
for many of these algorithms are available in <span class="SpellE">SunJCA</span>/JCE<br />
and the programmer just chooses the desired algorithm and uses it. No deep<br />
knowledge of the mathematical theory of the algorithms or how these algorithms<br />
are <span class="GramE">implemented ,is</span> required .Such topics are highly<br />
mathematical and are<span></span>dealt with in<span></span>books on Cryptography . </span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><b><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span class="GramE"><span>b)<b>Asymmetric</b></span></span><b><span> Algorithms</span></b><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span><span></span>This algorithm is also known as &#039;Public Key&#039;<br />
algorithm. There are two keys in this scheme. One key is known as <b>&#039;public<br />
key&#039; </b>and the other key is known as &#039;<b>private key&#039;<span class="GramE">.(</span></b>It should be noted that &#039;<b>secret key&#039; </b>does<br />
not mean &#039;private key&#039;.)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span></span><span>The<br />
basic theory of Public key Cryptography was developed by two research workers<br />
at </span><span>Stanford</span><span></span><span class="GramE"><span>University</span></span><span class="GramE"><span><span></span><span class="SpellE"><b>Diffie</b></span></span></span><span><b>&amp;</b><span class="SpellE"><b>Hellman</b></span> in <b>1976</b>. The<span></span><b>DH</b> algorithm is known as<br />
Key-Agreement method. RSA algorithm is an <span class="GramE">implementation ,</span><br />
named after the initials of the three academics who invented it. <span class="GramE">( <span class="SpellE">Rivest,Shamir</span></span> &amp; <span class="SpellE">Adleman</span>).RSA is the <span class="SpellE">defacto</span><br />
standard.<span></span>Another Asymmetric algorithm <span class="GramE">is<span></span><b>DSA</b></span></span></p>
<p class="MsoNormal"><span class="GramE"><span>( Digital</span></span><span> Signature<br />
Algorithm). Yet another algorithm is known as <span class="GramE"><b>ECC</b>(</span>Elliptic-Curve<br />
Cryptography). It is reputed to be very efficient and fast<span class="GramE">.[</span><br />
However, <span class="SpellE">SunJCA</span>/JCE does not provide ready-made<br />
implementation for ECC.]</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The public key and private key are known as <b>&#039;<span class="SpellE">keypair</span>&#039;</b>.<span></span>The<br />
public key and private key are mathematically related<span></span>in the sense that if a message is encrypted<br />
by using a particular public key, it can be decrypted by the corresponding<br />
private key and vice-versa(<span class="SpellE">ie</span>) the <b>data</b> can<br />
also be encrypted by using a private key and can be decrypted by the<br />
corresponding public key, and not by any other public <span class="SpellE">key.But</span><br />
the problem is that<span></span>any person who knows<br />
Sam&#039;s public key<span></span>can decrypt the <span class="SpellE">message.So</span>,<span></span>RSA<br />
system uses <b>public key </b>of the <b>recipient </b>to encrypt the data.(<br />
But, the private key <b>cannot be derived </b>from public <span class="SpellE">key.Similarly</span>,<br />
the public key cannot be derived from private key).</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>RSA method is the most widely used scheme.<br />
When Sam wants to send a secret message to Tom, he should know the <b>public<br />
key of Tom </b>to begin with<span class="GramE">.(</span> Just as we should know<br />
the mail-id of our friend first, if we want to send email to him). Sam<span></span>encrypts the message by using <b>Tom&#039;s<span></span>public key<span></span></b>and sends it to <span class="SpellE">Tom.At</span> the receiving end,<br />
Tom uses his <b>(Tom&#039;s)private key </b>and decrypts the letter and reads <span class="SpellE">it.The</span> advantage of this scheme is that it ensures that<br />
only Tom will be able to read the message, as only his private-key can decrypt<br />
the message encrypted with his public <span class="SpellE">key.A</span> person&#039;s<br />
private key need never be known to anyone else and there is no sharing the key<br />
with another <span class="SpellE">person.Only</span> the public key needs to be<br />
informed to others. <span class="GramE">( like</span> the difference in sharing<br />
our mail-id and sharing our password!).Thus key-administration problem is less.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span class="SpellE"><b><span>DigitalSignature</span></b></span><span><span class="GramE"><b>&amp;<span></span><span class="SpellE">MessageDigest</span></b></span><b></b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The Asymmetric system has another use as<br />
well. It can be used for creating the <b>Digital Signature</b>, to ensure that<br />
the message came from <span class="SpellE">Sam.Though</span> the message itself can<br />
be signed without creating a digest, the usual method is to sign the <span class="SpellE">messagedigest<span class="GramE">,so</span></span> that Integrity of<br />
data also can be ensured.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>A <b>&#039;Message Digest&#039; </b><span class="GramE">is<span></span>a</span> digital <span class="SpellE">fingerprint.It</span><br />
is<span></span>often referred to simply as a digest<br />
( summary) or hash. It is an one-way process <span class="GramE">( <span class="SpellE">ie</span></span>) it is impossible to reconstruct the original<br />
from the hash.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span></span><b>MD5(</b>MessageDigest-5<b>) </b><span></span>and<span></span><b>SHA-1</b>(<br />
Secure Hash Algorithm) are two examples of such Digesting <span class="SpellE">algorithms.These</span> two are provided in Sun security<br />
package.MD5 accepts some input and produces a 128-bit message digest.<span></span>SHA-1 is more secure and produces a 160-bit<br />
message digest. </span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>When Sam wants to send a secure message, he<br />
passes the message through a <span class="SpellE">MessageDigest</span> engine.<br />
The result is a hash.</span></p>
<p class="MsoNormal"><span>He then<br />
encrypts the<span></span><span class="GramE">hash<span></span>by</span> using <b>Sam&#039;s</b><span></span><b>private key</b>.( This encryption is done<br />
on the hash and<b> not on the data</b>). Thus we get the Digital Signature.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>Finally, Sam <span class="GramE">encrypts<span></span>the</span> original message using<span></span><b>Tom&#039;s Public key. </b>After this, Sam<br />
sends the package to Tom.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>At the receiving end, Tom uses <span class="GramE">his<b>(</b></span><b>Tom&#039;s) private key </b>to decrypt the <span class="SpellE">message.By</span> using Sam&#039;s public key, he<span></span>decrypts the digital signature and so gets<br />
the original<span></span>hash( hash1).<span></span>Using the same <span class="SpellE">oneway</span><br />
hash algorithm on the text <span class="SpellE">message<span class="GramE">,Tom</span></span><br />
creates another hash( hash2).If hash2<span></span>exactly matches hash1, it means that the data has not been altered in<br />
transit. Thus, we get assurance of Confidentiality <span class="GramE">and<span></span><b>Data</b></span><b><span class="SpellE">Integrity.<span style="font-weight: normal">It</span></span></b> also ensures the identity of<br />
the <span class="SpellE">sender,becuase</span> the <span class="SpellE">the</span><br />
hash1 was obtained by using the public key of Sam to decrypt the package.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>If the<br />
public key of Sam, used by Tom, has the added assurance from a certificate<br />
authority that it really belongs to Sam,<span></span>this is <span class="GramE">a<span></span>clear</span>-cut<br />
method with no problems except that it is not suitable if the message being<br />
encrypted is of large size. Besides satisfying the requirements of<br />
Authentication, Confidentiality, Integrity and Non-Repudiation, we should also<br />
ensure that the process is fast, in </span><span>Enterprise</span><span><br />
level. The method outlined above is slow and so may not be suitable for <b>large<br />
<span class="SpellE">messages<span style="font-weight: normal">.Otherwise</span></span></b>,<br />
it is a satisfactory method.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>(We will describe a<b> hybrid </b>method used<br />
for large messages, shortly).<span></span></span></p>
<p class="MsoNormal"><span></span></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p class="MsoNormal"><span><span></span>Sometimes, it may be enough if there is<br />
Authentication and Non-<span class="SpellE">Repudiation<span class="GramE">,without</span></span><br />
confidentiality. In such cases, it is enough if Sam sends the message-digest<br />
encrypted by Sam&#039;s <span class="SpellE"><span class="GramE">privatekey</span></span><span class="GramE"> ,along</span> with the plaintext.<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>Digital<br />
Certificate</span></b><span></span></p>
<p class="MsoNormal"><span><span></span>Just <span class="GramE">now ,</span> we saw<br />
that Tom<span></span>made use of <b>Sam&#039;s public key<br />
</b>to verify his Digital Signature. How does Tom <span class="GramE">get<span></span>to</span> know the public key of Sam?<span></span>Sam could have published his public key in<br />
the internet or could have sent it to Tom, personally. A person&#039;s public key<br />
can be freely published and shared and for this reason, anybody can use <span class="GramE">it ,</span> not necessarily Sam. A Digital signature of Sam can be<br />
verified only if Sam&#039;s public key is available to <span class="GramE">Tom<span></span>but</span> as it is a public key,<br />
impersonation is possible. A trusted third-party is required to certify that<br />
the said key is really Sam&#039;s public <span class="SpellE">key.This</span> is known<br />
as <b>Digital Certificate </b>and the authorities who issue such <span class="SpellE">certifictes</span> are <span class="GramE"><b>Certifying</b></span><b><br />
Authority.<span></span></b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span>Public<br />
Key <span class="GramE">Infrastructure(</span> PKI)</span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span>When Sam wants<br />
his public key to be certified by a CA, he generates a <span class="SpellE">keypair</span><br />
and sends the public key to an appropriate <span class="GramE">CA<span></span>with</span> some proof of his identification.</span></p>
<p class="MsoNormal"><span>The CA<br />
checks the identification and then after satisfying that the key has not been<br />
modified in transit, issues a certificate relating the public key of Sam with<br />
his <span class="SpellE">identity<span class="GramE">,by</span></span> signing the<br />
public key of Sam with the <b>private key of the CA</b>. The standard <span class="GramE">format<span></span>of</span> issuing the<br />
certificate is known as <b>X509.</b></span></p>
<p class="MsoNormal"><span><span></span>Who is to attest<br />
the CA themselves? The CA<span></span><span class="GramE">are</span> self-attested.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The PKI standard has been developed by RSA<br />
Security Systems in collaboration with Industry leaders like SUN, IBM and Microsoft<br />
and is the industry standard.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="SpellE"><b><span>Certficate</span></b></span><b><span>-Revocation</span></b></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span class="GramE"><span>A<span></span>certificate</span></span><span><br />
becomes invalid after the expiry of validation period. Sometimes, the private<br />
key associated with a public key gets compromised ( <span class="SpellE">ie</span>)<br />
exposed, and in that case also, the <span class="SpellE">cerificate</span> should<br />
be withdrawn( revoked).The owner of the <span class="SpellE">privatekey</span><br />
also may like to change <span class="SpellE">it.The</span> CA publishes a list of<br />
such defunct certificates and Tom should verify that Sam&#039;s<span></span>certificate is still valid, before important<br />
transactions.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>Message-Authentication-Code<br />
<span class="GramE">( MAC</span>)</span></b><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>Digital Signature makes use of Sam&#039;s<br />
private key to sign the hash. An alternative to Digital Signature is to use a <b>secre</b>t<br />
key to encrypt the hash. By its very definition, secret key is common to both<br />
Sam &amp; Tom. So Tom can use the secret key at his end and get back the hash.<br />
The code thus generated by mixing the hash and the secret key is known <span class="GramE">as <b><span></span>MAC</b></span>.<br />
Digital Signature is better than MAC because it does not need any &#039;secret&#039; key.<br />
In the context of E-Commerce, where there are thousands of <span class="GramE">parties<br />
,</span> secret key administration is always very difficult.<b></b></span></p>
<p class="MsoNormal"><b><span>&#8212;&#8211;</span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span><span></span></span><span>The scheme<br />
outlined above is suitable for most purposes. However, for very large amounts<br />
of data, encryption and decryption of <span class="GramE">data<span></span>by</span> public-key systems becomes<span></span>time consuming and requires large resources.<br />
In such cases, it is preferred to use Symmetric Encryption systems with some<br />
modifications. <b>Hybrid </b>Systems make use <span class="GramE">of<span></span>Asymmetric</span> method for agreeing upon a<br />
secret key and the actual encryption and decryption of <b>data</b> is done by<br />
this <b>secret</b><span class="SpellE">key.Some</span> such method<span></span>is the usual Industrial practice. The Secret <span class="GramE">key<span></span>used</span> here is<br />
valid only for a particular instance of transmission of message and so is<br />
usually called &#039;<b>session-key&#039;</b>. <span class="GramE">( This</span> is not the<br />
&#039;session&#039; as usually understood in <span class="SpellE">servlets</span>, because<br />
this is an one-time operation).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><b><span>Digital<br />
Envelope</span></b></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span><span></span>An illustration of Hybrid method is a Digital<br />
Envelope. In this scheme, Sam encrypts the message by a <b>random Secret key, </b><span class="GramE">( known</span> as DEK <span class="SpellE">i.e.Data</span>-Encryption-key<span></span>or session key).Next Sam encrypts this<br />
session key with <b>Tom&#039;s public key</b>. At this stage, Sam sends both the<br />
encrypted <b>message</b> and the encrypted <b>session key </b>to Tom.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>At the receiving end, Tom uses his private<br />
key to get the session key. Using this session key, Tom decrypts the <span class="SpellE">message.As</span> Symmetric method is about <b>1000 times </b>faster<br />
<span class="GramE">than<span></span>Asymmetric</span><br />
method , this is a good combination. Though public key method also has been<br />
used here, it is only for encrypting the session key and not the message.<span></span>This can be further improved by creating a<br />
hash of the message and <span class="SpellE">sigining</span> it. Also, there is<br />
no permanent Secret key <span class="GramE">between<span></span>Sam</span> &amp; Tom,<span></span>and the required secret key is produced just<br />
as required and then discarded after the job. Thus, the method is fast and secure.<br />
</span></p>
<p class="MsoNormal"><span>&#8212;</span></p>
<p class="MsoNormal"><span><span></span>With this background information, let us now<br />
see some simple code <span class="SpellE">examples<span class="GramE">,specific</span></span><br />
to JDK.</span></p>
<p class="MsoNormal"><span>&#8211;</span></p>
<p class="MsoNormal"><span>There are<br />
a number <span class="GramE">of<span></span>Cryptographic</span> Engines in <span class="SpellE">SunJCA</span> &amp; <span class="SpellE">SunJCE</span>. They are listed below.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>It<br />
will be immediately evident that the names will <span class="GramE">be<span></span>Greek</span> &amp; Latin to us , unless we<br />
have a background in Crypto terminology. That is why, a broad outline was<br />
given. The function of some of the engines will be evident from the earlier<br />
discussion. A few more of the remaining items will be clear when we deal with<br />
code examples.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span><span></span></p>
<p class="MsoNormal"><span><span></span><b>Cryptographic<br />
Engines</b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span>1)<b><span class="SpellE">KeyGenerator</span><span class="GramE">( symmetric</span>)</b></span></p>
<p class="MsoNormal"><span><span></span>(Blowfish, DES<span class="GramE">,<span></span><span class="SpellE">TripleDES</span></span>,<span></span>HmacMD5, </span></p>
<p class="MsoNormal"><span><span></span>HmacSHA1<span class="GramE">,RC5</span>)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>2) <span class="SpellE"><b>KeyPairGenerator</b></span><b><span class="GramE">( asymmetric</span>)</b></span></p>
<p class="MsoNormal"><span><span></span>(<span class="SpellE">DiffieHellman</span>,<br />
DSA, RSA)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>3) <b>Mac <span class="GramE">( message</span> authentication code)</b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( HmacMD5</span>,<br />
HmacSHA1)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>4) <span class="SpellE"><b>MessageDigest</b></span><b></b></span></p>
<p class="MsoNormal"><span><span></span>(MD5,<span></span>SHA1)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>5) <b>Signature</b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span class="GramE"><span>(<br />
MD5withRSA</span></span><span>,<br />
SHA1withRSA, SHA1withDSA)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>6) <b>Cipher</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( Blowfish</span>, DES, <span class="SpellE">TripleDES</span> etc)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>7) <span class="SpellE"><b>CertificateFactory</b></span><b><span></span></b><span></span></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( X509</span>)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>8)<b><span class="SpellE">KeyAgreement</span></b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( <span class="SpellE">DiffieHellman</span></span>)</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>9)<span></span><span class="SpellE"><b>KeyFactory</b></span><b></b></span></p>
<p class="MsoNormal"><span>10) <span class="SpellE"><b>SecretKeyFactory</b></span><b></b></span></p>
<p class="MsoNormal"><span>11) <span class="SpellE"><b>SecureRandom</b></span><b></b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( SHA1PRNG</span>)</span></p>
<p class="MsoNormal"><span><span></span>(<span class="SpellE"><span class="GramE">ie</span></span>)</span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( SHA1</span> ..<span class="GramE">pseudo-random-number-generator</span>)</span></p>
<p class="MsoNormal"><span>12) <span class="SpellE"><b>TrustManagerFactory</b></span><b></b></span></p>
<p class="MsoNormal"><span>13) <span class="SpellE"><b>KeyManagerFactory</b></span><b></b></span></p>
<p class="MsoNormal"><span>14) <span class="SpellE"><b>KeySore</b></span><b></b></span></p>
<p class="MsoNormal"><span><span></span><span class="GramE">( JKS</span>, PHCS12)</span></p>
<p class="MsoNormal"><span>15) <span class="SpellE"><b>SSLContext</b></span><b></b></span></p>
<p class="MsoNormal"><span>16) <span class="SpellE"><b>AlgorithmParameterGenerator</b></span><b></b></span></p>
<p class="MsoNormal"><b><span>17) <span class="SpellE">AlgorithmParameters</span></span></b></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>Let us now<br />
see a series of code-examples to get familiarity with some of the above<br />
engines. For all the examples, we are using <b>JDK1.4.2</b>. Our working<br />
directory is </span></p>
<p class="MsoNormal"><span>g:securitydemos.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="SpellE"><span class="GramE"><span>cd</span></span></span><span> to g:securitydemos</span></p>
<p class="MsoNormal"><span>We should<br />
set <b>path </b><span class="GramE">as :</span></span></p>
<p class="MsoNormal"><span>c:windowscommand;d:<b>jdk1.4.2</b>bin</span></p>
<p class="MsoNormal"><span>&#8211;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The easiest to understand is the <span class="SpellE"><b>MessageDigest</b></span><b>. &quot;</b>demo1.java<span class="GramE">&quot;<span></span>creates</span> the <span class="SpellE">messagedigest</span> of the string s1, by <b><span></span>SHA </b>method(Secure Hash Algorithm) . The<br />
given string is first converted into a byte array, because the function <span class="SpellE"><span class="GramE"><b>md.digest</b></span></span><span class="GramE"><b>(</b></span><b>),<br />
</b>accepts only a <span class="SpellE">bytearray.<b>md.update</b></span><b>() </b>simply<br />
adds the array to existing <span class="SpellE">arrays,if</span> any. The digest<br />
object thus created is simply saved as object to the file. </span></p>
<p class="MsoNormal"><span>*******************************************</span></p>
<p class="MsoNormal"><span>/<span class="GramE">/ <b><span></span>demo1.java</b></span></span><b><span><span></span></span></b><span></span></p>
<p class="MsoNormal"><span>//<br />
creation of message-digest</span></p>
<p class="MsoNormal"><span>//<br />
storing the string &amp; digest in file</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span class="GramE"><span>import</span></span><span><span class="SpellE">java.io</span>.*;</span></p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fjava-j2ee%2Fjca%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/java-j2ee/jca/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/java-j2ee/jca/feed/" data-count="vertical" data-text="JCA" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/05/java-security-packages-using-jcajce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>J2EE Connector Architecture(JCA), An Introduction</title>
		<link>http://www.javabeat.net/2007/07/j2ee-connector-architecturejca-an-introduction/</link>
		<comments>http://www.javabeat.net/2007/07/j2ee-connector-architecturejca-an-introduction/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 01:47:30 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java / J2EE]]></category>
		<category><![CDATA[JCA]]></category>
		<category><![CDATA[J2EE Connector Architecture (JCA)]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=57</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction JCA, the J2EE Connector Architecture, is an initiative towards EAI, Enterprise Application Integration. It is a standardized architecture providing the J2EE Components to have plug and play access to heterogeneous EIS, Enterprise Information Systems. Examples of EIS are ERP (Enterprise Resource Planning), Transaction Processing Systems, Legacy Database Systems etc. In the following section we [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Introduction</h2>
<p><strong><em>JCA, the J2EE Connector Architecture</em></strong>, is an initiative towards <strong><em>EAI, Enterprise Application Integration</em></strong>. It is a standardized architecture providing the J2EE Components to have plug and play access to heterogeneous <strong><em>EIS, Enterprise Information Systems</em></strong>. Examples of EIS are <strong><em>ERP (Enterprise Resource Planning), Transaction Processing Systems, Legacy Database Systems</em></strong> etc. In the following section we will discuss about the major problems that the programmers had to face for the EIS Integration and the role of JCA.</p>
<h2>EIS Integration</h2>
<p>An Enterprise Information System provides the information infrastructure for an enterprise. This information may be in the form of records in the database, business objects in an ERP, a workflow object in a <strong><em>Customer Relationship Management (CRM) System</em></strong> or a transaction program in a transaction processing application. Prior to the Internet economy, many companies had heavily invested in <strong><em>Business and Management Information Applications Systems.</em></strong></p>
<p>Examples of such systems can be:-</p>
<ul>
<li>ERP, Enterprise Resource Planning applications, such as SAP, BAAN etc.</li>
<li>CRM, Customer Relationship Management applications, such as Seibel and Clarify.</li>
<li>Database applications such as DB2 and Sybase.</li>
<li>Main Transaction processing applications, such as CICS.</li>
<li>Legacy Database Systems such as IBM’s IMS.</li>
</ul>
<p>Before the JCA, most vendors supported a variety of custom adapters for integrating their EIS. Basically these adapters provided custom native interfaces, which were complex to incorporate and limited to only one EIS. Because of this the application programmers had to deal with as many adapters as the number of EIS their application communicates to. Some of the limitations are listed below:-</p>
<ol>
<li>Application programming for the EIS was proprietary in nature, because there was no generic platform for integration with the open architectures.</li>
<li>Custom adapters lacked support for <strong><em>Connection Management</em></strong>, which is very crucial for large scale Web Applications, where thousands of customers interact every second. Because of which programmers had to implement connection pooling in their code which is a shear waste of time and money of the enterprises.</li>
<li>There was no standard infrastructure solution available to provide a vendor-neutral <strong><em>Security Mechanism and Generic Transaction Mechanism</em></strong> support to multiple EIS resource managers.</li>
</ol>
<p>In order to address the above problems Sun Microsystems released the <strong><em>J2EE Connector Architecture, JCA</em></strong> that provides a standard architecture for integration of J2EE Servers with heterogeneous EIS resources. It provides a common API and a common set of services within a consistent J2EE Environment.</p>
<p>The following diagram shows the J2EE application server with the JCA Components and some Enterprise Information Systems:-</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_1.jpg"><img class="aligncenter size-medium wp-image-2276" title="JCA__image_1" alt="" src="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_1-278x300.jpg" width="278" height="300" /></a></p>
<p>In the above diagram, there is a Web Container and an EJB Container in the J2EE Application Server. There are also some blocks for Resource Adapters. Resource adapters play the role of intermediaries between the J2EE Application / Web Components and the EIS. The programmers communicate with the Resource Adapters using the <strong><em>CCI API, Common Client Interface API</em></strong>. This is very similar to the JDBC API where the J2EE Components communicate with the relational database drivers using the JDBC API.</p>
<p>In this architecture, the J2EE Application Server implements the JCA Services like <strong><em>Connection Management, Transaction Management and Security Management </em></strong>etc. Whereas the EIS vendors implements the <strong><em>Resource Adapters</em></strong> specific to their products. This way the programmers need to code their programs in vendor neutral manner to communicate with heterogeneous EIS resources from different vendors.</p>
<h2>Elements of the J2EE Connector Architecture</h2>
<p>The JCA is implemented by J2EE compliant Application Servers and the Resource Adapters are provided by the EIS vendors.<br />
The Resource Adapter is an EIS specific, pluggable J2EE Component in the Application Server, which provides an interface for the J2EE Components to communicate with the underlying EIS.</p>
<p>There are the following elements and Services in a JCA implementation:-</p>
<ol>
<li><strong>System-level Services</strong>: &#8211; It defines the standard interface between the J2EE Components and the J2EE Aplication Server provider and the EIS Vendor. This contract specifies the roles and responsibilities of the Resource Adapter and the Application Server, so that they can co-ordinate with each other for the System level services like Connection Pooling, Security and Transactions. Furthermore this allows for any JCA compliant Resource Adapter to be pluggable to any J2EE Compliant Application Server.</li>
<li><strong>CCI, Common Client Interface:</strong> &#8211; This is an API which is used by the J2EE Components and other non managed Java Applications (like standalone Java programs and Java Applets) to communicate with the Resource Adapters, which in turn communicate to the underlying EIS.</li>
<li><strong>Packaging and Deployment Interfaces: </strong>- Packaging and Deployment Interfaces allow the Resource Adapters to be able to plug into any Application Server.</li>
</ol>
<p>The following diagram shows all the components of the J2EE Connector Architecture. It shows how the components communicate with each other.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_2.jpg"><img class="aligncenter size-medium wp-image-2277" title="JCA__image_2" alt="" src="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_2-300x222.jpg" width="300" height="222" /></a></p>
<p><strong><em>The CCI, Common Client Interface</em></strong> is part of the implementation of the Resource Adapters. The J2EE components use this API in order to communicate with the underlying EIS resource. Because of the System Level contracts the J2EE Application Servers provide the services like Connection Pooling, Transaction Management and Security Management and the programmers can stay away from the implementation of these services.</p>
<p>There are two types of environments based on the type of client application using the Resource Adapter. These are: -</p>
<ul>
<li><strong>Managed Environment: </strong>- This includes the multi tired J2EE based Web Applications that may have several Web / Application Components communicating to the Resource Adapters. Such applications are called as the Managed Applications in the JCA context.</li>
<li><strong>Non-Managed Environment: </strong>- In a two tired architecture, where the application client directly uses the application, the Resource Adapter provides the system level services to its clients. Such applications are referred as Non Managed applications.</li>
</ul>
<h2>Resource Adapter</h2>
<p>The Resource Adapter is a component in the J2EE Connector Architecture that sits between the J2EE Components and the EIS. This module is implemented with the EIS specific library, which can be written in Java or with native interface components. Basically it implements two things, first is the Common Client Interface, CCI so that when the developers invoke the methods of this library in their code, the invocations can be resolved by the implementations inside the Resource Adapter, and second is the implementation of the functionality through which it connects to the underlying EIS resource and get the work done for the method invocations. The Resource Adapters are required to support the System Level contracts as is required by the Application Servers. There are mainly two types of contracts that a Resource Adapter implements in order to get compliant with the JCA. These are: -</p>
<ul>
<li><strong>Application-Level Contracts: </strong>- Application Contract basically defines the CCI that the Resource Adapter must implement in order for the J2EE Components and the non-managed components to communicate to the underlying EIS resource.</li>
<li><strong>System-Level Contracts: </strong>- This defines a set of System Contracts which enable the Resource Adapter to plug-in into the Application Server and utilize its services to manage connections, transactions and Security. The three basic contracts are discussed below: -
<ul>
<li><strong>Connection Management: </strong>- The Connection Management contract specifies the following things: -
<ol>
<li>Connection to the Resource Adapters for managed and non-managed components can be made by using consistent application programming techniques, which remain same every time.</li>
<li>The Resource Adapter provides the Connection Factory and Connection Interface based on the CCI, which in turn is specific to the EIS.</li>
<li>Provide a generic mechanism for the J2EE components to consume the Application Server services like Transaction, Security and last but not the least the Connection Pooling etc.</li>
</ol>
</li>
<li><strong>Transaction Management: </strong>- This contract extends the Application Server&#8217;s transactional capabilities to the underlying EIS Resource Managers. An EIS Resource Manager manages a set of shared EIS resources to participate in a transaction. It can manage the following two types of transactions: -
<ol>
<li><strong>XA Transaction: </strong>- XA Transactions are controlled and coordinated by external Transaction Managers. A JTA XATransaction Management contract exists between the JCA compliant Resource Adapters and its underlying Resource Manager. The participating EIS resource also supports XA Transactions by implementing an XAResource in their Resource Adapter. The JTA XAResource interface enables two resource managers to participate in transactions coordinated by an external Transaction Manager. This allows the transactions to be managed by a transaction manager which is external to the Resource Adapter.</li>
<li><strong>Local Transactions: </strong>- These transactions do not require any external Transaction Manager, because it is managed internally, either by the J2EE Application Server (container managed) or by the J2EE component (component managed). In Component Managed Transactions the component uses JTA UserTransaction interface or a transaction API specific to the EIS. When an application component requires an EIS Connection, the Application Server starts a local transaction using the currently available transaction context. Upon closure of the connection by the application component, the server commits or rolls back depending upon success or failure of the transaction.</li>
</ol>
</li>
<li>Security Management:- This contract defines ways to implement security between the Application Server and the EIS resource. There are the following mechanisms used to protect the EIS against unauthorized access and other security threats: -
<ol>
<li>Use of user identification, authentication and authorization.</li>
<li>Use of open network communication security protocols like Kerberos which provide end to end security with authentication and confidentiality services.</li>
<li>Implementing an EIS specific security Service.</li>
</ol>
</li>
</ul>
</li>
</ul>
<h3>EIS Sign-On</h3>
<p>A Sign-on process is required while creating a new connection to EIS. Based on the security context, authentication and authorization is done for the user to obtain appropriate access. A re-authentication is required in case the Security Context is changed for the user. The following steps are required for sign on: -</p>
<ol type="a">
<li>Identity of the initiating user, or <strong><em>Resource Principal</em></strong>, is determined. This helps finding the security context of the user using which the connection will be established to the EIS.</li>
<li>Resource Principal is authenticated if the connection is not already authenticated.</li>
<li>Establish a secure connection between the Application Server and the EIS Resource using secure mechanisms like SSL or Kerberos etc. At this point the connection is associated with the initiating user. All subsequent invocations will happen under this context.</li>
</ol>
<p>This sign-on process can be Application Managed or it can be Container Managed. In case of Application Managed sign-on process, the application component itself provides the security credentials to the EIS Resource Adapter. While in the later case it becomes the duty of the application to find out the Resource Principal of the initiating user and present information of this Resource Principal to the EIS Resource Adapter in the form specific to the <strong><em>JAAS, Java Authentication and Authorization Service</em></strong>.</p>
<h2>Packaging and Deploying a Resource Adapter</h2>
<p>The Resource Adapters module is packaged as a .rar file, similar to the .ear files for the J2EE Application Modules. There are proper deployment and packaging interfaces that allow a Resource Adapter to plug-in to any J2EE compliant Application Server. The following diagram illustrates the process of packaging and deployment of Resource Adapters module into the Application Server.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_3.jpg"><img class="aligncenter size-medium wp-image-2275" title="JCA__image_3" alt="" src="http://www.javabeat.net/wp-content/uploads/2007/07/JCA__image_3-300x222.jpg" width="300" height="222" /></a></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>The exact steps involved in packaging and deployment are listed below: -</p>
<ol>
<li>The EIS Resource Adapter provider, usually the EIS Vendor, implements the Resource Adapter as a set of Interfaces and utility classes implementing the CCI API and the EIS functionality. These implementations take care of the JCA contracts that the Resource Adapter need to follow for JCA compliance.</li>
<li>All the components of the Resource Adapter, including the source files are packaged into a .rar file, called as <strong><em>Resource Adapter Module</em></strong>. The deployment descriptor of the Resource Adapter specifies the contract between the Resource Adapter provider and the one who deploys the Resource Adapter.</li>
<li>In the actual deployment process the Resource Adapter is deployed in the Application Server and then it is configured with the Application Server and the underlying EIS environment.</li>
</ol>
<p>Lets now discuss these steps in greater detail: -</p>
<h3>Packaging a Resource Adapter</h3>
<p>The Resource Adapters are proper J2EE components packaged in .rar files. One or more Resource Adapters can be staged in one directory and then packaged as .rar files. The following steps are usually involved for packaging a Resource Adapter: -</p>
<ol>
<li>Compile the Resource Adapter Java files into a staging directory.</li>
<li>Create a .jar file to add the class files created in the above step.</li>
<li>Create an ra.xml deployment descriptor file in the META-INF subdirectory. Add entries for the Resource Adapter.</li>
<li>Create a J2EE Application Server specific deployment descriptor in the same directory and add the entries for the Resource Adapter.</li>
<li>Create the Resource Adapter module .rar file by executing the following command: -</li>
</ol>
<pre class="brush: java; title: ; notranslate">&lt;code&gt;      jar cvf JavaBeatResourceAdapter.rar -C staging-dir&lt;/code&gt;</pre>
<p>Now this .rar file can be deployed to the Application Server or packaged inside an application&#8217;s .jar file. The packaged Resource Adapter includes the following: -</p>
<ol>
<li>Java Classes and Interfaces that implement the functionality of the JCA contract and the underlying EIS resource.</li>
<li>Some helper classes used by main implementation classes.</li>
<li>Platform dependent native libraries required by the Resource Adapter.</li>
<li>Meta information about the above elements.</li>
<li>Documentation.</li>
</ol>
<p>After installation of the .rar file, the directory structure of the Application Server looks like the following: -</p>
<pre class="brush: java; title: ; notranslate">&lt;code&gt; \AppServerHomeDir
 \config
 \JavaBeatDomain
 \applications
 \JavaBeatResourceAdapter.rar &lt;/code&gt;</pre>
<p>There are basically two deployment descriptors packaged within a .rar file of the <strong><em>Resource Adapter Module</em></strong>. These are the ra.xml, which specifies the general information about the Resource Adapter, and the ABCAppServer.xml, which specifies operational parameters required for the Application Server.</p>
<h3>Ra.xml, the Resource Adapter deployment descriptor</h3>
<p>Following is a deployment descriptor for an ABC Resource Adapter, we will discuss about all the xml elements in this file after this example: -</p>
<pre class="brush: java; title: ; notranslate">&lt;connector&gt;

&lt;display-name&gt;ABCResourceAdapter&lt;display-name&gt;
&lt;vendor-name&gt;Java Beat&lt;/vendor-name&gt;
&lt;spec-version&gt;1.0&lt;/spec-version&gt;
&lt;eis-type&gt;JDBC Database&lt;/eis-type&gt;
&lt;version&gt;1.5&lt;/version&gt;

&lt;resourceadapter&gt;

&lt;managedconnectionfactory-class&gt;com.sun.connector.javabeat.NoTxManagedConnectionFactory&lt;/managedconnectionfactory-class&gt;
&lt;connectionfactory-interface&gt;javax.sql.Datasource&lt;/connectionfactory-interface&gt;
&lt;connectionfactory-impl-class&gt; com.sun.Connector.abc.JdbcDataSource&lt;/connectionfactory-impl-class&gt;
&lt;connection-interface&gt;java.sql.Connection&lt;/connection-interface&gt;
&lt;connection-impl-class&gt;com.sun.connector.abc.JdbcConnection&lt;/connection-impl-class&gt;
&lt;transaction-support&gt;NoTransaction&lt;/transaction-support&gt;
&lt;config-property&gt;
      &lt;config-property-name&gt;ConnectionURL&lt;/config-property-name&gt;
      &lt;config-property-type&gt;java.lang.String&lt;/config-property-type&gt;
      &lt;config-property-value&gt;jdbc:cloudspace:rmi:CloudscapeDB:create=true&lt;/config-property-value&gt;
&lt;/config-property&gt;
&lt;authentication-mechanism&gt;
      &lt;authentication-mechanism-type&gt;BasicPassword&lt;/authentication-mechanism-type&gt;
      &lt;credential-interface&gt;javax.resource.security.PasswordCredential&lt;/credential-interface&gt;
&lt;/authentication-mechanism&gt;
&lt;reauthentication-support&gt;false&lt;/reauthentication-support&gt;

&lt;/resourceadapter&gt;

&lt;/connector&gt;</pre>
<p>The first block of the descriptor is:-</p>
<pre class="brush: java; title: ; notranslate">&lt;display-name&gt;ABCResourceAdapter&lt;display-name&gt;
&lt;vendor-name&gt;Java Beat&lt;/vendor-name&gt;
&lt;spec-version&gt;1.0&lt;/spec-version&gt;
&lt;eis-type&gt;JDBC Database&lt;/eis-type&gt;
&lt;version&gt;1.5&lt;/version&gt;</pre>
<p>It lists general information about the Resource Adapter, like its name, Vendor&#8217;s name, specification version, the type of the EIS resource that this Adapter is representing and the version of the JCA supported.</p>
<p>Then the name of the class that implements the javax.resource.spi.ManagedConnectionFactory interface is listed in the element.</p>
<p>The ConnectionFactory interface and the implementation class are mentioned thereafter in the following block of the descriptor:-</p>
<pre class="brush: java; title: ; notranslate">&lt;connectionfactory-interface&gt;javax.sql.Datasource&lt;/connectionfactory-interface&gt;
&lt;connectionfactory-impl-class&gt; com.sun.Connector.abc.JdbcDataSource&lt;/connectionfactory-impl-class&gt;</pre>
<p>The Connection implementation class for the java.sql.Connection interface is com.sun.connector.abc.JdbcConnection.</p>
<p>The level of transaction support can be either <em>NoTransaction</em>, or <em>LocalTransaction</em> or <em>XATransaction</em>. In this example the Resource Adapter does not support transaction which is specified by the <em>NoTransaction</em> value in the<br />
element.</p>
<p>Certain properties of <em>ManagedConnectionFactory</em> can be configured by specifying a name and type of the property and then providing a value of the property as follows: -</p>
<pre class="brush: java; title: ; notranslate">&lt;config-property&gt;
      &lt;config-property-name&gt;ConnectionURL&lt;/config-property-name&gt;
      &lt;config-property-type&gt;java.lang.String&lt;/ config-property-type&gt;
      &lt;config-property-value&gt;jdbc:cloudspace:rmi:CloudscapeDB:create=true&lt;/ config-property-value&gt;
&lt;/config-property&gt;</pre>
<p>The last section of the deployment descriptor specifies the authentication mechanisms supported by the Resource Adapter provider. In this case only <em>BasicPassword</em> method is supported. The Security Credential interface is <em>javax.resource.security.PasswordCredential</em>. There is no re-authentication support with this Resource Adapter.</p>
<pre class="brush: java; title: ; notranslate">&lt;authentication-mechanism&gt;
      &lt;authentication-mechanism-type&gt;BasicPassword&lt;/authentication-mechanism-type&gt;
      &lt;credential-interface&gt;javax.resource.security.PasswordCredential&lt;/credential-interface&gt;
&lt;/authentication-mechanism&gt;
&lt;reauthentication-support&gt;false&lt;/reauthentication-support&gt;</pre>
<p>The Resource Adapter can be deployed in two ways as discussed below: -</p>
<ol>
<li>By using the deploytool command line or the deploytool UI console using the following command: -
<ul>
<li>
<pre class="brush: java; title: ; notranslate">Deploytool -deployConnector %J2EE_HOME%\lib\connector\abc-ra.rar &lt;HostName&gt;</pre>
</li>
</ul>
</li>
<li>Deploying as a Web Application archive file, i.e. .ear file. In this method the .rar file is included into the .ear file just as we include a .jar or .war file in it. And then the .ear file is deployed in the Application Server. To identify the .rar module in the package the following line is added into the application.xml file: -
<ul>
<li>
<pre class="brush: java; title: ; notranslate">&lt;connector&gt;abcresourceadapter.rar&lt;/connector&gt;</pre>
</li>
</ul>
</li>
</ol>
<h2>JCA Advantages</h2>
<p>J2EE Connector Architecture has emerged as the primary technology for providing a vendor neutral platform for the programmers to communicate with multiple EIS resources without changing their components at all. There are the following scenarios in which the technology offers a potential solution: -</p>
<ol>
<li><strong>Enterprise Application Integration:</strong> &#8211; While integrating multiple EIS applications there are many challenges that need to be taken care of. These include, transaction, security and scalability issues. Multiple EIS vendors providing their own proprietary APIs for integration, which creates much bigger problem of embedding code specific to each vendor into the application components. But with the JCA technology, the EIS vendors are now required to provide with a Resource Adapters obeying the JCA contracts. And the programmers need to understand just the CCI API, required to communicate with the similar Resource Adapter of all the different EIS resources.</li>
<li><strong>Web-Enabled Enterprise Portals:</strong> &#8211; Enterprise portals usually unifies all the information, services, applications and processes for all the members of an enterprise, including the employees, clients, partners and customers etc. Such a portal needs to integrate all the heterogeneous EIS resources, such as database systems, information systems etc. which handle all information of the enterprise. In such a scenario the JCA technology solves the problem by seamlessly integrating the different EIS resources by introducing the concept of Resource Adapters and the CCI API. It also helps by providing the EIS sign-on mechanism that supports generic and application specific authentication mechanism.</li>
<li><strong>Business to Business Integration:</strong> &#8211; Business to Business integration requires end-to-end process automation and allows application interaction with an enterprise and across partners through the internet. In order to support the external partner interactions, the backend internal business systems need to be seamlessly integrated into the same process. With the help of JCA the backend EIS resources and end to end processes can be integrated without much difficulty.</li>
</ol>
<h2>Summary</h2>
<p>In this article we discussed about the concept of JCA, J2EE Connector Architecture, how it helps in solving the problems faced in EAI, Enterprise Application Integration, by introducing the concept of Resource Adapters, and the CCI API to facilitate communication between the J2EE Application Components and the underlying EIS, Enterprise Information Systems. We also discussed about the deployment details of the Resource Adapters by looking into two main deployment descriptors required in the process.</p>
<p>This technology is aimed to solve the problems and challages that the industry face while working with heterogeneus EIS, Enterprise Information Systems. In the next article we will discuss about this technology in more detail, which would be aimed at professional programmers in the J2EE domain.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2007/07/j2ee-connector-architecturejca-an-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
