Work in progress

Closed User Groups with Lenya

What is a Closed User Group (CUG)?

A typical example of a closed user groups (aka CUG) is a website that has a "Member's only" section. To access the content in that "Member's only" section the user needs to login using a username and password.

The authoring mode of Lenya is something quite similar: You need to login first. In fact, you can use the very same AAA framework that Lenya uses in authoring mode for Live mode as well. But as you will find out throughout this HOWTO, there are certain things to take into account and certain decisions to make.

For some background on how Lenya handles AAA at all, please see: OverviewAuthenticationAndAuthorization

Design decisions

Member yes/no versus Roles

The registration process

Implementation work in Lenya

Restricting access to live content in authoring

The login screen

The logout button

Though some website designer often overlook this, any website that requires it's users to login should provide a clean way to logout as well. Of course there are several alternatives ways to invalidate the user's session:

None of these methods is a clean way to end a session on a website. As users get more and more concerned with security and privacy while using the web, they will want a distinct logout button with a confirmation that they really invalidated the session they have been using so nobody can steal it.

For some more information on how the underlying Cocoon handles session please see:

Implementing a proper logout is quite straigtforward.

First of all, we need a publication specific usecase. Put the file usecase-session.xmap into your PUB_HOME directory:

<?xml version="1.0" encoding="UTF-8"?>
  Copyright 1999-2004 The Apache Software Foundation

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  See the License for the specific language governing permissions and
  limitations under the License.

<!-- $Id: usecase-bxeng.xmap,v 1.17 2004/05/23 12:52:44 gregor Exp $ -->

<map:sitemap xmlns:map="">

        <!-- =========================== Components ================================ -->
                <map:generators default="file"/>
                <map:transformers default="xalan">
      <map:transformer name="cinclude"
                <map:readers default="resource"/>
                <map:serializers default="xhtml"/>
                <map:matchers default="wildcard"/>
      <map:action name="upload" logger="sitemap.action.upload" src="org.apache.lenya.cms.cocoon.acting.UploadAction" />

      <map:selector name="request-method" logger="sitemap.selector.request-method"


  <!-- =========================== Resources ================================ -->

    <map:resource name="style-cms-page">
      <map:transform type="i18n">
        <map:parameter name="locale" value="{request:locale}"/>
      <map:transform src="../../xslt/util/page2xhtml.xsl">
        <map:parameter name="contextprefix" value="{request:contextPath}"/>
      <map:transform src="../../xslt/util/strip_namespaces.xsl"/>
      <map:select type="parameter">
        <map:parameter name="statusCode" value="{statusCode}"/>
        <map:when test="">
          <map:serialize type="html" />
          <map:serialize type="html" status-code="{statusCode}"/>

    <map:resource name="cms-screen-xml">
          <map:generate src="../../content/{serverpage}" type="serverpages"/>
          <map:transform src="../../xslt/{stylesheet}">
            <map:parameter name="use-request-parameters" value="true"/>

    <map:resource name="cms-screen">
      <map:call resource="cms-screen-xml">
        <map:parameter name="serverpage" value="{serverpage}"/>
        <map:parameter name="stylesheet" value="{stylesheet}"/>
      <map:call resource="style-cms-page"/>


        <!-- =========================== Pipelines ================================ -->


    <map:pipeline type="noncaching">

      <map:match type="usecase" pattern="session">

      <map:match type="step" pattern="logout">
        <map:act type="session">
          <map:parameter name="action" value="terminate"/>
        <map:redirect-to uri="/index.html" />





Note the <map:redirect-to uri="/index.html" /> part. This is necessary as every pipeline needs to end in a serializer. Alternatively you could generate any type of landing page here. In this example we just invalidate the user's session and redirect to the start page.

Now we need to call this usecase from somewhere.

A typical solution would be to have a page with a form button "Logout" on it somewhere in your application. When the user clicks on that button, the form will be posted to the usecase. This is quite clean and simple. It could look like this:

<form action="/index.html?lenya.usecase=session&amp;lenya.step=logout" method="POST">
  <input type="submit" value="Logout"/>

Lenya Developer's Dicussing: Lenya itself does not use the SessionAction from Cocoon to invalidate the session when logging out of the authoring mode. Instead it uses an XSP (see: LENYA_HOME/lenya/content/ac/logout.xsp) which invalidates the session upon logout.

Note (AndreasHartmann): This is just legacy. In Lenya 2.0, the login/logout usecases have been refactored using the usecase framework, which means the deprecated XSP+action concept is not necessary anymore.

Optional Features

Displaying information about the current user

TODO: Implement a password reminder function

HowToClosedUserGroup (last edited 2009-09-20 23:27:56 by localhost)