Configure CAS with LDAP
by krishna
Here are the few steps to configure LDAP with CAS server
- Download CAS Server 3.3.2 from the JaSig
- Unzip the file in C drive. Assume C:/cas-server-3.3.2
- Create new Java file (AuthenticatedLdapContextSource.java). I recommend, copy & paste the below code.
- Update deployerConfigContent.xml
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xmlns:p=”http://www.springframework.org/schema/p”
xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd”>
<bean id=”authenticationManager”
class=”org.jasig.cas.authentication.AuthenticationManagerImpl”>
<property name=”credentialsToPrincipalResolvers”>
<list>
<bean
class=”org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver” />
<bean
class=”org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver” />
</list>
</property>
<property name=”authenticationHandlers”>
<list>
<bean class=”org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler”
p:httpClient-ref=”httpClient” />
<!–
@author Krishna Manchikalapudi
BEGIN: LDAP Integration
–>
<bean
class=”org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler”>
<property name=”name” value=”LOCALENTITY_LDAP” />
<property name=”filter” value=”uid=%u” />
<property name=”searchBase” value=”dc=localentity,dc=com” />
<property name=”contextSource” ref=”contextSource” />
</bean>
<!– END: LDAP Integration –>
</list>
</property>
</bean><bean id=”userDetailsService” class=”org.springframework.security.userdetails.memory.InMemoryDaoImpl”>
<property name=”userMap”>
<value></value>
</property>
</bean>
<bean id=”attributeRepository”
class=”org.jasig.services.persondir.support.StubPersonAttributeDao”>
<property name=”backingMap”>
<map>
<entry key=”uid” value=”uid” />
<entry key=”eduPersonAffiliation” value=”eduPersonAffiliation” />
<entry key=”groupMembership” value=”groupMembership” />
</map>
</property>
</bean>
<bean
id=”serviceRegistryDao”
class=”org.jasig.cas.services.InMemoryServiceRegistryDaoImpl” />
<!–
@author Krishna Manchikalapudi
BEGIN: LDAP Integration
–>
<bean class=”org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler”>
<property name=”filter” value=”sAMAccountName=%u” />
<property name=”searchBase” value=”ou=People,dc=localentity,dc=com” />
<property name=”contextSource” ref=”contextSource” />
<property name=”ignorePartialResultException” value=”yes” />
</bean><bean id=”contextSource” class=”com.localentity.cas.adaptors.ldap.util.AuthenticatedLdapContextSource”>
<property name=”url” value=”ldap://ldap.localentity.com:389″ />
</bean>
<!– END: LDAP Integration –>
</beans> - Update C:/cas-server-3.3.2/cas-server-webapp/pom.xml under dependencies with the below code
- Build the cas project C:/cas-server-3.3.2/mvn package install
- Move the cas.war (located at C:cas-server-3.3.2cas-server-webapptarget) to tomcat webapps
- Start tomcat and go to http://localhost:8080/cas/
- Login with the LDAP userid & password
package com.localentity.cas.adaptors.ldap.util;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.springframework.ldap.core.support.LdapContextSource;
/**
* @author Krishna Manchikalapudi
* http://www.LocalEntity.com
*/
public class AuthenticatedLdapContextSource extends LdapContextSource {
private DirContext context;
private String url;
public DirContext getDirContext(final String username,
final String password) {
String basedn = “dc=localentity,dc=com”;
String base = “ou=People,dc=localentity,dc=com”;;
String dn = (“uid=” + username + “,” + base);
Hashtable<String, String> authEnv = new Hashtable<String, String>();
authEnv.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”);
authEnv.put(Context.PROVIDER_URL, url);
authEnv.put(Context.SECURITY_AUTHENTICATION, “simple”);
authEnv.put(Context.SECURITY_PRINCIPAL, dn);
authEnv.put(“basedn”, basedn);
authEnv.put(Context.SECURITY_CREDENTIALS, password);
try {
// Create the initial directory context
context = new InitialDirContext(authEnv);
} catch (Exception e) {
System.err.println(“Authentication failed: ” + e);
context = null;
}
return context;
}
}
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-support-ldap</artifactId>
<version>3.3.2</version>
</dependency>
Here are the few steps to configure LDAP with CAS server Download CAS Server 3.3.2 from the JaSig Unzip the file in C drive. Assume C:/cas-server-3.3.2 Create new Java file (AuthenticatedLdapContextSource.java). I recommend, copy & paste the below code. package com.localentity.cas.adaptors.ldap.util; import java.util.Hashtable; import javax.naming.Context; import javax.naming.directory.DirContext; import javax.naming.directory.InitialDirContext; import org.springframework.ldap.core.support.LdapContextSource; /** * @author Krishna…
Recent Comments
Archives
- August 2025
- July 2025
- June 2025
- May 2025
- April 2025
- March 2025
- November 2024
- October 2024
- September 2024
- August 2024
- July 2024
- June 2024
- May 2024
- April 2024
- March 2024
- February 2024
- January 2024
- December 2023
- November 2023
- February 2012
- January 2012
- December 2011
- October 2011
- August 2011
- July 2011
- May 2011
- January 2011
- November 2010
- October 2010
- September 2010
- July 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- August 2008
- July 2008
- June 2008
- December 2007
- April 2007
- January 2007