PageRenderTime 28ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/src/j2eetutorial14/doc/Security8.html

https://github.com/dtolabs/dukesbank
HTML | 175 lines | 141 code | 8 blank | 26 comment | 0 complexity | 95b012af0f61ce060269c4afbf1df841 MD5 | raw file
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  6. <meta http-equiv="Content-Style-Type" content="text/css" />
  7. <title>EJB-Tier Security</title>
  8. <link rel="StyleSheet" href="document.css" type="text/css" media="all" />
  9. <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" />
  10. <link rel="Table of Contents" href="J2EETutorialTOC.html" />
  11. <link rel="Previous" href="Security7.html" />
  12. <link rel="Next" href="Security9.html" />
  13. <link rel="Index" href="J2EETutorialIX.html" />
  14. <!--[if gte IE 5.5000]>
  15. <script language="JavaScript">
  16. function correctPNG() { // correctly handle PNG transparency in Win IE 5.5 or higher.
  17. for(var i=0; i<document.images.length; i++) {
  18. var img = document.images[i]
  19. var imgName = img.src.toUpperCase()
  20. if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
  21. var imgID = (img.id) ? "id='" + img.id + "' " : ""
  22. var imgClass = (img.className) ? "class='" + img.className + "' " : ""
  23. var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
  24. var imgStyle = "display:inline-block;" + img.style.cssText
  25. if (img.align == "left") imgStyle = "float:left;" + imgStyle
  26. if (img.align == "right") imgStyle = "float:right;" + imgStyle
  27. if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
  28. var strNewHTML = "<span " + imgID + imgClass + imgTitle
  29. + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
  30. + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
  31. + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
  32. img.outerHTML = strNewHTML
  33. i = i-1
  34. }
  35. }
  36. }
  37. window.attachEvent("onload", correctPNG);
  38. </script>
  39. <![endif]-->
  40. </head>
  41. <body>
  42. <div id="header">
  43. <img src="images/tutorialTitle.png" width="154" height="50" alt="The J2EE(TM) 1.4 Tutorial"/>
  44. <div class="navigation">
  45. <a accesskey="p" href="Security7.html" title="Previous"><img id="LongDescNotReq1" src="images/previous.png" width="40" height="40" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html" title="Beginning"><img id="LongDescNotReq1" src="images/up.png" width="40" height="40" border="0" alt="Beginning" /></a><a accesskey="n" href="Security9.html" title="Next"><img id="LongDescNotReq3" src="images/next.png" width="40" height="40" border="0" alt="Next" /></a>
  46. </div>
  47. <div id="header-links">
  48. <a href="index.html" target="_blank">Home</a> | <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> | <a href="J2EETutorial.pdf" target="_blank">PDF</a> | <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> | <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> | <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> | <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a> | <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>
  49. </div>
  50. </div>
  51. <blockquote>
  52. <a name="wp474732"> </a><h2 class="pHeading1">
  53. EJB-Tier Security
  54. </h2>
  55. <a name="wp474733"> </a><p class="pBody">
  56. The following sections describe declarative and programmatic security mechanisms that can be used to protect resources in the EJB tier. The protected resources include methods of enterprise beans that are called from application clients, web components, or other enterprise beans.
  57. </p>
  58. <a name="wp474735"> </a><p class="pBody">
  59. You can protect EJB tier resources by doing the following:
  60. </p>
  61. <div class="pSmartList1"><ul class="pSmartList1">
  62. <a name="wp474736"> </a><div class="pSmartList1"><li>Declaring method permissions</li></div>
  63. <a name="wp474737"> </a><div class="pSmartList1"><li>Mapping roles to J2EE users and groups</li></div>
  64. </ul></div>
  65. <a name="wp474740"> </a><p class="pBody">
  66. For information about mapping roles to J2EE users and groups, see <a href="Security3.html#wp500172">Mapping Roles to Users and Groups</a>.
  67. </p>
  68. <a name="wp474742"> </a><h3 class="pHeading2">
  69. Declaring Method Permissions
  70. </h3>
  71. <a name="wp474746"> </a><p class="pBody">
  72. After you've defined the roles (see <a href="Security3.html#wp478265">Setting Up Security Roles</a>), you can define the method permissions of an enterprise bean. Method permissions indicate which roles are allowed to invoke which methods. You can define method permissions in various ways.
  73. </p>
  74. <div class="pSmartList1"><ul class="pSmartList1">
  75. <a name="wp474748"> </a><div class="pSmartList1"><li>You can apply method permissions to all the methods of the specified enterprise bean's home, component, and web service endpoint interfaces.</li></div>
  76. <a name="wp474749"> </a><div class="pSmartList1"><li>You can apply method permissions to the specified method of the enterprise bean. If the enterprise bean contains multiple methods having the same method name, the method permission applies to all the methods.</li></div>
  77. <a name="wp474750"> </a><div class="pSmartList1"><li>If the enterprise bean contains multiple methods having the same method name but the methods have different method parameters (such as <code class="cCode">create(a,b)</code> and <code class="cCode">create(a,b,c)</code>), you can apply method permissions by specifying the method parameters.</li></div>
  78. </ul></div>
  79. <a name="wp474761"> </a><p class="pBody">
  80. In general, use <code class="cCode">deploytool</code> to specify method permissions by mapping roles to methods:
  81. </p>
  82. <div class="pSmartList1"><ol type="1" class="pSmartList1">
  83. <a name="wp474762"> </a><div class="pSmartList1"><li>Select the enterprise bean.</li></div>
  84. <a name="wp474763"> </a><div class="pSmartList1"><li>Select the Security tab.</li></div>
  85. <a name="wp474764"> </a><div class="pSmartList1"><li>Select the interface type (local, local home, remote, or remote home). The table displays methods contained in the selected interface. If no interfaces have been defined, the interface buttons will be disabled.</li></div>
  86. <a name="wp474765"> </a><div class="pSmartList1"><li>In the Method Permissions table, select the method for which you want to specify permissions.</li></div>
  87. <a name="wp515772"> </a><div class="pSmartList1"><li>In the Availability column for that method, select Sel Roles from the drop-down list for that method.</li></div>
  88. <a name="wp474766"> </a><div class="pSmartList1"><li>Select a role's checkbox if that role should be allowed to invoke a method.</li></div>
  89. </ol></div>
  90. <a name="wp474767"> </a><h3 class="pHeading2">
  91. Configuring IOR Security
  92. </h3>
  93. <a name="wp474768"> </a><p class="pBody">
  94. Enterprise beans that are deployed in one vendor's server product are often accessed from J2EE client components that are deployed in another vendor's product. Common Secure Interoperability version 2 (CSIv2), a CORBA/IIOP-based standard interoperability protocol, addresses this situation by providing authentication, protection of integrity and confidentiality, and principal propagation for invocations on enterprise beans, where the invocations take place over an enterprise's intranet.
  95. </p>
  96. <a name="wp474769"> </a><p class="pBody">
  97. CSIv2 configuration settings are specified in the Interoperable Object Reference (IOR) of the target enterprise bean. In the IOR security configuration dialog box, you can specify the security information for the IOR.
  98. </p>
  99. <a name="wp474770"> </a><p class="pBody">
  100. To get to the IOR security configuration dialog box, select the enterprise bean to which you want to add the settings in the <code class="cCode">deploytool</code> tree view. From the General tabbed pane, select Sun-specific Settings. In the General subpane of the EJB Settings pane, press the IOR button.
  101. </p>
  102. <a name="wp474771"> </a><p class="pBody">
  103. In the Transport Configuration subpane are the following fields:
  104. </p>
  105. <div class="pSmartList1"><ul class="pSmartList1">
  106. <a name="wp474772"> </a><div class="pSmartList1"><li>The Integrity field specifies whether the target supports integrity-protected messages for transport.</li></div>
  107. <a name="wp474773"> </a><div class="pSmartList1"><li>The Confidentiality field specifies whether the target supports privacy-protected messages (SSL) for transport.</li></div>
  108. <a name="wp474774"> </a><div class="pSmartList1"><li>The Establish Trust In Target field specifies whether or not the target component is capable of authenticating to a client for transport. It is used for mutual authentication (to validate the server's identity).</li></div>
  109. <a name="wp474775"> </a><div class="pSmartList1"><li>The Establish Trust In Client field specifies whether or not the target component is capable of authenticating a client for transport (target asks the client to authenticate itself).</li></div>
  110. </ul></div>
  111. <a name="wp474776"> </a><p class="pBody">
  112. In each of these fields, you can select whether the item is supported, required, or not activated (none).
  113. </p>
  114. <a name="wp474777"> </a><p class="pBody">
  115. In the As Context subpane, do the following:
  116. </p>
  117. <div class="pSmartList1"><ol type="1" class="pSmartList1">
  118. <a name="wp474778"> </a><div class="pSmartList1"><li>Use the Required drop-down list to identify whether the authentication method specified is required to be used for client authentication. Setting this field to <code class="cCode">true</code> indicates that the authentication method specified is required. Setting this field to <code class="cCode">false</code> indicates that the method authentication is not required.</li></div>
  119. <a name="wp474779"> </a><div class="pSmartList1"><li>Use the Authorization Method drop-down list to authenticate the client. The only supported value is <code class="cCode">USERNAME_PASSWORD</code>.</li></div>
  120. <a name="wp474780"> </a><div class="pSmartList1"><li>Use the Realm field to identify the realm in which the user is authenticated.</li></div>
  121. </ol></div>
  122. <a name="wp474781"> </a><p class="pBody">
  123. In the Duke's Bank example, the As Context setting is used to require client authentication (with user name and password) when access to protected methods in the <code class="cCode">AccountControllerBean</code> and <code class="cCode">CustomerControllerBean</code> components is attempted.
  124. </p>
  125. <a name="wp474782"> </a><p class="pBody">
  126. In the Sas Context subpane, use the Caller Propagation drop-down list to identify whether or not the target component will accept propagated caller identities.
  127. </p>
  128. <a name="wp474784"> </a><p class="pBody">
  129. In the Duke's Bank example, the Sas Context setting is set to <code class="cCode">Supported</code> for the <code class="cCode">AccountBean</code>, <code class="cCode">CustomerBean</code>, and <code class="cCode">TxBean</code> components, indicating that these target components will accept propagated caller identities.
  130. </p>
  131. <a name="wp474786"> </a><h3 class="pHeading2">
  132. Using Programmatic Security in the EJB Tier
  133. </h3>
  134. <a name="wp474790"> </a><p class="pBody">
  135. Programmatic security in the EJB tier consists of the <code class="cCode">getCallerPrincipal</code> and the <code class="cCode">isCallerInRole</code> methods. You can use the <code class="cCode">getCallerPrincipal</code> method to determine the caller of the enterprise bean and use the <code class="cCode">isCallerInRole</code> method to determine whether the caller has the specified role.
  136. </p>
  137. <a name="wp474791"> </a><p class="pBody">
  138. The <code class="cCode">getCallerPrincipal</code> method of the <code class="cCode">EJBContext</code> interface returns the <code class="cCode">java.security.Principal</code> object that identifies the caller of the enterprise bean. (In this case, a principal is the same as a user.) In the following example, the <code class="cCode">getUser</code> method of an enterprise bean returns the name of the J2EE user that invoked it:
  139. </p>
  140. <div class="pPreformattedRelative"><pre class="pPreformattedRelative">
  141. public String getUser() {
  142. return context.getCallerPrincipal().getName();
  143. }<a name="wp474792"> </a>
  144. </pre></div>
  145. <a name="wp474793"> </a><p class="pBody">
  146. You can determine whether an enterprise bean's caller belongs to the <code class="cCode">Customer </code>role.
  147. </p>
  148. <div class="pPreformattedRelative"><pre class="pPreformattedRelative">
  149. boolean result = context.isCallerInRole(&quot;Customer&quot;);<a name="wp474794"> </a>
  150. </pre></div>
  151. <a name="wp474795"> </a><h3 class="pHeading2">
  152. Unauthenticated User Name
  153. </h3>
  154. <a name="wp474796"> </a><p class="pBody">
  155. Web applications accept unauthenticated web clients and allow these clients to make calls to the EJB container. The EJB specification requires a security credential for accessing EJB methods. Typically, the credential will be that of a generic unauthenticated user.
  156. </p>
  157. </blockquote>
  158. <div id="footer">
  159. <div class="navigation">
  160. <a accesskey="p" href="Security7.html" title="Previous"><img id="LongDescNotReq1" src="images/previous.png" width="40" height="40" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html" title="Beginning"><img id="LongDescNotReq1" src="images/up.png" width="40" height="40" border="0" alt="Beginning" /></a><a accesskey="n" href="Security9.html" title="Next"><img id="LongDescNotReq3" src="images/next.png" width="40" height="40" border="0" alt="Next" /></a>
  161. </div>
  162. <div id="copyright">
  163. <p>All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other works without express written permission from Sun Microsystems.</p>
  164. </div>
  165. </div>
  166. </body>
  167. </html>