samples.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" xml:id="sample-apps">
  2. <info>
  3. <title xml:id="samples">Sample Applications</title>
  4. </info>
  5. <para>
  6. There are several sample web applications that are available with the
  7. project. To avoid an overly large download, only the "tutorial"
  8. and "contacts" samples are included in the distribution file. You can
  9. either build the others yourself, or you can obtain the war files
  10. individually from the central Maven repository. We'd recommend the former.
  11. You can get the source as described in <link xlink:href="get-source">the introduction</link>
  12. and it's easy to build the project using Maven. There is more information
  13. on the project web site at
  14. <link xlink:href="http://www.springframework.org/spring-security/">
  15. http://www.springframework.org/spring-security/
  16. </link>if you need it.
  17. </para>
  18. <section xml:id="tutorial-sample">
  19. <title>Tutorial Sample</title>
  20. <para> The tutorial sample is a nice basic example to get you started. It uses
  21. simple namespace configuration throughout.
  22. </para>
  23. <para>The compiled tutorial is included in the distribution ZIP file,
  24. ready to be deployed into your web container.
  25. The <link xlink:href="#form">form-based</link>
  26. authentication mechanism is used, with the commonly-used
  27. <link xlink:href="#remember-me">remember-me</link>
  28. authentication provider used to automatically remember the login using
  29. cookies.</para>
  30. <para>We recommend you start with the tutorial sample, as the XML is
  31. minimal and easy to follow. Most importantly, you can easily add
  32. this one XML file (and its corresponding <literal>web.xml</literal> entries) to your existing
  33. application. Only when this basic integration is achieved do we
  34. suggest you attempt adding in method authorization or domain object
  35. security.</para>
  36. </section>
  37. <section xml:id="contacts-sample">
  38. <title>Contacts</title>
  39. <para>
  40. The Contacts Sample is quite an advanced example in that it
  41. illustrates the more powerful features of domain object access control lists
  42. in addition to basic application security.
  43. </para>
  44. <para>To deploy, simply copy the WAR file from Spring
  45. Security distribution into your container’s <literal>webapps</literal>
  46. directory. The war should be called <filename>spring-security-samples-contacts-2.0.0.war</filename>
  47. (the appended version number will vary depending on what release you are using).
  48. </para>
  49. <para>After starting your container, check the application can load.
  50. Visit
  51. <literal>http://localhost:8080/contacts</literal>
  52. (or whichever URL is appropriate for your web container and the WAR
  53. you deployed). </para>
  54. <para>Next, click "Debug". You will be prompted to authenticate, and a
  55. series of usernames and passwords are suggested on that page. Simply
  56. authenticate with any of these and view the resulting page. It should
  57. contain a success message similar to the following:
  58. <literallayout>
  59. Authentication object is of type: org.springframework.security.providers.UsernamePasswordAuthenticationToken
  60. Authentication object as a String:
  61. org.springframework.security.providers.UsernamePasswordAuthenticationToken@1f127853:
  62. Principal: org.springframework.security.userdetails.User@b07ed00:
  63. Username: rod; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true;
  64. credentialsNonExpired: true; AccountNonLocked: true;
  65. Granted Authorities: ROLE_SUPERVISOR, ROLE_USER; Password: [PROTECTED]; Authenticated: true;
  66. Details: org.springframework.security.ui.WebAuthenticationDetails@0:
  67. RemoteIpAddress: 127.0.0.1; SessionId: k5qypsawgpwb;
  68. Granted Authorities: ROLE_SUPERVISOR, ROLE_USER
  69. Authentication object holds the following granted authorities:
  70. ROLE_SUPERVISOR (getAuthority(): ROLE_SUPERVISOR)
  71. ROLE_USER (getAuthority(): ROLE_USER)
  72. SUCCESS! Your web filters appear to be properly configured!
  73. </literallayout>
  74. </para>
  75. <para>Once you successfully receive the above message, return to the
  76. sample application's home page and click "Manage". You can then try
  77. out the application. Notice that only the contacts available to the
  78. currently logged on user are displayed, and only users with
  79. <literal>ROLE_SUPERVISOR</literal> are granted access to delete their
  80. contacts. Behind the scenes, the
  81. <literal>MethodSecurityInterceptor</literal> is securing the business
  82. objects. </para>
  83. <para>The application allows you to modify the access control lists associated
  84. with different contacts. Be sure to give this a try and understand how
  85. it works by reviewing the application context XML files.</para>
  86. <!--
  87. TODO: Reintroduce standalone client example.
  88. <para>The Contacts sample application also includes a
  89. <literal>client</literal> directory. Inside you will find a small
  90. application that queries the backend business objects using several
  91. web services protocols. This demonstrates how to use Spring Security
  92. for authentication with Spring remoting protocols. To try this client,
  93. ensure your servlet container is still running the Contacts sample
  94. application, and then execute <literal>client rod koala</literal>. The
  95. command-line parameters respectively represent the username to use,
  96. and the password to use. Note that you may need to edit
  97. <literal>client.properties</literal> to use a different target
  98. URL.</para>
  99. -->
  100. </section>
  101. <section xml:id="ldap-sample">
  102. <title>LDAP Sample</title>
  103. <para>
  104. The LDAP sample application provides a basic configuration and sets up both a namespace configuration
  105. and an equivalent configuration using traditional beans, both in the same application context file.
  106. This means there are actually two identical authentication providers configured in this application.
  107. </para>
  108. </section>
  109. <section xml:id="cas-sample">
  110. <title>CAS Sample</title>
  111. <para>
  112. The CAS sample requires that you run both a CAS server and CAS client. It isn't included in the distribution so you should check out
  113. the project code as described in <link xlink:href="get-source">the introduction</link>. You'll find the relevant files under the
  114. <filename>sample/cas</filename> directory. There's also a <filename>Readme.txt</filename> file in there which explains how to run
  115. both the server and the client directly from the source tree, complete with SSL support. You have to download the CAS Server web application
  116. (a war file) from the CAS site and drop it into the <filename>samples/cas/server</filename> directory.
  117. </para>
  118. </section>
  119. <section xml:id="preauth-sample">
  120. <title>Pre-Authentication Sample</title>
  121. <para>
  122. This sample application demonstrates how to wire up beans from the <link xlink:href="#preauth">pre-authentication</link>
  123. framework to make use of login information from a J2EE container. The user
  124. </para>
  125. </section>
  126. </chapter>