Authentication processing filter configuration of authenticationprocessingfilter
- <Bean id = "authenticationprocessingfilter" class = "org. acegisecurity. UI. webapp. authenticationprocessingfilter">
- <Property name = "filterprocessesurl" value = "/j_security_check"/>
- <Property name = "authenticationfailureurl" value = "/index. jsp? Login_error = 1 "/>
- <Property name = "defaulttargeturl" value = "/Main. Do"/>
- <Property name = "authenticationmanager" ref = "authenticationmanager"/>
- <Property name = "remembermeservices" ref = ""/> <! -Optional -->
- </Bean>
- Note:
- 1) processes form-based authentication requests.
- 2) When a request is received as defined in filterprocessesurl, it first authenticates the user identity through authenticationmanager. If the verification succeeds, the system redirects to the successful login page defined by defaulttargeturl. If the verification fails, the user identity is obtained from remembermeservices. If retrieval fails, the logon Failure page defined by auhenticationfailureurl is redirected.
- 3) filterprocessesurl: The default value is/j_acegi_security_check. This value must be consistent with the action value of the form on the logon page.
- The name of the input control that inputs the user name in form must be j_username; the name of the input control that inputs the password must be j_password.
- 4) remembermeservices stores previous user logon information in the form of cookies. If the authentication object does not exist, remembermeprocessingfilter calls the remembermeservices autologin () method to obtain user logon information in cookies. If so, the authentication object is returned. If the rememberme function is set during each user login, after the user's identity is verified successfully, the loginsuccess () method is called to record the user information in cookies; otherwise, loginfail () is called () method to clear the cookie.
Authentication Manager authenticationmanager Configuration
- <Bean id = "authenticationmanager" class = "org. acegisecurity. providers. providermanager">
- <Property name = "providers">
- <List>
- <Ref local = "daoauthenticationprovider"/>
- <Ref local = "anonymousauthenticationprovider"/>
- </List>
- </Property>
- </Bean>
- Note:
- 1) The Authentication Manager is used to manage the authentication provider. It delegates the authentication function to multiple providers and traverses providers to ensure identity authentication from different sources. If a provider can successfully confirm the identity of the current user, authenticate () method returns a complete authentication object containing user authorization information. Otherwise, an authenticationexception is thrown.
- 2) Whether successful or not, the Authentication Manager will publish an applicationevent event object.
Authentication provider Configuration
- <Bean id = "daoauthenticationprovider" class = "org. acegisecurity. providers. Dao. daoauthenticationprovider">
- <Property name = "userdetailsservice" ref = "userdao"/>
- <Property name = "usercache" ref = "usercache"/>
- <Property name = "passwordencoder" ref = "passwordencoder"/> <! -Optional -->
- </Bean>
- <Bean id = "anonymousauthenticationprovider" class = "org. acegisecurity. providers. Anonymous. anonymousauthenticationprovider">
- <Property name = "key" value = "anonymous"/>
- </Bean>
- <Bean id = "userdao" class = "com. CJM. Web. Dao. impl. userdaoimpl">
- <Property name = "sessionfactory" ref = "sessionfactory"/>
- </Bean>
- <Bean id = "usercache" class = "org. acegisecurity. providers. Dao. cache. ehcachebasedusercache">
- <Property name = "cache">
- <Bean class = "org. springframework. cache. ehcache. ehcachefactorybean">
- <Property name = "cachemanager">
- <Bean class = "org. springframework. cache. ehcache. ehcachemanagerfactorybean"/>
- </Property>
- <Property name = "cachename" value = "usercache"/>
- </Bean>
- </Property>
- </Bean>
- <Bean id = "passwordencoder" class = "org. acegisecurity. providers. encoding. md5passwordencoder"/>
- Note:
- 1) daoauthenticationprovider: Provides user information, including the user name and password. The username and password retrieval work should be done by userdetailsservice.
- 2) anonymousauthenticationprovider: anonymous user authentication.
- 3) userdao: used to obtain user information in the database. Userdaoimpl must implement the userdetailsservice interface class provided by acegi.
- 4) usercache: caches the permission information of users and resources. Every time a protected resource is requested, daoauthenticationprovider is called to obtain user authorization information. If you get the information from the database every time, it is very costly. for users and resources that are not often changed, it is best to cache the relevant authorization information.
- 5) passwordencoder: Use the encryptor to encrypt the plaintext entered by the user. Acegi provides three Encryptors:
- Plaintextpasswordencoder --- default, not encrypted, return plaintext
- Shapasswordencoder --- hash algorithm (SHA) Encryption
- D5passwordencoder --- Message Digest (MD5) Encryption