Dashboard > Community Wiki > ... > Integration > Magnolia CAS
Magnolia CAS Log In View a printable version of the current page.

Added by Grégory Joseph , last edited by Boris Kraft on Jun 23, 2008  (view change)
Labels: 

You will find a tutorial written by Roberto Cosenza here:
Magnolia and CAS

The above tutorial is useful in terms of pointing you in the right direction, but it is hopelessly out of date now. I recently interfaced my Magnolia instance with CAS and this is how I did it (disclaimer, this is how I did it, possibly there are better ways).

  • Download the Yale casclient.jar (version 2.1.1) and put it in your Magnolia/WEB-INF/lib folder  (*note the 2.1.1 version of casclient has an error that may cause issues on some application servers such as Tomcat, so if you get a SerialisationException pointing to the CASReciept class then you will have to download the casclient 2.1.1 source code (available on google code) and add 'implements serializable' to the CASReciept class definition and re-jar it.
  • Check out the Magnolia source code (follow the tutorial found elsewhere on this wiki)
  • Add the following class to the code:
/**
 * Magnolia and its source-code is licensed under the LGPL. You may copy, adapt,
 * and redistribute this file for commercial or non-commercial use. When
 * copying, adapting, or redistributing this document in keeping with the
 * guidelines above, you are required to provide proper attribution to obinary.
 * If you reproduce or distribute the document without making any substantive
 * modifications to its content, please use the following attribution line:
 * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights
 * reserved.
 */
package info.magnolia.cms.filters;

import info.magnolia.cms.beans.config.ContentRepository;
import info.magnolia.cms.core.Content;
import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.core.Path;
import info.magnolia.cms.security.Authenticator;
import info.magnolia.cms.security.Listener;
import info.magnolia.cms.security.Lock;
//import info.magnolia.cms.security.SessionAccessControl;
import info.magnolia.content2bean.Content2BeanException;
import info.magnolia.content2bean.Content2BeanUtil;
import info.magnolia.context.MgnlContext;
import info.magnolia.cms.security.URISecurityFilter;

import java.io.IOException;
import java.util.*;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import edu.yale.its.tp.cas.client.filter.CASFilter;

/**
 * @author Chris Robson and Francis Calleja
 */
public class CASSecurityFilter extends URISecurityFilter{

    protected Logger logger = Logger.getLogger(getClass());
    private CASFilter casFilter;
    private static final String PROTECTED_URI_LIST = "server/protectedURIList";

    public void init(FilterConfig filterConfig) throws ServletException {
        logger.debug("CASSecurityFilter initialising.");
        try {
            casFilter = new CASFilter();
            casFilter.init(filterConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        logger.debug("CASSecurityFilter initialised.");
    }

    public void destroy() {
        casFilter.destroy();
    }

    public boolean isProtectedURI (HttpServletRequest request){
        String requestURI = request.getRequestURI();
        for(Iterator i = getProtectedURIList().iterator(); i.hasNext();){
            String uri = (String)i.next();
	    if(uri == null || uri.trim().equals("")){//skip any rules that are blank
 		continue;
	    }
            if(requestURI.startsWith(uri)){
                logger.debug(requestURI + " is protected by following rule: " + uri);
                return true;
            }
        }
        logger.debug(requestURI + " is not protected");
        return false;
    }

    public Set getProtectedURIList(){
        Map map = null;
        try {
            final HierarchyManager hm = MgnlContext
                .getSystemContext()
                .getHierarchyManager(ContentRepository.CONFIG);
            final Content node = hm.getContent(PROTECTED_URI_LIST);
            map = Content2BeanUtil.toMap(node);
            logger.debug("list of protected uri's is: \n" + map.toString());
        }
        catch (PathNotFoundException e) {
            logger.warn("Config : no filters configured at " + PROTECTED_URI_LIST); //$NON-NLS-1$
        }
        catch (RepositoryException e) {
            logger.error("can't read filter definitions", e);
        }
        catch (Content2BeanException e) {
            logger.error("can't create filter objects", e);
        }
        if(map == null){
            return new HashSet();
        }
        return new HashSet(map.values());
    }
    public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)throws IOException, ServletException {
        if(isProtectedURI(request)){
            logger.debug("protected uri: "+ request.getRequestURI() + " being cas filtered");
            casFilter.doFilter(request, response, chain);
        }else{
            super.doFilter(request, response, chain);
        }
    }

}

You now need to re-build the code. To do so you should follow these steps:

  • Install the casclient jar into your local maven repository using this command: mvn install:install-file -DgroupId=cas-client -DartifactId=cas-client -Dversion=1.0 -Dpackaging=jar -Dfile=path-to-jar-file
  •  run 'mvn clean package' this should build the project.
  • Copy the magnolia* jars from <magnolia code dir>\magnolia-empty-webapp\target\magnolia-empty-webapp-3.5.5-SNAPSHOT\WEB-INF\lib into your WEB-INF/lib directory make sure to delete the old ones from the WEB-INF/lib folder first

In your Magnolia Admin Central make the following folder 'server/protectedURIList' (ie, create a folder in the server folder called protectedURIList). In protectedURIList you can now make as many nodes as you like to define which URI's you want to secure. So to clarify, you should have the following structure:

folder->server
    folder->protectedURIList

		nodeData-> 001 		value->/homepage/protectedpage.html
		nodeData-> 002 		value->/marketing/boo/protectedbranch/

The next step is to modify your web.xml within your magnolia/WEB-INF directory to give your new filter its parameters (bolded) as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <description>Magnolia</description>
  <display-name>magnolia</display-name>
  <distributable/>
  <filter>
    <display-name>Magnolia global filters</display-name>
    <filter-name>magnoliaFilterChain</filter-name>
    <filter-class>info.magnolia.cms.filters.MgnlMainFilter</filter-class>
    <init-param>
        <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name>
      <param-value>your-login-url-here</param-value>
    </init-param>
    <init-param>
      <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name>
      <param-value>your-validate-url-here</param-value>
    </init-param>
    <init-param>
      <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name>
      <param-value>your-return-url-here</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>magnoliaFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>

  <listener>
    <listener-class>info.magnolia.cms.servlets.MgnlServletContextListener</listener-class>
  </listener>
  <!-- These are the default paths searched for magnolia configuration. Uncomment if you need to customize this. -->
  <!-- Be aware that your container might do its own variables replacement here (Resin does, Tomcat doesn't, for instance -->
  <!--
  <context-param>
    <param-name>magnolia.initialization.file</param-name>
    <param-value>
      WEB-INF/config/${servername}/${webapp}/magnolia.properties, WEB-INF/config/${servername}/magnolia.properties,
      WEB-INF/config/${webapp}/magnolia.properties, WEB-INF/config/default/magnolia.properties,
      WEB-INF/config/magnolia.properties
    </param-value>
  </context-param>
  -->
</web-app>

The final step is to modify server/filters/uriSecurity/class to point to the CASSecurityFilter class.

Anyway, HTH.

In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 10:26:35 AM

Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators