---
title: "acegi 源码学习之用户登录篇 "
author: "srj2903"
date: "2009-03-19T17:02:53Z"
tags: ["Acegi", "Bean", "Cache", "JSP", "Security"]
slug: "acegi"
draft: false
lastmod: "2009-03-19T17:02:53Z"
id: 351644
url: "https://srj2903.iteye.com/blog/351644"
---

一、查看 applicationContext-acegi-security.xml 配置文件，涉及到登录的配置为：

 1 ．

&lt; bean id = "authenticationProcessingFilter" class = "org.javajohn.test.plugins.security.UserAuthenticationProcessingFilter" &gt;

        &lt; property name = "authenticationManager" ref = "authenticationManager" /&gt;

        &lt; property name = "authenticationFailureUrl" &gt;

            &lt; value &gt; /login.jsp?login\_error=1 &lt;/ value &gt;

        &lt;/ property &gt;

        &lt; property name = "defaultTargetUrl" &gt;

            &lt; value &gt; /index.jsp &lt;/ value &gt;

        &lt;/ property &gt;

        &lt; property name = "filterProcessesUrl" &gt;

            &lt; value &gt; /j\_acegi\_security\_check &lt;/ value &gt;

        &lt;/ property &gt;

        &lt; property name = "userManager" ref = "userManager" /&gt;

        &lt; property name = "rememberMeServices" ref = "rememberMeServices" /&gt;

        &lt; property name = "exceptionMappings" &gt;

            &lt; value &gt;

                org.acegisecurity.AuthenticationException=/login.jsp?login\_error=user\_psw\_error

                org.acegisecurity.concurrent.ConcurrentLoginException=/login.jsp?login\_error=too\_many\_user\_error

             &lt;/ value &gt;

        &lt;/ property &gt;

&lt;/ bean &gt;

 

 

2 ． &lt; bean id = "authenticationManager"

       class = "org.acegisecurity.providers.ProviderManager" &gt;

       &lt; property name = "providers" &gt;

           &lt; list &gt;

              &lt; ref local = "daoAuthenticationProvider" /&gt;

              &lt; bean class = "org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider" &gt;

                  &lt; property name = "key" value = "javajohnKey" /&gt;

              &lt;/ bean &gt;

              &lt; bean class = "org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider" &gt;

                  &lt; property name = "key" value = "javajohnKey" /&gt;

              &lt;/ bean &gt;

           &lt;/ list &gt;

       &lt;/ property &gt;   

    &lt;/ bean &gt;

 

3 ．

&lt; bean id = "daoAuthenticationProvider" class = "org.acegisecurity.providers.dao.DaoAuthenticationProvider" &gt;

       &lt; property name = "userDetailsService" ref = "jdbcDaoImpl" /&gt;

       &lt; property name = "userCache" &gt;

           &lt; bean class = "org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache" &gt;

              &lt; property name = "cache" &gt;

                  &lt; bean class = "org.springframework.cache.ehcache.EhCacheFactoryBean" &gt;

                     &lt; property name = "cacheManager" &gt;

                         &lt; bean class = "org.springframework.cache.ehcache.EhCacheManagerFactoryBean" /&gt;

                     &lt;/ property &gt;

                     &lt; property name = "cacheName" value = "userCache" /&gt;

                  &lt;/ bean &gt;

              &lt;/ property &gt;

           &lt;/ bean &gt;

       &lt;/ property &gt;

       &lt; property name = "passwordEncoder" ref = "passwordEncoder" /&gt;

    &lt;/ bean &gt;

 

 

4 ． &lt; bean id = "jdbcDaoImpl"

          class = "org.acegisecurity.userdetails.jdbc.JdbcDaoImpl" &gt;

        &lt; property name = "dataSource" ref = "dataSource" /&gt;

        &lt; property name = "usersByUsernameQuery" &gt;

            &lt; value &gt;

                select loginid,passwd,1 from users where status='1' and loginid = ?

            &lt;/ value &gt;

        &lt;/ property &gt;

        &lt; property name = "authoritiesByUsernameQuery" &gt;

            &lt; value &gt;

                select u.loginid,p.name from

                users u,roles r,permissions p,user\_role ur,role\_permis rp

                where

                u.id=ur.user\_id and