The following example defines a Bean and associated form that presents a login form to a user until the user’s login succeeds, then lists some details about the account the user logged in with after the login is successful. This example illustrates the use of the LoginUserAuthority interface and some features of the Persona interface.

Authenticate Bean (Authenticate.java)
import java.io.*;
import javax.servlet.http.*;
import atg.security.*;
import atg.servlet.*;

/**
 * A bean that authenticates and identifies a user.
 */
public class Authenticate extends DynamoServlet
{
  private LoginUserAuthority mAuthority;
  private String mLoginFailedPage;
  private User mUser = new User();
  private String mLogin;
  private String mPassword;

  /////////////////////
  // Bean properties //
  /////////////////////

  /**
   * Returns true if the user has been authenticated.
   */
  public boolean isAuthenticated()
  {
    return mUser.getPersonae(mAuthority) != null;
  }

  /**
   * Returns the page that the browser will be redirected to when a login
   * fails.
   */
  public String getLoginFailedPage()
  {
    return mLoginFailedPage;
  }

  /**
   * Changes the page that the browser will be redirected to when a login
   * fails.
   */
  public void setLoginFailedPage(String pPage)
  {
    mLoginFailedPage = pPage;
  }

  /**
   * Returns the persona for the currently logged-in user, if any.
   */
  private Persona getLoginPersona()
  {
    Persona[] loginPersonae = mUser.getPersonae(mAuthority);
    if ((loginPersonae == null) || (loginPersonae.length == 0))
      return null;
    else
      return loginPersonae[0];
  }

  /**
   * Returns the account name that the user logged in with.
   */
  public String getUserAccount()
  {
    Persona loginPersona = getLoginPersona();
    if (loginPersona == null)
      return "<not logged in>";
    else
      return loginPersona.getName();
  }

  /**
   * Returns the list of groups that the logged-in user is a member of.
   */
  public String[] getUserGroups()
  {
    Persona loginPersona = getLoginPersona();
    if (loginPersona == null)
      return new String[] { "<not logged in>" };

    // convert set of personae to a set of account names
    Persona[] groups = loginPersona.getSubPersonae();
    if ((groups == null) || (groups.length == 0))
      return new String[] { "<no groups>" };
    String[] groupNames = new String[groups.length];
    for (int i = 0; i < groups.length; i++)
      groupNames[i] = groups[i].getName();
    return groupNames;
  }

  /**
   * Returns the currently configured user authority.
   */
  public LoginUserAuthority getUserAuthority()
  {
    return mAuthority;
  }

  /**
   * Changes the user authority used for authentication.
   */
  public void setUserAuthority(LoginUserAuthority pAuthority)
  {
    mAuthority = pAuthority;
  }

  /////////////////////
  // Form properties //
  /////////////////////

  public String getLogin()
  {
    return mLogin;
  }

  public void setLogin(String pLogin)
  {
    mLogin = pLogin;
  }

  public String getPassword()
  {
    return mPassword;
  }

  public void setPassword(String pPassword)
  {
    mPassword = pPassword;
  }

  //////////////////
  // Form handler //
  //////////////////

  /**
   * Handles a form submission to perform a login.
   */
  public void handleAuthenticate(DynamoHttpServletRequest pRequest,
    DynamoHttpServletResponse pResponse)
  {
    try {
      // Check validity of form properties
      if ((mLogin == null) || (mLogin.length() == 0) ||
          (mPassword == null)) {
        pResponse.sendLocalRedirect(mLoginFailedPage, pRequest);
        return;
      }

      // Hash the password as required by the user authority. In a more
      // tightly coupled client/server arrangement the client would obtain
      // the password hasher from the user authority via RMI and pass the
      // hash and the hash key back to the server, but we can't do that
      // in the browser interface so instead we do it all in the server.
      PasswordHasher hasher = mAuthority.getPasswordHasher();
      String hashedPassword;
      if (hasher == null)
        hashedPassword = mPassword; // not hashed
      else
        hashedPassword = hasher.hashPasswordForLogin(mPassword);

      // Perform the login
      if (!mAuthority.login(mUser, mLogin, hashedPassword,
                            hasher.getPasswordHashKey()))
        pResponse.sendLocalRedirect(mLoginFailedPage, pRequest);
    }
    catch (IOException e) {}
    finally { // clear out password
      mPassword = null;
    }
  }
}
Authenticate Bean Configuration file (Authenticate.properties)
# /atg/dynamo/security/examples/Authenticate
$class=Authenticate
$scope=session
userAuthority=/atg/dynamo/security/AdminUserAuthority
loginFailedPage=loginfailed.html
Authenticate JSP (authenticate.jsp)

The authenticate.jsp file is as follows:

<%@ taglib uri="/dspTaglib" prefix="dsp" %>
<%@ page import="atg.servlet.*"%>
<dsp:page>

<html>
<dsp:importbean bean="/atg/dynamo/droplet/ForEach"/>
<dsp:importbean bean="/atg/dynamo/droplet/Switch"/>
<dsp:importbean bean="/atg/dynamo/security/examples/Authenticate"/>

<body>
<!-- Display a login form if they have not logged in yet,
  -- or their login attributes if they have.
  -->

<dsp:droplet name="/atg/dynamo/droplet/Switch">
  <dsp:param bean="Authenticate.authenticated" name="value"/>
  <dsp:oparam name="false">
    Please log in:<p>

    <dsp:form action="<%=ServletUtil.getDynamoRequest(request).getRequestURI()%>"
      method="post">
      <table>
        <tr><td><b>Name:</b></td><td><dsp:input bean="Authenticate.login"
          type="text"/></td></tr>
        <tr><td><b>Password:</b></td><td><dsp:input bean="Authenticate.password"
          type="password"/></td></tr>
      </table><p>
      <dsp:input bean="Authenticate.authenticate" type="submit" value="Login"/>
    </dsp:form>
  </dsp:oparam>

  <dsp:oparam name="true">
    <b>You are logged in as</b> '<dsp:valueof
      bean="Authenticate.userAccount">?</dsp:valueof>'<p>
    <b>You are a member of the following groups:</b><p>
    <dsp:droplet name="/atg/dynamo/droplet/ForEach">
      <dsp:param bean="Authenticate.userGroups" name="array"/>
      <dsp:oparam name="output">
         <dsp:valueof param="element">?</dsp:valueof><br>
      </dsp:oparam>
      </dsp:droplet><!-- ForEach -->
    </table>
  </dsp:oparam>
</dsp:droplet><!-- Switch -->
</body>

</html>

</dsp:page>