Skip to content

Instantly share code, notes, and snippets.

@efraimcf
Created June 2, 2015 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efraimcf/8aa69cb2744721481827 to your computer and use it in GitHub Desktop.
Save efraimcf/8aa69cb2744721481827 to your computer and use it in GitHub Desktop.
Configuration for Spring security with LDAP Authentication
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/home*" access="isAuthenticated()" />
<security:form-login login-page="/login"
default-target-url="/home"
login-processing-url="/login.servlet"
username-parameter="username"
password-parameter="password"
authentication-failure-url="/login?failed" />
<security:logout logout-url="/logout.servlet"
delete-cookies="JSESSIONID"
logout-success-url="/login?logout" />
<security:access-denied-handler error-page="/erro?code=401" />
</security:http>
<security:authentication-manager>
<security:authentication-provider ref="myCustomLdapAuthenticationProvider" />
</security:authentication-manager>
<security:ldap-server ldif="classpath:spring\test-server.ldif"/>
<security:authentication-manager>
<security:ldap-authentication-provider
group-search-filter="member={0}"
group-search-base="ou=groups"
user-search-base="ou=people"
user-search-filter="uid={0}"
/>
<security:authentication-provider ref='myCustomLdapAuthenticationProvider' />
</security:authentication-manager>
<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="ldap://localhost:33389/dc=springframework,dc=org"/>
</bean>
<bean id="myCustomLdapAuthenticationProvider" class="br.com.project.auth.MyCustomAuthenticationProvider">
<constructor-arg ref="bindAuthenticator" />
<constructor-arg ref="authoritiesPopulator"/>
</bean>
<bean id="authoritiesPopulator" class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource" />
<constructor-arg value="ou=groups" />
<property name="groupSearchFilter" value="(member={0})"/>
<property name="rolePrefix" value="ROLE_"/>
<property name="searchSubtree" value="true"/>
<property name="convertToUpperCase" value="true"/>
</bean>
<bean id="bindAuthenticator" class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="contextSource" />
<property name="userSearch">
<bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value="ou=people"/>
<constructor-arg index="1" value="(uid={0})"/>
<constructor-arg index="2" ref="contextSource" />
</bean>
</property>
</bean>
<bean id="passwordEncoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/>
<!-- <bean id="loggerListener" class="org.springframework.security.access.event.LoggerListener" /> -->
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment