faq.fml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <faqs title="Frequently Asked Questions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/maven-1.x/plugins/faq/faq.xsd">
  4. <part id="general">
  5. <title>General</title>
  6. <faq id="other-concerns">
  7. <question>Will Spring Security take care of all my application security requirements?</question>
  8. <answer>
  9. <p>Spring Security provides you with a very flexible framework for
  10. your authentication and authorization requirements, but there are many other considerations
  11. for building a secure application that are outside its scope. Web applications are
  12. vulnerable to all kinds of attacks which you should be familiar with, preferably before you
  13. start development so you can design and code with them in mind from the beginning.
  14. Check out the <a href="http://www.owasp.org/">OWASP web site</a>
  15. for information on the major issues facing web application developers and the countermeasures
  16. you can use against them.
  17. </p>
  18. </answer>
  19. </faq>
  20. <faq id="web-xml">
  21. <question>Why not just use web.xml security?</question>
  22. <answer>
  23. <p>Let's assume you're developing an enterprise application based on Spring.
  24. There are four security concerns you typically need to address: authentication,
  25. web request security, service layer security (i.e. your methods that implement
  26. business logic), and domain object instance security (i.e. different domain objects
  27. have different permissions). With these typical requirements in mind:
  28. <ol>
  29. <li><b>Authentication</b>: The servlet specification provides an approach
  30. to authentication. However, you will need to configure the container
  31. to perform authentication which typically requires editing of
  32. container-specific "realm" settings. This makes a non-portable
  33. configuration, and if you need to write an actual Java class to implement
  34. the container's authentication interface, it becomes even more non-portable.
  35. With Spring Security you achieve complete portability - right down to the
  36. WAR level. Also, Spring Security offers a choice of production-proven
  37. authentication providers and mechanisms, meaning you can switch your
  38. authentication approaches at deployment time. This is particularly
  39. valuable for software vendors writing products that need to work in
  40. an unknown target environment.<br></br><br></br></li>
  41. <li><b>Web request security:</b> The servlet specification provides an
  42. approach to secure your request URIs. However, these URIs can only be
  43. expressed in the servlet specification's own limited URI path format.
  44. Spring Security provides a far more comprehensive approach. For instance,
  45. you can use Ant paths or regular expressions, you can consider parts of the
  46. URI other than simply the requested page (eg you can consider HTTP GET
  47. parameters), and you can implement your own runtime source of configuration
  48. data. This means your web request security can be dynamically changed during
  49. the actual execution of your webapp.<br></br><br></br></li>
  50. <li><b>Service layer and domain object security:</b> The absence of support
  51. in the servlet specification for services layer security or domain object
  52. instance security represent serious limitations for multi-tiered
  53. applications. Typically developers either ignore these requirements, or
  54. implement security logic within their MVC controller code (or even worse,
  55. inside the views). There are serious disadvantages with this approach:<br/><br/>
  56. <ol>
  57. <li><i>Separation of concerns:</i> Authorization is a
  58. crosscutting concern and should be implemented as such.
  59. MVC controllers or views implementing authorization code
  60. makes it more difficult to test both the controller and
  61. authorization logic, more difficult to debug, and will
  62. often lead to code duplication.</li>
  63. <li><i>Support for rich clients and web services:</i> If an
  64. additional client type must ultimately be supported, any
  65. authorization code embedded within the web layer is
  66. non-reusable. It should be considered that Spring remoting
  67. exporters only export service layer beans (not MVC
  68. controllers). As such authorization logic needs to be
  69. located in the services layer to support a multitude of
  70. client types.</li>
  71. <li><i>Layering issues:</i> An MVC controller or view is simply
  72. the incorrect architectural layer to implement authorization
  73. decisions concerning services layer methods or domain object
  74. instances. Whilst the Principal may be passed to the services
  75. layer to enable it to make the authorization decision, doing
  76. so would introduce an additional argument on every services
  77. layer method. A more elegant approach is to use a ThreadLocal
  78. to hold the Principal, although this would likely increase
  79. development time to a point where it would become more
  80. economical (on a cost-benefit basis) to simply use a dedicated
  81. security framework.</li>
  82. <li><i>Authorisation code quality:</i> It is often said of web
  83. frameworks that they "make it easier to do the right things,
  84. and harder to do the wrong things". Security frameworks are
  85. the same, because they are designed in an abstract manner for
  86. a wide range of purposes. Writing your own authorization code
  87. from scratch does not provide the "design check" a framework
  88. would offer, and in-house authorization code will typically
  89. lack the improvements that emerge from widespread deployment,
  90. peer review and new versions.
  91. </li></ol>
  92. </li>
  93. </ol>
  94. </p>
  95. <p>
  96. For simple applications, servlet specification security may just be enough.
  97. Although when considered within the context of web container portability,
  98. configuration requirements, limited web request security flexibility, and
  99. non-existent services layer and domain object instance security, it becomes
  100. clear why developers often look to alternative solutions.
  101. </p>
  102. </answer>
  103. </faq>
  104. <faq id="requirements">
  105. <question>What Java and Spring Framework versions are required</question>
  106. <answer>
  107. Spring Security 2.0.x requires a minimum JDK version of 1.4 and is built against Spring 2.0.x. It should
  108. also be compatible with applications using Spring 2.5.x.
  109. </answer>
  110. </faq>
  111. </part>
  112. <part id="common-problems">
  113. <title>Common Problems</title>
  114. <faq id="login-loop">
  115. <question>My application goes into an "endless loop" when I try to login, what's going on?</question>
  116. <answer><p>A common user problem with infinite loop and redirecting to the login page is caused
  117. by accidently configuring the login page as a "secured" resource. Make sure your configuration
  118. allows anonymous access to the login page, either by excluding it from the security filter
  119. chain or marking it as requiring ROLE_ANONYMOUS.</p>
  120. <p>If your AccessDecisionManager includes an AutheticatedVoter, you can use the attribute
  121. "IS_AUTHENTICATED_ANONYMOUSLY". This is automatically available if you are using the
  122. standard namespace configuration setup.
  123. </p>
  124. <p>
  125. From Spring Security 2.0.1 onwards, when you are using namespace-based configuration, a check will be made
  126. on loading the application context and a warning message logged if your login page appears to be protected.
  127. </p>
  128. </answer>
  129. </faq>
  130. <faq id="anon-access-denied">
  131. <question>I get an exception with the message "Access is denied (user is anonymous);". What's wrong?</question>
  132. <answer>
  133. <p>
  134. This is a debug level message which occurs the first time an anonymous user attempts to access a protected
  135. resource.
  136. <pre>
  137. DEBUG [ExceptionTranslationFilter] - Access is denied (user is anonymous); redirecting to authentication entry point
  138. org.springframework.security.AccessDeniedException: Access is denied
  139. at org.springframework.security.vote.AffirmativeBased.decide(AffirmativeBased.java:68)
  140. at org.springframework.security.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:262)
  141. </pre>
  142. It is normal and shouldn't be anything to worry about.
  143. </p>
  144. </answer>
  145. </faq>
  146. <faq id="tomcat-https-session">
  147. <question>
  148. I'm using Tomcat and have enabled HTTPS for my login page, switching back to HTTP afterwards. It doesn't work - I just
  149. end up back at the login page after authenticating.
  150. </question>
  151. <answer>
  152. <p>
  153. This happens because Tomcat sessions created under HTTPS cannot subsequently be used under HTTP and any session state is lost (including
  154. the security context information). Starting in HTTP first should work.
  155. </p>
  156. </answer>
  157. </faq>
  158. <faq id="no-security-on-forward">
  159. <question>
  160. I'm forwarding a request to another URL using the RequestDispatcher, but my security constraints aren't being applied.
  161. </question>
  162. <answer>
  163. Filters are not applied by default to forwards or includes. If you really want the security filters to be applied to forwards and/or includes,
  164. then you have to configure these explicitly in your web.xml using the &lt;dispatcher&gt; element, a child element of &lt;filter-mapping&gt;.
  165. </answer>
  166. </faq>
  167. <faq id="session-listener-missing">
  168. <question>
  169. I'm trying to use the concurrent session-control support but it won't let me log back in, even if I'm sure I've logged out and haven't exceeded the allowed sessions.
  170. </question>
  171. <answer>
  172. Make sure you have added the listener to your web.xml file. It is essential to make sure that the Spring Security session registry is
  173. notified when a session is destroyed. Without it, the session information will not be removed from the registry.
  174. <pre>
  175. &lt;listener&gt;
  176. &lt;listener-classorg.springframework.security.ui.session.HttpSessionEventPublisher&lt;/listener-class&gt;
  177. &lt;/listener&gt;
  178. </pre>
  179. </answer>
  180. </faq>
  181. </part>
  182. <part id="how-tos">
  183. <title>Common "How To" Requests</title>
  184. <faq id="extra-login-fields">
  185. <question>I need to login in with more information than just the username. How do I add support for extra login fields (e.g. a company name)?</question>
  186. <answer>
  187. <p>This question comes up repeatedly in the Spring Security forum so you will find more information there by searching the archives (or through google).</p>
  188. <p>
  189. The submitted login information is processed by an instance of <i>AuthenticationProcessingFilter</i>. You will need to customize this class to handle
  190. the extra data field(s). One option is to use your own customized authentication token class (rather than the standard <i>UsernamePasswordAuthenticationToken</i>),
  191. another is simply to concatenate the extra fields with the username (for example, using a ":" as the separator) and pass them in the username property of
  192. <i>UsernamePasswordAuthenticationToken</i>.
  193. </p>
  194. <p>
  195. You will also need to customize the actual authentication process. If you are using a custom authentication token class, for example, you will have to write an
  196. <i>AuthenticationProvider</i> to handle it (or extend the standard <i>DaoAuthenticationProvider</i>).
  197. If you have concatenated the fields, you can implement your own <i>UserDetailsService</i> which splits them up and loads the appropriate user data for
  198. authentication.
  199. </p>
  200. </answer>
  201. </faq>
  202. <faq>
  203. <title>How do I know what dependencies to add to my application to work with Spring Security?</title>
  204. <para>
  205. <p>
  206. There is no definite answer here, (it will depend on what features you are using), but a good starting point is to copy those from one of the
  207. pre-built sample applications WEB-INF/lib directories. For a basic application, you can start with the tutorial sample. If you want to
  208. use LDAP, with an embedded test server, then use the LDAP sample as a starting point.
  209. </p>
  210. <p>
  211. If you are building your project with maven, then adding the appropriate Spring Security modules to your pom.xml will automatically pull in
  212. the core jars that the framework requires. Any which are marked as "optional" in the Spring Security POM files will have to be added
  213. to your own pom.xml file if you need them.
  214. </p>
  215. </para>
  216. </faq>
  217. </part>
  218. </faqs>