codebase-structure.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?oxygen RNGSchema="http://www.oasis-open.org/docbook/xml/5.0/rng/docbook.rng" type="xml"?>
  3. <article xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
  4. version="5.0">
  5. <info>
  6. <title>The Spring Security 3.0 Codebase</title>
  7. <subtitle>Why have the packages changed in Spring Security 3.0?</subtitle>
  8. <author>
  9. <personname>Luke Taylor</personname>
  10. <affiliation><orgname>SpringSource</orgname></affiliation></author>
  11. <abstract>
  12. <para>An quick introduction to the code modules and package structure of the Spring
  13. Security 3.0 codebase.</para>
  14. </abstract>
  15. </info>
  16. <sect1>
  17. <title>Introduction</title>
  18. <para>In versions prior to 3.0, most of Spring Security's code was contained in the
  19. <filename>spring-security-core</filename> jar<footnote>
  20. <para>There was also an additional <filename>spring-security-core-tiger</filename>
  21. jar which contained the Java 5 specific code. In Spring Security 3.0 Java 5 is
  22. the minimum supported platform, so this code is now part of the core.</para>
  23. </footnote>. Over the years, as more features have been added, it has become more
  24. difficult to track the dependencies both within the codebase itself and also on third
  25. party libraries. For example, it's hard for a user to determine which of the listed
  26. dependencies in the core Maven <filename>pom.xml</filename> are required for a
  27. particular set of features within the framework.</para>
  28. <para>In addition, the original package structure and class names have been around since the
  29. framework's origins as Acegi Security in 2004, when only a few basic authentication
  30. mechanisms were supported. As the amount of code has increased and the feature set has
  31. expanded, this package structure has begun to show its age.</para>
  32. <figure xml:id="structure-2.0.4">
  33. <title>Spring Security 2.0.4 Package Structure</title>
  34. <mediaobject>
  35. <imageobject>
  36. <imagedata fileref="images/spring-security-2.0.4.png" scale="80" align="center"
  37. />
  38. </imageobject>
  39. </mediaobject>
  40. </figure>
  41. <para>
  42. <xref linkend="structure-2.0.4"/> shows the high-level package diagram of the core,
  43. core-tiger, cas-client and acl jars in the 2.0.4 release, as produced by the
  44. Structure101 tool<footnote>
  45. <para>Structure101 is an excellent tool for analyzing your own code or for
  46. understanding someone else's. It is developed by <link
  47. xlink:href="http://www.headwaysoftware.com">Headway Software</link>. </para>
  48. </footnote>. You don't have to be an expert in code structure to realise that there is a
  49. bit of a problem here. There are a lot of circular references and no clear overall
  50. dependency structure within the packages. There are also some issues with packages being
  51. split across jar boundaries, which can cause problems with OSGi, for example.<footnote>
  52. <para>For more information on how to structure a large codebase, Juergen Hoeller's
  53. <quote>Organization of Large Code Bases</quote> is an excellent overview of
  54. the topic where he shares some of the insights gained from maintaining the
  55. Spring Framework through multiple versions. You can find him discussing the
  56. topic in an online interview <link
  57. xlink:href="http://www.se-radio.net/transcript-82-organization-large-code-bases-juergen-hoeller"
  58. >transcript</link> and an <link
  59. xlink:href="http://www.infoq.com/presentations/code-organization-large-projects"
  60. >InfoQ video</link>. </para>
  61. </footnote>. This fragility in the code structure would likely have caused a maintenance
  62. overhead as Spring Security evolved, so the decision was made to restructure the code
  63. for the 3.0 release to give us a stable base for future development. </para>
  64. <para>Let's take a look at how things are now organised.</para>
  65. </sect1>
  66. <sect1>
  67. <title>Spring Security 3.0</title>
  68. <sect2>
  69. <title>Project Jars</title>
  70. <para>The first thing we did was split the core out into several jars. The
  71. <filename>spring-security-core</filename> jar now contains only basic
  72. authentication and access-control code and is much cleaner. It has no dependencies
  73. on LDAP or the servlet API, for example, and there are now separate jars for
  74. web-specific code and for LDAP. We've also split out the namespace parsing code out
  75. int a separate jar, as it depends on most of the other jars and doesn't expose any
  76. public APIs that you are likely to use directly in your application. You only need
  77. to use it if you are using Spring Security namespace configuration in your
  78. application context XML files. The main project jars are shown in the following
  79. table.<table xml:id="jar-files-3.0">
  80. <title>Spring Security Jars</title>
  81. <tgroup cols="3" align="left">
  82. <colspec colnum="1" colname="c1" colwidth="0.6*"/>
  83. <colspec colnum="2" colname="c2" colwidth="0.9*"/>
  84. <colspec colnum="3" colname="c3" colwidth="0.88*"/>
  85. <colspec colnum="4" colname="c4" colwidth="1.61*"/>
  86. <thead>
  87. <row>
  88. <entry align="center">Jar Name</entry>
  89. <entry align="center">Description</entry>
  90. <entry align="center">When to use</entry>
  91. <entry align="center">Root Package(s)</entry>
  92. </row>
  93. </thead>
  94. <tbody>
  95. <row>
  96. <entry valign="middle">spring-security-core</entry>
  97. <entry>Core authentication and access-contol classes and interfaces.
  98. Remoting support and basic provisioning APIs.</entry>
  99. <entry>Required by any application which uses Spring Security.
  100. Supports standalone applications, remote clients, method
  101. (service layer) security and JDBC user provisioning.</entry>
  102. <entry>
  103. <literal>org.springframework.security.core</literal>,
  104. <literal>org.springframework.security.access</literal>,
  105. <literal>org.springframework.security.authentication</literal>,
  106. <literal>org.springframework.security.provisioning</literal>,
  107. <literal>org.springframework.security.remoting</literal>
  108. </entry>
  109. </row>
  110. <row>
  111. <entry valign="middle">spring-security-web</entry>
  112. <entry>Filters and other web-security infrastructure and related
  113. code. Anything with a servlet API dependency.</entry>
  114. <entry>If you require Spring Security web authentication services
  115. and URL-based access-control</entry>
  116. <entry><literal>org.springframework.security.web</literal></entry>
  117. </row>
  118. <row>
  119. <entry valign="middle">spring-security-config</entry>
  120. <entry>Namespace parsing code.</entry>
  121. <entry>If you are using the Spring Security XML namespace.</entry>
  122. <entry><literal>org.springframework.security.config</literal></entry>
  123. </row>
  124. <row>
  125. <entry valign="middle">spring-security-ldap</entry>
  126. <entry>LDAP authentication and provisioning code.</entry>
  127. <entry>If you need to use LDAP authentication or manage LDAP user
  128. entries.</entry>
  129. <entry><literal>org.springframework.security.ldap</literal></entry>
  130. </row>
  131. <row>
  132. <entry valign="middle">spring-security-acl</entry>
  133. <entry>Domain object ACL implementation.</entry>
  134. <entry>If you need to apply security to specific domain object
  135. instances within your application.</entry>
  136. <entry><literal>org.springframework.security.acls</literal></entry>
  137. </row>
  138. <row>
  139. <entry valign="middle">spring-security-cas-client</entry>
  140. <entry>Spring Security's CAS client integration.</entry>
  141. <entry>If you want to use Spring Security web authentication with a
  142. CAS single sign-on server.</entry>
  143. <entry><literal>org.springframework.security.cas</literal></entry>
  144. </row>
  145. <row>
  146. <entry valign="middle">spring-security-openid</entry>
  147. <entry>OpenID web authentication support.</entry>
  148. <entry>If you need to authenticate users against an external OpenID
  149. server.</entry>
  150. <entry><literal>org.springframework.security.openid</literal></entry>
  151. </row>
  152. </tbody>
  153. </tgroup>
  154. </table></para>
  155. <para>There is now a clearer separation of concerns at the jar level. For example, you
  156. only need the web jar (and its transitive dependencies) if you are writing a web
  157. application. This also makes the code easier to navigate and understand. The
  158. dependencies between the 3.0 jars which now make up the same code set of code we
  159. looked at for version 2.0.4 are shown in <xref linkend="jar-deps-3.0"/>. <figure
  160. xml:id="jar-deps-3.0">
  161. <title>Inter-Jar Dependencies</title>
  162. <mediaobject>
  163. <imageobject>
  164. <imagedata fileref="images/spring-security-3.0.0.M2-jars.png"
  165. align="center"/>
  166. </imageobject>
  167. </mediaobject>
  168. </figure></para>
  169. </sect2>
  170. <sect2>
  171. <title>Package Structure</title>
  172. <para>The package layout in 3.0 is show in <xref linkend="structure-3.0"/>. As you can
  173. see, there are no longer any circular references and the structure is much clearer.
  174. The <filename>core</filename> package and sub packages contain the basic classes and
  175. interfaces which are used throughout the framework and the other two main packages
  176. within the core jar are <filename>authentication</filename> and
  177. <filename>access</filename>. The <filename>access</filename> package containst
  178. access-control/authorization code such as the
  179. <interfacename>AccessDecisionManager</interfacename> and related voter-based
  180. implementations, the interception and method security infrastructure, annotation
  181. classes and support for Spring Security 3.0's expression-based access control. The
  182. <filename>authentication</filename> package contains the
  183. <interfacename>AuthenticationManager</interfacename> and related classes (such
  184. as authentication exception classes), the simple DAO-based authentication provider
  185. and password-encoders. <figure xml:id="structure-3.0">
  186. <title>Spring Security 2.0.4 Package Structure</title>
  187. <mediaobject>
  188. <imageobject>
  189. <imagedata fileref="images/spring-security-3.0.0.M1.png" align="center"
  190. />
  191. </imageobject>
  192. </mediaobject>
  193. </figure></para>
  194. </sect2>
  195. </sect1>
  196. <sect1>
  197. <title>How will these changes affect you?</title>
  198. <para>If you are developing a new application then obviously you won't be affected, other
  199. than by starting out with new package names. But what if you are upgrading an existing
  200. application or another framework to use Spring Security 3.0. The first thing is that you
  201. will obviously need to update build paths and dependency lists to take account of the
  202. new jar modules, but the divisions there are straightforward (see the table above). How
  203. much the package restructuring will affect you will depend on how much you use the
  204. framework classes directly or in explicit bean configurations (if you are only using the
  205. namespace for configuration then it will hide the changes from you). Your IDE should be
  206. able to help with changing imports and finding out where classes have moved to (a simple
  207. <command>Ctrl-Shift-T</command>or <command>Ctrl-Shift-O</command> in Eclipse can do
  208. wonders).</para>
  209. <para>There are other changes in 3.0 that will affect some users who want to upgrade but for
  210. the most part, the underlying architecture is unchanged.</para>
  211. <para>We hope you enjoy using Spring Security 3.0.</para>
  212. </sect1>
  213. </article>