Skip to content

Instantly share code, notes, and snippets.

@Promichel
Created November 9, 2011 13:48
Show Gist options
  • Save Promichel/1351470 to your computer and use it in GitHub Desktop.
Save Promichel/1351470 to your computer and use it in GitHub Desktop.
Spring Security 3.1 with LDAP Auth Provider
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<global-method-security secured-annotations="enabled" jsr250-annotations="enabled"/>
<!-- Automatically receives AuthenticationEvent messages -->
<beans:bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
<!-- use-expressions="true" -->
<!-- Resources available without login -->
<http pattern="/css/**" security="none"/>
<http pattern="/img/**" security="none"/>
<http pattern="/js/**" security="none"/>
<http pattern="/login.html" security="none"/>
<!-- PrimeFaces Filter for Version 2 and 3 -->
<http pattern="/javax.faces.resource/themes/sam/theme.css.html" security="none"/>
<http pattern="/javax.faces.resource/themes/aristo/theme.css.html" security="none"/>
<http pattern="/javax.faces.resource/theme.css.html" security="none"/>
<http pattern="/favicon.ico" security="none"/>
<http auto-config="true" use-expressions="true"
access-denied-page="/login.html">
<intercept-url pattern="${security.intercept}" access="!isAnonymous()"/>
<form-login
login-processing-url="/j_spring_security_check"
login-page="/login.html"
default-target-url="/overview.html"
authentication-failure-url="/login.html"/>
<logout logout-success-url="/login.html" invalidate-session="true"/>
<session-management>
<concurrency-control max-sessions="1" error-if-maximum-exceeded="false"/>
</session-management>
</http>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="ldapAuthProvider"/>
</authentication-manager>
<beans:bean id="ldapAuthProvider"
class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
<beans:constructor-arg value="pm.dom"/>
<beans:constructor-arg value="${ldap.hostname}"/>
</beans:bean>
<beans:bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<beans:constructor-arg index="0" value="${ldap.searchBase}"/>
<beans:constructor-arg index="1" value="(sAMAccountName={0})"/>
<beans:constructor-arg index="2" ref="contextSource"/>
<beans:property name="searchSubtree" value="true"/>
</beans:bean>
<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="${ldap.hostname}"/>
</beans:bean>
</beans:beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment