faq.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <document><properties><title>Frequently Asked Questions (FAQ) on Acegi Security</title></properties><body><section name="Frequently Asked Questions"><subsection name="What is Acegi Security?"><p>Acegi Security is an open source project that provides comprehensive authentication
  3. and authorisation services for enterprise applications based on
  4. <a href="http://www.springframework.org">The Spring Framework</a>.
  5. Acegi Security can authenticate using a variety of pluggable providers, and
  6. can authorise both web requests and method invocations.
  7. Acegi Security provides an integrated security approach across
  8. these various targets, and also offers access control list (ACL) capabilities to
  9. enable individual domain object instances to be secured. At an implementation
  10. level, Acegi Security is managed through Spring's inversion of control and
  11. lifecycle services, and actually enforces security using interception through
  12. servlet Filters and Java AOP frameworks. In terms of AOP framework support, Acegi
  13. Security currently supports AOP Alliance (which is what the
  14. Spring IoC container uses internally) and AspectJ, although additional frameworks
  15. can be easily supported.</p></subsection><subsection name="Why not just use web.xml security?"><p>Let's assume you're developing an enterprise application based on Spring.
  16. There are four security concerns you typically need to address: authentication,
  17. web request security, service layer security (ie your methods that implement
  18. business logic), and domain object instance security (ie different domain objects
  19. have different permissions). With these typical requirements in mind:
  20. <ol>
  21. <li><b>Authentication</b>: The servlet specification provides an approach
  22. to authentication. However, you will need to configure the container
  23. to perform authentication which typically requires editing of
  24. container-specific "realm" settings. This makes a non-portable
  25. configuration, and if you need to write an actual Java class to implement
  26. the container's authentication interface, it becomes even more non-portable.
  27. With Acegi Security you achieve complete portability - right down to the
  28. WAR level. Also, Acegi Security offers a choice of production-proven
  29. authentication providers and mechanisms, meaning you can switch your
  30. authentication approaches at deployment time. This is particularly
  31. valuable for software vendors writing products that need to work in
  32. an unknown target environment.<br></br><br></br></li>
  33. <li><b>Web request security:</b> The servlet specification provides an
  34. approach to secure your request URIs. However, these URIs can only be
  35. expressed in the servlet specification's own limited URI path format.
  36. Acegi Security provides a far more comprehensive approach. For instance,
  37. you can use Ant paths or regular expressions, you can consider parts of the
  38. URI other than simply the requested page (eg you can consider HTTP GET
  39. parameters), and you can implement your own runtime source of configuration
  40. data. This means your web request security can be dynamically changed during
  41. the actual execution of your webapp.<br></br><br></br></li>
  42. <li><b>Service layer and domain object security:</b> The absence of support
  43. in the servlet specification for services layer security or domain object
  44. instance security represent serious limitations for multi-tiered
  45. applications. Typically developers either ignore these requirements, or
  46. implement security logic within their MVC controller code (or even worse,
  47. inside the views). There are serious disadvantages with this approach:<br></br><br></br>
  48. <ol>
  49. <li><i>Separation of concerns:</i> Authorization is a
  50. crosscutting concern and should be implemented as such.
  51. MVC controllers or views implementing authorization code
  52. makes it more difficult to test both the controller and
  53. authorization logic, more difficult to debug, and will
  54. often lead to code duplication.</li>
  55. <li><i>Support for rich clients and web services:</i> If an
  56. additional client type must ultimately be supported, any
  57. authorization code embedded within the web layer is
  58. non-reusable. It should be considered that Spring remoting
  59. exporters only export service layer beans (not MVC
  60. controllers). As such authorization logic needs to be
  61. located in the services layer to support a multitude of
  62. client types.</li>
  63. <li><i>Layering issues:</i> An MVC controller or view is simply
  64. the incorrect architectural layer to implement authorization
  65. decisions concerning services layer methods or domain object
  66. instances. Whilst the Principal may be passed to the services
  67. layer to enable it to make the authorization decision, doing
  68. so would introduce an additional argument on every services
  69. layer method. A more elegant approach is to use a ThreadLocal
  70. to hold the Principal, although this would likely increase
  71. development time to a point where it would become more
  72. economical (on a cost-benefit basis) to simply use a dedicated
  73. security framework.</li>
  74. <li><i>Authorisation code quality:</i> It is often said of web
  75. frameworks that they "make it easier to do the right things,
  76. and harder to do the wrong things". Security frameworks are
  77. the same, because they are designed in an abstract manner for
  78. a wide range of purposes. Writing your own authorization code
  79. from scratch does not provide the "design check" a framework
  80. would offer, and in-house authorization code will typically
  81. lack the improvements that emerge from widespread deployment,
  82. peer review and new versions.
  83. </li></ol>
  84. </li>
  85. </ol>
  86. For simple applications, servlet specification security may just be enough.
  87. Although when considered within the context of web container portability,
  88. configuration requirements, limited web request security flexibility, and
  89. non-existent services layer and domain object instance security, it becomes
  90. clear why developers often look to alternative solutions.
  91. </p></subsection><subsection name="How do you pronounce &quot;Acegi&quot;?"><p><i>Ah-see-gee</i>. Said quickly, without emphasis on any part.
  92. Acegi isn't an acronym, name of a Greek God or anything similarly
  93. impressive - it's just letters #1, #3, #5, #7 and #9 of the alphabet.</p></subsection><subsection name="Is it called &quot;Acegi&quot; or &quot;Acegi Security&quot;?"><p>It's official name is <i>Acegi Security System for Spring</i>,
  94. although we're happy for it to be abbreviated to
  95. <i>Acegi Security</i>. Please don't just call it <i>Acegi</i>, though,
  96. as that gets confused with the name of the company that maintains Acegi
  97. Security.</p></subsection><subsection name="What catches 80% of users reporting problems?"><p>80% of support questions are because people have not defined
  98. the necessary filters in <code>web.xml</code>, or the filters are being
  99. mapped in the incorrect order. Check the
  100. <a href="reference.html">Reference Guide</a>, which
  101. has a specific section on filter ordering.</p></subsection><subsection name="I&apos;m sure my filters are ordered correctly. What else could be wrong?"><p>The next most common source of problems stem from custom
  102. <code>AuthenticationDao</code> implementations that simply don't properly
  103. implement the interface contract. For example, they return <code>null</code> instead
  104. of the user not found exception, or fail to add in the
  105. <code>GrantedAuthority[]</code>s. Whilst <code>DaoAuthenticationProvider</code>
  106. does its best to check the <code>AuthenticationDao</code> returns a valid
  107. <code>UserDetails</code>, we suggest you write the
  108. <code>UserDetails</code> object to the log and check it looks correct.</p></subsection><subsection name="Common Problem #1: My application goes into an &quot;endless loop&quot; when I try to login, what&apos;s going on?"><p>A common user problem with infinite loop and redirecting to the login page
  109. is caused by accidently configuring the login page as a "secured" resource.
  110. Generally make sure you mark your login page as requiring ROLE_ANONYMOUS.
  111. </p></subsection><subsection name="Common Problem #2: My application pages don&apos;t seem to be protected."><p>If you are securing web resources and they dont seem to be matched in the URL patterns,
  112. check the objectDefinitionSource in the FilterSecurityInterceptor.
  113. If you are using the <tt>CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON</tt> setting,
  114. then the URL patterns configured MUST be in lowercase.
  115. </p><p>
  116. For example, making a request ending in <tt>/someAction.do</tt> will need
  117. to be configured as: <tt>/someaction.do</tt> (Note the case).
  118. <pre>
  119. &lt;property name="objectDefinitionSource"&gt;
  120. &lt;value&gt;
  121. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  122. PATTERN_TYPE_APACHE_ANT
  123. /index.jsp=ROLE_ANONYMOUS,ROLE_USER
  124. /someaction.do=ROLE_USER
  125. &lt;value&gt;
  126. &lt;/property&gt;
  127. </pre>
  128. </p></subsection><subsection name="Common Problem #3: How do I disable a user after a number of failed logins?"><p>A common user requirement is to disable / lock an account after a number of failed login attempts.
  129. Acegi itself does not provide anything "out of the box", however in your application you can implement
  130. and register an <tt>org.springframework.context.ApplicationListener</tt>. Inside your application
  131. event listener you can then check for an instanceof the particular <tt>AuthenticationFailureEvent</tt>
  132. and then call your application user management interface to update the user details.
  133. </p><p>
  134. For example:
  135. <pre>
  136. public void onApplicationEvent(ApplicationEvent event) {
  137. // check failed event
  138. if(event instanceof AuthenticationFailurePasswordEvent){
  139. // call user management interface to increment failed login attempts, etc.
  140. . . .
  141. }
  142. }
  143. </pre>
  144. </p></subsection><subsection name="Common Problem #4: I am changing my password using a web controller and DAO, why is my password still not being refreshed?"><p>There are three things you must do to make a user password change take affect:
  145. <ul>
  146. <li> Change the password using your authentication DAO</li>
  147. <li> Remove the user from the User Cache (i.e. if you have a cache configured) </li>
  148. <li> Update the <tt>SecurityContextHolder</tt> to include the new <tt>Authentication</tt> object and password</li>
  149. </ul>
  150. </p></subsection><subsection name="I need some help. What files should I post?"><p>The most important things to post with any support requests on the
  151. <a href="http://forum.springframework.org">Spring Forums</a> are your
  152. <code>web.xml</code>, <code>applicationContext.xml</code> (or whichever
  153. XML loads the security-related beans) as well as any custom
  154. <code>AuthenticationDao</code> you might be using. For really odd problems,
  155. also switch on debug-level logging and include the resulting log.</p></subsection><subsection name="How do I switch on debug-level logging?"><p>Acegi Security uses Commons Logging, just as Spring does. So you use the
  156. same approach as you'd use for Spring. Most people output to Log4J, so
  157. the following <code>log4j.properties</code> would work:</p><source>
  158. log4j.rootCategory=WARN, stdout
  159. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  160. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  161. log4j.appender.stdout.layout.ConversionPattern=%d %p %c - %m%n
  162. log4j.category.net.sf.acegisecurity=DEBUG
  163. </source></subsection><subsection name="How do I store custom properties, like a user&apos;s email address?"><p>In most cases write an <code>AuthenticationDao</code> which returns
  164. a subclass of <code>User</code>. Alternatively, write your own
  165. <code>UserDetails</code> implementation from scratch and return that.</p></subsection><subsection name="Why doesn&apos;t Acegi Security use JAAS?"><p>Acegi Security targets <i>enterprise applications</i>, which are typically
  166. multi-user, data-oriented applications that are important to
  167. the core business. Acegi Security was designed to provide a portable and effective
  168. security framework for this target application type. It was not designed for securing
  169. limited privilege runtime environments, such as web browser applets.</p><p>We did consider JAAS when designing Acegi Security, but it simply
  170. wasn't suitable for our purpose. We needed to avoid complex JRE configurations,
  171. we needed container portability, and we wanted maximum leveraging of the Spring IoC
  172. container. Particularly as limited privilege runtime environments were not
  173. an actual requirement, this lead to the natural design of Acegi Security as
  174. it exists today.</p><p>Acegi Security already provides some JAAS integration. It can today authenticate
  175. via delegation to a JAAS login module. This means it offers the same level of JAAS
  176. integration as many web containers. Indeed the container adapter model supported by
  177. Acegi Security allows Acegi Security and container-managed security to happily
  178. co-exist and benefit from each other. Any debate about Acegi Security and JAAS
  179. should therefore centre on the authorisation issue. An evaluation of major
  180. containers and security frameworks would reveal that Acegi Security is by no
  181. means unusual in not using JAAS for authorisation.</p><p>There are many examples of open source applications being preferred to
  182. official standards. A few that come to mind in the Java community include
  183. using Spring managed POJOs (rather than EJBs), Hibernate (instead of entity beans),
  184. Log4J (instead of JDK logging), Tapestry (instead of JSF), and Velocity/FreeMarker
  185. (instead of JSP). It's important to recognise that many open source projects do
  186. develop into de facto standards, and in doing so play a legitimate and beneficial
  187. role in professional software development.</p></subsection><subsection name="Do you welcome contributions?"><p>Yes. If you've written something and it works well, please feel free to share it.
  188. Simply email the contribution to the
  189. <a href="mail-lists.html">acegisecurity-developers</a> list. If you haven't yet
  190. written the contribution, we encourage you to send your thoughts to the same
  191. list so that you can receive some initial design feedback.</p><p>For a contribution to be used, it must have appropriate unit test coverage and
  192. detailed JavaDocs. It will ideally have some comments for the Reference Guide
  193. as well (this can be sent in word processor or HTML format if desired). This
  194. helps ensure the contribution maintains the same quality as the remainder of
  195. the project.</p><p>We also welcome documentation improvements, unit tests, illustrations,
  196. people supporting the user community (especially on the forums), design ideas,
  197. articles, blog entries, presentations and alike. If you're looking for something
  198. to do, you can always email the
  199. <a href="mail-lists.html">acegisecurity-developers</a> list and we'll be
  200. pleased to suggest something. :-)</p></subsection></section></body></document>