2
0

faq.html 15 KB

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