FANDOM


Acegi Security base configuration Edit

Used versions:

  • Spring Framework 1.2.8
  • Acegi Security 1.0.3

This configuration provides

  • Anonymous authentication
  • Logout
  • Form based login
  • Different authentication backends
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
   <!-- Uncomment this for properties-file based authentication -->
   <!--   <import resource="inmemory.xml" />-->

   <!-- Uncomment this for Lotus Domino based authentication -->
   <!--   <import resource="domino.xml" />-->

   <!-- Uncomment this for Oracle based authentication -->
   <!--   <import resource="oracle.xml" />-->

   <!-- Uncomment this for Active Directory authentication -->
   <!--   <import resource="msad.xml" />-->

   <bean id="filterChainProxy"
      class="org.acegisecurity.util.FilterChainProxy">
      <property name="filterInvocationDefinitionSource">
         <value>
            <![CDATA[
        CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
        PATTERN_TYPE_APACHE_ANT
        /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
        ]]>
         </value>
      </property>
   </bean>

   <bean id="logoutFilter"
      class="org.acegisecurity.ui.logout.LogoutFilter">
      <constructor-arg value="/main.htm"></constructor-arg>
      <constructor-arg>
         <list>
            <bean
               class="org.acegisecurity.ui.logout.SecurityContextLogoutHandler" />
         </list>
      </constructor-arg>
      <property name="filterProcessesUrl" value="/logout.htm" />
   </bean>

   <bean id="anonymousAuthenticationProvider"
      class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
      <property name="key">
         <value>foobar</value>
      </property>
   </bean>

   <bean id="anonymousProcessingFilter"
      class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
      <property name="key">
         <value>foobar</value>
      </property>
      <property name="userAttribute">
         <value>anonymousUser,ACEGI_ANONYMOUS</value>
      </property>
   </bean>

   <bean id="authenticationManager"
      class="org.acegisecurity.providers.ProviderManager">
      <property name="providers">
         <list>
            <ref bean="authenticationProvider" />
            <ref bean="anonymousAuthenticationProvider" />
         </list>
      </property>
   </bean>

   <bean id="cacheManager"
      class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
      <property name="configLocation">
         <value>classpath:/ehcache-failsafe.xml</value>
      </property>
   </bean>

   <bean id="userCacheBackend"
      class="org.springframework.cache.ehcache.EhCacheFactoryBean">
      <property name="cacheManager">
         <ref local="cacheManager" />
      </property>
      <property name="cacheName">
         <value>userCache</value>
      </property>
   </bean>

   <bean id="userCache"
      class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
      <property name="cache">
         <ref local="userCacheBackend" />
      </property>
   </bean>

   <bean id="authenticationProcessingFilter"
      class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
      <property name="authenticationManager">
         <ref bean="authenticationManager" />
      </property>
      <property name="authenticationFailureUrl">
         <value>/login.jsp?error=1</value>
      </property>
      <property name="defaultTargetUrl">
         <value>/</value>
      </property>
      <property name="filterProcessesUrl">
         <value>/j_acegi_security_check</value>
      </property>
   </bean>

   <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter">
      <property name="rolePrefix">
         <value>ACEGI_</value>
      </property>
   </bean>

   <bean id="accessDecisionManager"
      class="org.acegisecurity.vote.AffirmativeBased">
      <property name="decisionVoters">
         <list>
            <ref local="roleVoter" />
         </list>
      </property>
   </bean>

   <bean id="exceptionTranslationFilter"
      class="org.acegisecurity.ui.ExceptionTranslationFilter">
      <property name="authenticationEntryPoint">
         <ref local="authenticationProcessingFilterEntryPoint" />
      </property>
      <property name="accessDeniedHandler">
         <bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl">
            <property name="errorPage" value="/login.jsp?error=1" />
         </bean>
      </property>
   </bean>

   <bean id="authenticationProcessingFilterEntryPoint"
      class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
      <property name="loginFormUrl">
         <value>/login.jsp</value>
      </property>
      <property name="forceHttps">
         <value>false</value>
      </property>
   </bean>

   <bean id="httpSessionContextIntegrationFilter"
      class="org.acegisecurity.context.HttpSessionContextIntegrationFilter">
      <property name="context">
         <value>org.acegisecurity.context.SecurityContextImpl</value>
      </property>
   </bean>

   <bean id="filterSecurityInterceptor"
      class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
      <property name="authenticationManager">
         <ref bean="authenticationManager" />
      </property>
      <property name="accessDecisionManager">
         <ref bean="accessDecisionManager" />
      </property>
      <property name="objectDefinitionSource">
         <value>
            <![CDATA[
        CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
        PATTERN_TYPE_APACHE_ANT
        /secret.htm=ACEGI_ADMIN
        /secure.htm=ACEGI_ADMIN,ACEGI_USER
        /**/*.htm=ACEGI_ADMIN,ACEGI_USER,ACEGI_ANONYMOUS
        ]]>
         </value>
      </property>
   </bean>
</beans>

To use it you have to include this to your web.xml

   <filter>
      <filter-name>Acegi-Security</filter-name>
      <filter-class>
         org.acegisecurity.util.FilterToBeanProxy
      </filter-class>
      <init-param>
         <param-name>targetClass</param-name>
         <param-value>
            org.acegisecurity.util.FilterChainProxy
         </param-value>
      </init-param>
   </filter>

   <filter-mapping>
      <filter-name>Acegi-Security</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.