Configure CAS with LDAP

Here are the few steps to configure LDAP with CAS server

  1. Download CAS Server 3.3.2 from the JaSig
  2. Unzip the file in C drive. Assume C:/cas-server-3.3.2
  3. Create new Java file (AuthenticatedLdapContextSource.java). I recommend, copy & paste the below code.

  4. 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;
    }

    }

  5. 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>

  6. Update C:/cas-server-3.3.2/cas-server-webapp/pom.xml under dependencies with the below code
  7. <dependency>
    <groupId>org.jasig.cas</groupId>
    <artifactId>cas-server-support-ldap</artifactId>
    <version>3.3.2</version>
    </dependency>

  8. Build the cas project C:/cas-server-3.3.2/mvn package install
  9. Move the cas.war (located at C:cas-server-3.3.2cas-server-webapptarget) to tomcat webapps
  10. Start tomcat and go to http://localhost:8080/cas/
  11. Login with the LDAP userid & password

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…

Leave a Reply

Your email address will not be published. Required fields are marked *