I want to move the LdapAuthenticationProvider, FilterBasedLdapUserSearch and DefaultInitialDirContextFactory to Java code.
Would I put that in a Java Bean or what is the correct way to do that?
In other words, with my current applicationContext set-up, everything works great! How would I split the set-up between XML and Java code?
Suggestions, examples or useful advice is greatly appreciated.
Thank you.
Full applicationContext.xml:
Code:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean class="org.acegisecurity.util.FilterChainProxy" id="filterChainProxy"> <property name="filterInvocationDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /**=httpSessionContextIntegrationFilter,rememberMeProcessingFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor </value> </property> </bean> <bean class="org.acegisecurity.context.HttpSessionContextIntegrationFilter" id="httpSessionContextIntegrationFilter"/> <bean id="rememberMeProcessingFilter" class="org.acegisecurity.ui.rememberme.RememberMeProcessingFilter"> <property name="authenticationManager"> <ref local="authenticationManager"/> </property> <property name="rememberMeServices"> <ref local="rememberMeServices"/> </property> </bean> <bean id="rememberMeServices" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices"> <property name="userDetailsService"> <ref local="ldapAuthProvider"/> </property> <property name="key"> <value>springRocks</value> </property> </bean> <bean id="rememberMeAuthenticationProvider" class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider"> <property name="key"> <value>springRocks</value> </property> </bean> <bean id="logoutFilter" class="org.acegisecurity.ui.logout.LogoutFilter"> <constructor-arg value="/index.jsp?event=0"/> <constructor-arg> <list> <ref bean="rememberMeServices"/> <bean class="org.acegisecurity.ui.logout.SecurityContextLogoutHandler"/> </list> </constructor-arg> </bean> <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter" id="authenticationProcessingFilter"> <property name="authenticationManager" ref="authenticationManager"/> <property name="filterProcessesUrl"> <value>/j_acegi_security_check</value> </property> <property name="authenticationFailureUrl"> <value>/index.jsp?event=1</value> </property> <property name="defaultTargetUrl"> <value>/eaigft/eaigft_add_option.jsf</value> </property> </bean> <bean class="org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter" id="securityContextHolderAwareRequestFilter"/> <bean class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter" id="anonymousProcessingFilter"> <property name="key" value="changeThis"/> <property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS"/> </bean> <bean class="org.acegisecurity.ui.ExceptionTranslationFilter" id="exceptionTranslationFilter"> <property name="authenticationEntryPoint"> <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint"> <property name="loginFormUrl" value="/index.jsp?event=0"/> <property name="forceHttps" value="false"/> </bean> </property> <property name="accessDeniedHandler"> <bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl"> <property name="errorPage" value="/index.jsp?event=3"/> </bean> </property> </bean> <bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.ShaPasswordEncoder"/> <bean class="org.springframework.jndi.JndiObjectFactoryBean" id="dataSource"> <property name="resourceRef"> <value>true</value> </property> <property name="jndiName"> <value>jdbc/MyOracle</value> </property> </bean> <bean class="org.acegisecurity.vote.RoleVoter" id="roleVoter"/> <bean class="org.acegisecurity.vote.UnanimousBased" id="accessDecisionManager"> <property name="allowIfAllAbstainDecisions"> <value>false</value> </property> <property name="decisionVoters"> <list> <ref local="roleVoter"/> </list> </property> </bean> <bean class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint" id="authenticationProcessingFilterEntryPoint"> <property name="loginFormUrl"> <value>/index.jsp</value> </property> <property name="forceHttps"> <value>false</value> </property> </bean> <bean class="org.acegisecurity.vote.AffirmativeBased" id="httpRequestAccessDecisionManager"> <property name="allowIfAllAbstainDecisions"> <value>false</value> </property> <property name="decisionVoters"> <list> <ref bean="roleVoter"/> </list> </property> </bean> <bean class="org.acegisecurity.intercept.web.FilterSecurityInterceptor" id="filterInvocationInterceptor"> <property name="authenticationManager"> <ref bean="authenticationManager"/> </property> <property name="accessDecisionManager"> <ref local="httpRequestAccessDecisionManager"/> </property> <property name="objectDefinitionSource"> <value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON PATTERN_TYPE_APACHE_ANT /index.jsp=ROLE_ANONYMOUS,ROLE_USERONE,ROLE_USERTWO /common/**=ROLE_ANONYMOUS,ROLE_USERONE /login/**=ROLE_ANONYMOUS,ROLE_USERONE,ROLE_USERTWO /resources/**=ROLE_ANONYMOUS,ROLE_USERONE,ROLE_USERTWO /browser/**=ROLE_USERONE /theme/**=ROLE_ANONYMOUS,ROLE_USERONE,ROLE_USERTWO /**=ROLE_ANONYMOUS,ROLE_USERONE,ROLE_USERTWO </value> </property> </bean> <bean class="org.acegisecurity.providers.ProviderManager" id="authenticationManager"> <property name="providers"> <list> <ref local="ldapAuthProvider"/> <bean class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider"> <property name="key" value="changeThis"/> </bean> <bean class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider"> <property name="key" value="changeThis"/> </bean> </list> </property> </bean> <bean id="initialDirContextFactory" class="org.acegisecurity.ldap.DefaultInitialDirContextFactory"> <constructor-arg value="ldap://url.company.com"/> <property name="managerDn"> <value>CN=user,DC=company,DC=com</value> </property> <property name="managerPassword"> <value>password</value> </property> </bean> <bean id="userSearch" class="org.acegisecurity.ldap.search.FilterBasedLdapUserSearch"> <constructor-arg index="0"> <value>OU=BusinessUnits,DC=company,DC=com</value> </constructor-arg> <constructor-arg index="1"> <value>(&(sAMAccountName={0}))</value> </constructor-arg> <constructor-arg index="2"> <ref local="initialDirContextFactory"/> </constructor-arg> <property name="searchSubtree"> <value>true</value> </property> </bean> <bean id="ldapAuthProvider" class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider"> <constructor-arg> <bean class="org.acegisecurity.providers.ldap.authenticator.BindAuthenticator"> <constructor-arg> <ref local="initialDirContextFactory"/> </constructor-arg> <property name="userSearch" ref="userSearch"/> </bean> </constructor-arg> <constructor-arg> <bean class="org.acegisecurity.providers.ldap.populator.DefaultLdapAuthoritiesPopulator"> <constructor-arg> <ref local="initialDirContextFactory"/> </constructor-arg> <constructor-arg> <value>OU=DTN Groups,DC=company,DC=com</value> </constructor-arg> <property name="groupRoleAttribute"> <value>cn</value> </property> </bean> </constructor-arg> </bean> <bean class="org.acegisecurity.event.authentication.LoggerListener" id="loggerListener"/> </beans>



