You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by mp...@apache.org on 2003/01/13 21:09:47 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/util ParseExceptionMessage.java

mpoeschl    2003/01/13 12:09:46

  Modified:    src/java/org/apache/turbine/services/security/ldap
                        LDAPSecurityConstants.java LDAPSecurityService.java
                        LDAPUser.java LDAPUserManager.java
  Removed:     src/java/org/apache/turbine/services/security/ldap/util
                        ParseExceptionMessage.java
  Log:
  TTWS34:
  Implemented the following functions in LDAPUserManager:
  store(), createAccount() and removeAccount().
  patch by Humberto Hernandez <hh...@itweb.com.mx>
  
  Revision  Changes    Path
  1.3       +65 -22    jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPSecurityConstants.java
  
  Index: LDAPSecurityConstants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPSecurityConstants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LDAPSecurityConstants.java	31 Dec 2002 12:51:11 -0000	1.2
  +++ LDAPSecurityConstants.java	13 Jan 2003 20:09:45 -0000	1.3
  @@ -57,6 +57,7 @@
   import java.util.Properties;
   import org.apache.turbine.services.security.TurbineSecurity;
   
  +
   /**
    * <p>This is a static class for defining the default ldap confiquration
    * keys used by core Turbine components.</p>
  @@ -67,27 +68,66 @@
    */
   public class LDAPSecurityConstants
   {
  +    /** Property key */
       static final String LDAP_ADMIN_USERNAME_KEY = "ldap.admin.username";
  +
  +    /** Property key */
       static final String LDAP_ADMIN_PASSWORD_KEY = "ldap.admin.password";
  -    static final String LDAP_HOST_KEY           = "ldap.host";
  -    static final String LDAP_HOST_DEFAULT       = "localhost";
  -    static final String LDAP_PORT_KEY           = "ldap.port";
  -    static final String LDAP_PORT_DEFAULT       = "389";
  -    static final String LDAP_PROVIDER_KEY       = "ldap.provider";
  -    static final String LDAP_PROVIDER_DEFAULT   =
  +
  +    /** Property key */
  +    static final String LDAP_HOST_KEY = "ldap.host";
  +
  +    /** Property default value */
  +    static final String LDAP_HOST_DEFAULT = "localhost";
  +
  +    /** Property key */
  +    static final String LDAP_PORT_KEY = "ldap.port";
  +
  +    /** Property default value */
  +    static final String LDAP_PORT_DEFAULT = "389";
  +
  +    /** Property key */
  +    static final String LDAP_PROVIDER_KEY = "ldap.provider";
  +
  +    /** Property default value */
  +    static final String LDAP_PROVIDER_DEFAULT =
           "com.sun.jndi.ldap.LdapCtxFactory";
  -    static final String LDAP_BASE_SEARCH_KEY    = "ldap.basesearch";
  -    static final String LDAP_USER_USERID_KEY        = "ldap.user.userid";
  -    static final String LDAP_USER_USERNAME_KEY      = "ldap.user.username";
  -    static final String LDAP_USER_USERNAME_DEFAULT  = "turbineUserUniqueId";
  -    static final String LDAP_USER_FIRSTNAME_KEY     = "ldap.user.firstname";
  +
  +    /** Property key */
  +    static final String LDAP_BASE_SEARCH_KEY = "ldap.basesearch";
  +
  +    /** Property key */
  +    static final String LDAP_USER_USERID_KEY = "ldap.user.userid";
  +
  +    /** Property key */
  +    static final String LDAP_USER_USERNAME_KEY = "ldap.user.username";
  +
  +    /** Property default value */
  +    static final String LDAP_USER_USERNAME_DEFAULT = "turbineUserUniqueId";
  +
  +    /** Property key */
  +    static final String LDAP_USER_FIRSTNAME_KEY = "ldap.user.firstname";
  +
  +    /** Property default value */
       static final String LDAP_USER_FIRSTNAME_DEFAULT = "turbineUserFirstName";
  -    static final String LDAP_USER_LASTNAME_KEY      = "ldap.user.lastname";
  -    static final String LDAP_USER_LASTNAME_DEFAULT  = "turbineUserLastName";
  -    static final String LDAP_USER_EMAIL_KEY         = "ldap.user.email";
  -    static final String LDAP_USER_EMAIL_DEFAULT     = "turbineUserMailAddress";
  -    static final String LDAP_USER_PASSWORD_KEY      = "ldap.user.password";
  -    static final String LDAP_USER_PASSWORD_DEFAULT  = "userPassword";
  +
  +    /** Property key */
  +    static final String LDAP_USER_LASTNAME_KEY = "ldap.user.lastname";
  +
  +    /** Property default value */
  +    static final String LDAP_USER_LASTNAME_DEFAULT = "turbineUserLastName";
  +
  +    /** Property key */
  +    static final String LDAP_USER_EMAIL_KEY = "ldap.user.email";
  +
  +    /** Property default value */
  +    static final String LDAP_USER_EMAIL_DEFAULT = "turbineUserMailAddress";
  +
  +    /** Property key */
  +    static final String LDAP_USER_PASSWORD_KEY = "ldap.user.password";
  +
  +    /** Property default value */
  +    static final String LDAP_USER_PASSWORD_DEFAULT = "userPassword";
   
       /**
        * Get all the properties for the security service.
  @@ -127,12 +167,13 @@
       public static String getAdminUsername()
       {
           String str = getProperty(LDAP_ADMIN_USERNAME_KEY);
  +
           /*
            * The adminUsername string contains some
            * characters that need to be transformed.
            */
  -        str = str.replace('/','=');
  -        str = str.replace('%',',');
  +        str = str.replace('/', '=');
  +        str = str.replace('%', ',');
           return str;
       }
   
  @@ -179,12 +220,13 @@
       public static String getBaseSearch()
       {
           String str = getProperty(LDAP_BASE_SEARCH_KEY);
  +
           /*
            * The userBaseSearch string contains some
            * characters that need to be transformed.
            */
  -        str = str.replace('/','=');
  -        str = str.replace('%',',');
  +        str = str.replace('/', '=');
  +        str = str.replace('%', ',');
           return str;
       }
   
  @@ -212,7 +254,8 @@
        */
       public static String getFirstNameAttribute()
       {
  -        return getProperty(LDAP_USER_FIRSTNAME_KEY, LDAP_USER_FIRSTNAME_DEFAULT);
  +        return getProperty(LDAP_USER_FIRSTNAME_KEY,
  +            LDAP_USER_FIRSTNAME_DEFAULT);
       }
   
       /**
  
  
  
  1.9       +256 -172  jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPSecurityService.java
  
  Index: LDAPSecurityService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPSecurityService.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- LDAPSecurityService.java	12 Jan 2003 15:11:04 -0000	1.8
  +++ LDAPSecurityService.java	13 Jan 2003 20:09:45 -0000	1.9
  @@ -84,6 +84,7 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  +
   /**
    * An implementation of SecurityService that uses LDAP as a backend.
    *
  @@ -97,6 +98,7 @@
    */
   public class LDAPSecurityService extends BaseSecurityService
   {
  +
       /** Logging */
       private static Log log = LogFactory.getLog(LDAPSecurityService.class);
   
  @@ -114,44 +116,52 @@
        * into an AccessControlList object.
        *
        * @param user the user for whom the AccessControlList are to be retrieved
  -     * @throws DataBackendException if there was an error accessing the data backend.
  +     * @return the AccessControlList for the user
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
        * @throws UnknownEntityException if user account is not present.
        */
       public AccessControlList getACL(User user)
  -            throws DataBackendException, UnknownEntityException
  +        throws DataBackendException, UnknownEntityException
       {
  -        if(!TurbineSecurity.accountExists(user))
  +        if (!TurbineSecurity.accountExists(user))
           {
  -            throw new UnknownEntityException("The account '" +
  -                        user.getUserName() + "' does not exist");
  +            throw new UnknownEntityException("The account '"
  +                    + user.getUserName() + "' does not exist");
           }
           try
           {
               Hashtable roles = new Hashtable();
               Hashtable permissions = new Hashtable();
  -            // notify the state modifiers (writers) that we want to create the snapshot.
  +
  +            // notify the state modifiers (writers) that we want to create the
  +            // snapshot.
               lockShared();
   
               // construct the snapshot:
               // foreach group in the system
               Iterator groupsIterator = getAllGroups().elements();
  -            while(groupsIterator.hasNext())
  +
  +            while (groupsIterator.hasNext())
               {
  -                Group group = (Group)groupsIterator.next();
  +                Group group = (Group) groupsIterator.next();
   
                   // get roles of user in the group
  -                RoleSet groupRoles = getRoles( user, group );
  +                RoleSet groupRoles = getRoles(user, group);
  +
                   // put the Set into roles(group)
                   roles.put(group, groupRoles);
                   // collect all permissoins in this group
                   PermissionSet groupPermissions = new PermissionSet();
                   // foreach role in Set
                   Iterator rolesIterator = groupRoles.elements();
  -                while(rolesIterator.hasNext())
  +
  +                while (rolesIterator.hasNext())
                   {
  -                    Role role = (Role)rolesIterator.next();
  +                    Role role = (Role) rolesIterator.next();
                       // get permissions of the role
                       PermissionSet rolePermissions = getPermissions(role);
  +
                       groupPermissions.add(rolePermissions);
                   }
                   // put the Set into permissions(group)
  @@ -159,31 +169,42 @@
               }
               return getAclInstance(roles, permissions);
           }
  -        catch(Exception e)
  +        catch (Exception e)
           {
  -            throw new DataBackendException("Failed to build ACL for user '" +
  -                                    user.getUserName() + "'" , e);
  +            throw new DataBackendException("Failed to build ACL for user '"
  +                    + user.getUserName() + "'", e);
           }
           finally
           {
  -            // notify the state modifiers that we are done creating the snapshot.
  +            // notify the state modifiers that we are done creating the snapshot
               unlockShared();
           }
       }
   
  +    /**
  +     * Get the roles for an user in within a group
  +     *
  +     * @param user the user
  +     * @param group the group
  +     * @return the roles
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     */
       private RoleSet getRoles(User user, Group group)
           throws DataBackendException
       {
           Vector roles = new Vector(0);
  +
           try
           {
               DirContext ctx = LDAPUserManager.bindAsAdmin();
   
               String baseSearch = LDAPSecurityConstants.getBaseSearch();
               String filter = "(& ";
  +
               filter += "(objectclass=turbineUserGroup)";
  -            filter += "(turbineUserUniqueId="+user.getUserName()+")";
  -            filter += "(turbineGroup="+group.getName()+")";
  +            filter += "(turbineUserUniqueId=" + user.getUserName() + ")";
  +            filter += "(turbineGroup=" + group.getName() + ")";
               filter += ")";
   
               /*
  @@ -200,12 +221,15 @@
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   Attribute attr = attribs.get("turbineRoleName");
  +
                   if (attr != null)
                   {
                       NamingEnumeration values = attr.getAll();
  -                    while(values.hasMore())
  +
  +                    while (values.hasMore())
                       {
                           Role role = getNewRole(values.next().toString());
  +
                           roles.add(role);
                       }
                   }
  @@ -217,9 +241,9 @@
           }
           catch (NamingException ex)
           {
  -            log.error("NamingException caught",ex);
  +            log.error("NamingException caught", ex);
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
   
           return new RoleSet(roles);
  @@ -237,8 +261,10 @@
        * @param user the user.
        * @param group the group.
        * @param role the role.
  -     * @throws DataBackendException if there was an error accessing the data backend.
  -     * @throws UnknownEntityException if user account, group or role is not present.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if user account, group or role is
  +     *         not present.
        */
       public synchronized void grant(User user, Group group, Role role)
           throws DataBackendException, UnknownEntityException
  @@ -246,40 +272,44 @@
       }
   
       /**
  -      * Revoke a Role in a Group from an User.
  -      *
  -      * @param user the user.
  -      * @param group the group.
  -      * @param role the role.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if user account, group or role is not present.
  -      */
  +     * Revoke a Role in a Group from an User.
  +     *
  +     * @param user the user.
  +     * @param group the group.
  +     * @param role the role.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if user account, group or role is
  +     *         not present.
  +     */
       public synchronized void revoke(User user, Group group, Role role)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Grants a Role a Permission
  -      *
  -      * @param role the Role.
  -      * @param permission the Permission.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if role or permission is not present.
  -      */
  +     * Grants a Role a Permission
  +     *
  +     * @param role the Role.
  +     * @param permission the Permission.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if role or permission is not present.
  +     */
       public synchronized void grant(Role role, Permission permission)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Revokes a Permission from a Role.
  -      *
  -      * @param role the Role.
  -      * @param permission the Permission.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if role or permission is not present.
  -      */
  +     * Revokes a Permission from a Role.
  +     *
  +     * @param role the Role.
  +     * @param permission the Permission.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if role or permission is not present.
  +     */
       public synchronized void revoke(Role role, Permission permission)
           throws DataBackendException, UnknownEntityException
       {
  @@ -298,8 +328,9 @@
        * <strong>Not implemented</strong>
        *
        * @param groupName The name of the Group to be retrieved.
  +     * @return the group
        */
  -    public Group getNewGroup( String groupName )
  +    public Group getNewGroup(String groupName)
       {
           return (Group) new TurbineGroup(groupName);
       }
  @@ -311,6 +342,7 @@
        * <strong>Not implemented</strong>
        *
        * @param roleName The name of the Group to be retrieved.
  +     * @return the role
        */
       public Role getNewRole(String roleName)
       {
  @@ -318,14 +350,15 @@
       }
   
       /**
  -     * Retrieves a new Permission. It creates
  -     * a new Permission based on the Services Permission implementation. It does not
  -     * create a new Permission in the system though. Use create for that.
  +     * Retrieves a new Permission. It creates a new Permission based on the
  +     * Services Permission implementation. It does not create a new Permission
  +     * in the system though. Use create for that.
        * <strong>Not implemented</strong>
        *
        * @param permissionName The name of the Permission to be retrieved.
  +     * @return the permission
        */
  -    public Permission getNewPermission( String permissionName )
  +    public Permission getNewPermission(String permissionName)
       {
           return (Permission) new TurbinePermission(permissionName);
       }
  @@ -335,17 +368,20 @@
        *
        * @param criteria Criteria of Group selection.
        * @return a set of Groups that meet the specified Criteria.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
        */
       public GroupSet getGroups(Criteria criteria)
           throws DataBackendException
       {
           Hashtable groups = new Hashtable();
  +
           try
           {
               DirContext ctx = LDAPUserManager.bindAsAdmin();
   
               String baseSearch = LDAPSecurityConstants.getBaseSearch();
  -            String filter     = "(objectclass=turbineUserGroup)";
  +            String filter = "(objectclass=turbineUserGroup)";
   
               /*
                * Create the default search controls.
  @@ -355,42 +391,48 @@
               ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
   
               NamingEnumeration answer = ctx.search(baseSearch, filter, ctls);
  +
               while (answer.hasMore())
               {
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   Attribute attr = attribs.get("turbineGroup");
  +
                   if (attr != null && attr.get() != null)
                   {
                       Group group = getNewGroup(attr.get().toString());
  +
                       groups.put(group.getName(), group);
                   }
               }
           }
           catch (NamingException ex)
           {
  -            log.error("NamingException caught",ex);
  +            log.error("NamingException caught", ex);
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
           return new GroupSet(groups.values());
       }
   
       /**
  -      * Retrieve a set of Roles that meet the specified Criteria.
  -      *
  -      * @param criteria Criteria of Roles selection.
  -      * @return a set of Roles that meet the specified Criteria.
  -      */
  +     * Retrieve a set of Roles that meet the specified Criteria.
  +     *
  +     * @param criteria Criteria of Roles selection.
  +     * @return a set of Roles that meet the specified Criteria.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     */
       public RoleSet getRoles(Criteria criteria) throws DataBackendException
       {
           Vector roles = new Vector(0);
  +
           try
           {
               DirContext ctx = LDAPUserManager.bindAsAdmin();
   
               String baseSearch = LDAPSecurityConstants.getBaseSearch();
  -            String filter     = "(objectclass=turbineRole)";
  +            String filter = "(objectclass=turbineRole)";
   
               /*
                * Create the default search controls.
  @@ -404,9 +446,11 @@
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   Attribute attr = attribs.get("turbineRoleName");
  +
                   if (attr != null && attr.get() != null)
                   {
                       Role role = getNewRole(attr.get().toString());
  +
                       roles.add(role);
                   }
                   else
  @@ -417,30 +461,33 @@
           }
           catch (NamingException ex)
           {
  -            log.error("NamingException caught",ex);
  +            log.error("NamingException caught", ex);
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
   
           return new RoleSet(roles);
       }
   
       /**
  -      * Retrieve a set of Permissions that meet the specified Criteria.
  -      *
  -      * @param criteria Criteria of Permissions selection.
  -      * @return a set of Permissions that meet the specified Criteria.
  -      */
  +     * Retrieve a set of Permissions that meet the specified Criteria.
  +     *
  +     * @param criteria Criteria of Permissions selection.
  +     * @return a set of Permissions that meet the specified Criteria.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     */
       public PermissionSet getPermissions(Criteria criteria)
  -            throws DataBackendException
  +        throws DataBackendException
       {
           Hashtable permissions = new Hashtable();
  +
           try
           {
               DirContext ctx = LDAPUserManager.bindAsAdmin();
   
               String baseSearch = LDAPSecurityConstants.getBaseSearch();
  -            String filter     = "(objectClass=turbineRole)";
  +            String filter = "(objectClass=turbineRole)";
   
               /*
                * Create the default search controls.
  @@ -454,12 +501,16 @@
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   Attribute attr = attribs.get("turbinePermission");
  +
                   if (attr != null)
                   {
                       NamingEnumeration values = attr.getAll();
  -                    while(values.hasMore())
  +
  +                    while (values.hasMore())
                       {
  -                        Permission perm = getNewPermission(values.next().toString());
  +                        Permission perm = getNewPermission(
  +                                values.next().toString());
  +
                           permissions.put(perm.getName(), perm);
                       }
                   }
  @@ -467,32 +518,36 @@
           }
           catch (NamingException ex)
           {
  -            log.error("NamingException caught",ex);
  +            log.error("NamingException caught", ex);
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
           return new PermissionSet(permissions.values());
       }
   
       /**
  -      * Retrieves all permissions associated with a role.
  -      *
  -      * @param role the role name, for which the permissions are to be retrieved.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the role is not present.
  -      */
  +     * Retrieves all permissions associated with a role.
  +     *
  +     * @param role the role name, for which the permissions are to be retrieved.
  +     * @return the permissions
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the role is not present.
  +     */
       public PermissionSet getPermissions(Role role)
  -            throws DataBackendException, UnknownEntityException
  +        throws DataBackendException, UnknownEntityException
       {
           Hashtable permissions = new Hashtable();
  +
           try
           {
               DirContext ctx = LDAPUserManager.bindAsAdmin();
   
               String baseSearch = LDAPSecurityConstants.getBaseSearch();
               String filter = "(& ";
  +
               filter += "(objectClass=turbineRole)";
  -            filter += "(turbineRoleName="+ role.getName() +")";
  +            filter += "(turbineRoleName=" + role.getName() + ")";
               filter += ")";
   
               /*
  @@ -507,12 +562,16 @@
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   Attribute attr = attribs.get("turbinePermission");
  +
                   if (attr != null)
                   {
                       NamingEnumeration values = attr.getAll();
  -                    while(values.hasMore())
  +
  +                    while (values.hasMore())
                       {
  -                        Permission perm = getNewPermission(values.next().toString());
  +                        Permission perm = getNewPermission(
  +                                values.next().toString());
  +
                           permissions.put(perm.getName(), perm);
                       }
                   }
  @@ -520,58 +579,63 @@
           }
           catch (NamingException ex)
           {
  -            log.error("NamingException caught",ex);
  +            log.error("NamingException caught", ex);
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
           return new PermissionSet(permissions.values());
       }
   
       /**
  -      * Stores Group's attributes. The Groups is required to exist in the system.
  -      *
  -      * @param group The Group to be stored.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the group does not exist.
  -      */
  +     * Stores Group's attributes. The Groups is required to exist in the system.
  +     *
  +     * @param group The Group to be stored.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the group does not exist.
  +     */
       public void saveGroup(Group group) throws DataBackendException,
  -    UnknownEntityException
  +            UnknownEntityException
       {
       }
   
       /**
  -      * Stores Role's attributes. The Roles is required to exist in the system.
  -      *
  -      * @param role The Role to be stored.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the role does not exist.
  -      */
  +     * Stores Role's attributes. The Roles is required to exist in the system.
  +     *
  +     * @param role The Role to be stored.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the role does not exist.
  +     */
       public void saveRole(Role role) throws DataBackendException,
  -    UnknownEntityException
  +            UnknownEntityException
       {
       }
   
       /**
  -      * Stores Permission's attributes. The Permissions is required to exist in the system.
  -      *
  -      * @param permission The Permission to be stored.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the permission does not exist.
  -      */
  +     * Stores Permission's attributes. The Permissions is required to exist in
  +     * the system.
  +     *
  +     * @param permission The Permission to be stored.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the permission does not exist.
  +     */
       public void savePermission(Permission permission)
  -            throws DataBackendException, UnknownEntityException
  +        throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Creates a new group with specified attributes.
  -      * <strong>Not implemented</strong>
  -      *
  -      * @param group the object describing the group to be created.
  -      * @return a new Group object that has id set up properly.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws EntityExistsException if the group already exists.
  -      */
  +     * Creates a new group with specified attributes.
  +     * <strong>Not implemented</strong>
  +     *
  +     * @param group the object describing the group to be created.
  +     * @return a new Group object that has id set up properly.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws EntityExistsException if the group already exists.
  +     */
       public synchronized Group addGroup(Group group)
           throws DataBackendException, EntityExistsException
       {
  @@ -580,29 +644,31 @@
       }
   
       /**
  -      * Creates a new role with specified attributes.
  -      *
  -      * @param role the object describing the role to be created.
  -      * @return a new Role object that has id set up properly.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws EntityExistsException if the role already exists.
  -      */
  +     * Creates a new role with specified attributes.
  +     *
  +     * @param role the object describing the role to be created.
  +     * @return a new Role object that has id set up properly.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws EntityExistsException if the role already exists.
  +     */
       public synchronized Role addRole(Role role)
           throws DataBackendException, EntityExistsException
       {
           return null;
  -        //return new Role();
  +        // return new Role();
       }
   
       /**
  -      * Creates a new permission with specified attributes.
  -      * <strong>Not implemented</strong>
  -      *
  -      * @param permission the object describing the permission to be created.
  -      * @return a new Permission object that has id set up properly.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws EntityExistsException if the permission already exists.
  -      */
  +     * Creates a new permission with specified attributes.
  +     * <strong>Not implemented</strong>
  +     *
  +     * @param permission the object describing the permission to be created.
  +     * @return a new Permission object that has id set up properly.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws EntityExistsException if the permission already exists.
  +     */
       public synchronized Permission addPermission(Permission permission)
           throws DataBackendException, EntityExistsException
       {
  @@ -611,92 +677,110 @@
       }
   
       /**
  -      * Removes a Group from the system.
  -      *
  -      * @param group object describing group to be removed.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the group does not exist.
  -      */
  +     * Removes a Group from the system.
  +     *
  +     * @param group object describing group to be removed.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the group does not exist.
  +     */
       public synchronized void removeGroup(Group group)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Removes a Role from the system.
  -      *
  -      * @param role object describing role to be removed.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the role does not exist.
  -      */
  +     * Removes a Role from the system.
  +     *
  +     * @param role object describing role to be removed.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the role does not exist.
  +     */
       public synchronized void removeRole(Role role)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Removes a Permission from the system.
  -      *
  -      * @param permission object describing permission to be removed.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the permission does not exist.
  -      */
  +     * Removes a Permission from the system.
  +     *
  +     * @param permission object describing permission to be removed.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the permission does not exist.
  +     */
       public synchronized void removePermission(Permission permission)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Renames an existing Group.
  -      *
  -      * @param group object describing the group to be renamed.
  -      * @param name the new name for the group.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the group does not exist.
  -      */
  +     * Renames an existing Group.
  +     *
  +     * @param group object describing the group to be renamed.
  +     * @param name the new name for the group.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the group does not exist.
  +     */
       public synchronized void renameGroup(Group group, String name)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Renames an existing Role.
  -      *
  -      * @param role object describing the role to be renamed.
  -      * @param name the new name for the role.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the role does not exist.
  -      */
  +     * Renames an existing Role.
  +     *
  +     * @param role object describing the role to be renamed.
  +     * @param name the new name for the role.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the role does not exist.
  +     */
       public synchronized void renameRole(Role role, String name)
           throws DataBackendException, UnknownEntityException
       {
       }
   
       /**
  -      * Renames an existing Permission.
  -      *
  -      * @param permission object describing the permission to be renamed.
  -      * @param name the new name for the permission.
  -      * @throws DataBackendException if there was an error accessing the data backend.
  -      * @throws UnknownEntityException if the permission does not exist.
  -      */
  +     * Renames an existing Permission.
  +     *
  +     * @param permission object describing the permission to be renamed.
  +     * @param name the new name for the permission.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     * @throws UnknownEntityException if the permission does not exist.
  +     */
       public synchronized void renamePermission(Permission permission,
  -            String name)
  +        String name)
           throws DataBackendException, UnknownEntityException
       {
       }
   
  -    //just to satisify the interface requirements
  +    /**
  +     * just to satisify the interface requirements
  +     *
  +     * @param user the user
  +     */
       public void revokeAll(User user)
       {
       }
   
  -    //just to satisify the interface requirements
  +    /**
  +     * just to satisify the interface requirements
  +     *
  +     * @param role the role
  +     */
       public void revokeAll(Role role)
       {
       }
   
  -    //just to satisify the interface requirements
  +    /**
  +     * just to satisify the interface requirements
  +     *
  +     * @param group the group
  +     */
       public void revokeAll(Group group)
       {
       }
  
  
  
  1.6       +391 -277  jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPUser.java
  
  Index: LDAPUser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPUser.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LDAPUser.java	4 Jan 2003 03:56:34 -0000	1.5
  +++ LDAPUser.java	13 Jan 2003 20:09:45 -0000	1.6
  @@ -61,6 +61,8 @@
   import javax.servlet.http.HttpSessionBindingEvent;
   import javax.naming.directory.Attributes;
   import javax.naming.directory.Attribute;
  +import javax.naming.directory.BasicAttributes;
  +import javax.naming.directory.BasicAttribute;
   import javax.naming.NamingException;
   import org.apache.torque.om.BaseObject;
   import org.apache.turbine.om.security.User;
  @@ -69,6 +71,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.torque.om.StringKey;
   
  +
   /**
    * LDAPUser implements User and provides access to a user who accesses the
    * system via LDAP.
  @@ -81,12 +84,19 @@
    */
   public class LDAPUser extends BaseObject implements User
   {
  +
       /** Logging */
       private static Log log = LogFactory.getLog(LDAPUser.class);
   
       /* A few attributes common to a User. */
  +
  +    /** Date when the user was created */
       private java.util.Date createDate = null;
  +
  +    /** Date when the user was last accessed */
       private java.util.Date lastAccessDate = null;
  +
  +    /** timeout */
       private int timeout = 15;
   
       /** This is data that will survive a servlet engine restart. */
  @@ -107,14 +117,13 @@
           setHasLoggedIn(new Boolean(false));
       }
   
  -
       /**
        * Populates the user with values obtained from the LDAP Service.
        * This method could be redefined in subclasses.
        * @param attribs The attributes obtained from LDAP.
        * @throws NamingException if there was an error with JNDI.
        */
  -    public void setAttributes(Attributes attribs)
  +    public void setLDAPAttributes(Attributes attribs)
           throws NamingException
       {
   
  @@ -132,9 +141,9 @@
                   {
                       setPrimaryKey(new StringKey(attr.get().toString()));
                   }
  -                catch(Exception ex)
  +                catch (Exception ex)
                   {
  -                    log.error("Exception caught:",ex);
  +                    log.error("Exception caught:", ex);
                   }
               }
           }
  @@ -178,47 +187,142 @@
   
           // Set the E-Mail
           attrName = LDAPSecurityConstants.getEmailAttribute();
  -        log.debug("emailattr = "+attrName);
           if (attrName != null)
           {
               attr = attribs.get(attrName);
               if (attr != null && attr.get() != null)
               {
  -                log.debug("attr.get() = "+attr.get().toString());
                   setEmail(attr.get().toString());
  -                log.debug("getEmail = "+getEmail());
               }
           }
       }
   
       /**
  +     * Get the JNDI Attributes used to store the user in LDAP.
  +     * This method could be redefined in a subclass.
  +     *
  +     * @throws NamingException if there is a JNDI error.
  +     * @return The JNDI attributes of the user.
  +     */
  +    public Attributes getLDAPAttributes()
  +        throws NamingException
  +    {
  +        Attributes attribs = new BasicAttributes();
  +        String attrName;
  +
  +        // Set the objectClass
  +        attrName = "objectClass";
  +        if (attrName != null)
  +        {
  +            Object value = "turbineUser";
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        // Set the User id.
  +        attrName = LDAPSecurityConstants.getUserIdAttribute();
  +        if (attrName != null)
  +        {
  +            Object value = getPrimaryKey();
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        // Set the Username.
  +        attrName = LDAPSecurityConstants.getUserNameAttribute();
  +        if (attrName != null)
  +        {
  +            Object value = getUserName();
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        // Set the Firstname.
  +        attrName = LDAPSecurityConstants.getFirstNameAttribute();
  +        if (attrName != null)
  +        {
  +            Object value = getFirstName();
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        // Set the Lastname.
  +        attrName = LDAPSecurityConstants.getLastNameAttribute();
  +        if (attrName != null)
  +        {
  +            Object value = getLastName();
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        // Set the E-Mail.
  +        attrName = LDAPSecurityConstants.getEmailAttribute();
  +        if (attrName != null)
  +        {
  +            Object value = getEmail();
  +
  +            if (value != null)
  +            {
  +                Attribute attr = new BasicAttribute(attrName, value);
  +
  +                attribs.put(attr);
  +            }
  +        }
  +
  +        return attribs;
  +    }
  +
  +    /**
        * Gets the distinguished name (DN) of the User.
        * This method could be redefined in a subclass.
        * @return The Distinguished Name of the user.
        */
  -     public String getDN()
  -     {
  +    public String getDN()
  +    {
           String filterAttribute = LDAPSecurityConstants.getUserNameAttribute();
  -        String userBaseSearch  = LDAPSecurityConstants.getBaseSearch();
  +        String userBaseSearch = LDAPSecurityConstants.getBaseSearch();
           String userName = getUserName();
  -        log.debug("userName ="+userName);
   
           String dn = filterAttribute + "=" + userName + "," + userBaseSearch;
  -        log.debug("dn ="+dn);
  +
           return dn;
  -     }
  +    }
   
       /**
  -      * Gets the access counter for a user during a session.
  -      *
  -      * @return The access counter for the user for the session.
  -      */
  +     * Gets the access counter for a user during a session.
  +     *
  +     * @return The access counter for the user for the session.
  +     */
       public int getAccessCounterForSession()
       {
           try
           {
  -            return ( (Integer) getTemp(User.SESSION_ACCESS_COUNTER)).
  -                    intValue();
  +            return ((Integer) getTemp(User.SESSION_ACCESS_COUNTER)).intValue();
           }
           catch (Exception e)
           {
  @@ -227,10 +331,10 @@
       }
   
       /**
  -      * Gets the access counter for a user from perm storage.
  -      *
  -      * @return The access counter for the user.
  -      */
  +     * Gets the access counter for a user from perm storage.
  +     *
  +     * @return The access counter for the user.
  +     */
       public int getAccessCounter()
       {
           try
  @@ -244,116 +348,113 @@
       }
   
       /**
  -      * Gets the create date for this User.  This is the time at which
  -      * the user object was created.
  -      *
  -      * @return A Java Date with the date of creation for the user.
  -      */
  +     * Gets the create date for this User.  This is the time at which
  +     * the user object was created.
  +     *
  +     * @return A Java Date with the date of creation for the user.
  +     */
       public java.util.Date getCreateDate()
       {
           return createDate;
       }
  +
       /**
  -      * Returns the value of Confirmed variable
  -      *
  -      */
  +     * Returns the value of Confirmed variable
  +     * @return the confirm value.
  +     */
       public String getConfirmed()
       {
           String tmp = null;
  -        try
  -        {
  -            tmp = (String) getPerm (User.CONFIRM_VALUE);
  -            if (tmp.length() == 0)
  -                tmp = null;
  -        }
  -        catch (Exception e)
  +
  +        tmp = (String) getPerm(User.CONFIRM_VALUE);
  +        if (tmp.length() == 0)
           {
  +            tmp = null;
           }
           return tmp;
       }
   
       /**
  -      * Returns the Email for this user.  If this is defined, then
  -      * the user is considered logged in.
  -      *
  -      * @return A String with the user's Email.
  -      */
  +     * Returns the Email for this user.  If this is defined, then
  +     * the user is considered logged in.
  +     *
  +     * @return A String with the user's Email.
  +     */
       public String getEmail()
       {
  -        log.debug("start getEmail()");
           String tmp = null;
  -        try
  -        {
  -            tmp = (String) getPerm (User.EMAIL);
  -            if (tmp.length() == 0)
  -                tmp = null;
  -        }
  -        catch (Exception e)
  +
  +        tmp = (String) getPerm(User.EMAIL);
  +        if (tmp.length() == 0)
           {
  +            tmp = null;
           }
  -        log.debug("email = "+tmp);
           return tmp;
       }
   
  -
       /**
  -      * Gets the last access date for this User.  This is the last time
  -      * that the user object was referenced.
  -      *
  -      * @return A Java Date with the last access date for the user.
  -      */
  +     * Gets the last access date for this User.  This is the last time
  +     * that the user object was referenced.
  +     *
  +     * @return A Java Date with the last access date for the user.
  +     */
       public java.util.Date getLastAccessDate()
       {
           if (lastAccessDate == null)
  +        {
               setLastAccessDate();
  +        }
           return lastAccessDate;
       }
   
       /**
  -      * Get last login date/time for this user.
  -      *
  -      * @return A Java Date with the last login date for the user.
  -      */
  +     * Get last login date/time for this user.
  +     *
  +     * @return A Java Date with the last login date for the user.
  +     */
       public java.util.Date getLastLogin()
       {
           return (java.util.Date) getPerm(User.LAST_LOGIN);
       }
   
       /**
  -      * Get password for this user.
  -      *
  -      * @return A String with the password for the user.
  -      */
  +     * Get password for this user.
  +     *
  +     * @return A String with the password for the user.
  +     */
       public String getPassword()
       {
           return (String) getPerm(User.PASSWORD);
       }
   
       /**
  -      * Get an object from permanent storage.
  -      * @param name The object's name.
  -      * @return An Object with the given name.
  -      */
  -    public Object getPerm (String name)
  -    {
  -        return permStorage.get (name);
  +     * Get an object from permanent storage.
  +     * @param name The object's name.
  +     * @return An Object with the given name.
  +     */
  +    public Object getPerm(String name)
  +    {
  +        return permStorage.get(name);
       }
   
       /**
  -      * Get an object from permanent storage; return default if value
  -      * is null.
  -      *
  -      * @param name The object's name.
  -      * @param def A default value to return.
  -      * @return An Object with the given name.
  -      */
  -    public Object getPerm (String name, Object def)
  +     * Get an object from permanent storage; return default if value
  +     * is null.
  +     *
  +     * @param name The object's name.
  +     * @param def A default value to return.
  +     * @return An Object with the given name.
  +     */
  +    public Object getPerm(String name, Object def)
       {
           try
           {
  -            Object val = permStorage.get (name);
  +            Object val = permStorage.get(name);
  +
               if (val == null)
  +            {
                   return def;
  +            }
               return val;
           }
           catch (Exception e)
  @@ -363,11 +464,11 @@
       }
   
       /**
  -      * This should only be used in the case where we want to save the
  -      * data to the database.
  -      *
  -      * @return A Hashtable.
  -      */
  +     * This should only be used in the case where we want to save the
  +     * data to the database.
  +     *
  +     * @return A Hashtable.
  +     */
       public Hashtable getPermStorage()
       {
           if (this.permStorage == null)
  @@ -378,30 +479,31 @@
       }
   
       /**
  -      * Get an object from temporary storage.
  -      *
  -      * @param name The object's name.
  -      * @return An Object with the given name.
  -      */
  -    public Object getTemp (String name)
  -    {
  -        return tempStorage.get (name);
  +     * Get an object from temporary storage.
  +     *
  +     * @param name The object's name.
  +     * @return An Object with the given name.
  +     */
  +    public Object getTemp(String name)
  +    {
  +        return tempStorage.get(name);
       }
   
       /**
  -      * Get an object from temporary storage; return default if value
  -      * is null.
  -      *
  -      * @param name The object's name.
  -      * @param def A default value to return.
  -      * @return An Object with the given name.
  -      */
  -    public Object getTemp (String name, Object def)
  +     * Get an object from temporary storage; return default if value
  +     * is null.
  +     *
  +     * @param name The object's name.
  +     * @param def A default value to return.
  +     * @return An Object with the given name.
  +     */
  +    public Object getTemp(String name, Object def)
       {
           Object val;
  +
           try
           {
  -            val = tempStorage.get (name);
  +            val = tempStorage.get(name);
               if (val == null)
               {
                   val = def;
  @@ -415,362 +517,363 @@
       }
   
       /**
  -      * A User object can have a variable Timeout, which is defined in
  -      * minutes.  If the user has been timed out, then the
  -      * hasLoggedIn() value will return false.
  -      *
  -      * @return An int specifying the timeout.
  -      */
  +     * A User object can have a variable Timeout, which is defined in
  +     * minutes.  If the user has been timed out, then the
  +     * hasLoggedIn() value will return false.
  +     *
  +     * @return An int specifying the timeout.
  +     */
       public int getTimeout()
       {
           return this.timeout;
       }
   
       /**
  -      * Returns the username for this user.  If this is defined, then
  -      * the user is considered logged in.
  -      *
  -      * @return A String with the username.
  -      */
  +     * Returns the username for this user.  If this is defined, then
  +     * the user is considered logged in.
  +     *
  +     * @return A String with the username.
  +     */
       public String getUserName()
       {
           String tmp = null;
  -        try
  +
  +        tmp = (String) getPerm(User.USERNAME);
  +        if (tmp.length() == 0)
           {
  -            tmp = (String) getPerm (User.USERNAME);
  -            if (tmp.length() == 0)
                   tmp = null;
           }
  -        catch (Exception e)
  -        {
  -        }
           return tmp;
       }
   
       /**
  -      * Returns the first name for this user.  If this is defined, then
  -      * the user is considered logged in.
  -      *
  -      * @return A String with the user's first name.
  -      */
  +     * Returns the first name for this user.  If this is defined, then
  +     * the user is considered logged in.
  +     *
  +     * @return A String with the user's first name.
  +     */
       public String getFirstName()
       {
           String tmp = null;
  -        try
  -        {
  -            tmp = (String) getPerm (User.FIRST_NAME);
  -            if (tmp.length() == 0)
  -                tmp = null;
  -        }
  -        catch (Exception e)
  +
  +        tmp = (String) getPerm(User.FIRST_NAME);
  +        if (tmp.length() == 0)
           {
  +            tmp = null;
           }
           return tmp;
       }
   
       /**
  -      * Returns the last name for this user.  If this is defined, then
  -      * the user is considered logged in.
  -      *
  -      * @return A String with the user's last name.
  -      */
  +     * Returns the last name for this user.  If this is defined, then
  +     * the user is considered logged in.
  +     *
  +     * @return A String with the user's last name.
  +     */
       public String getLastName()
       {
           String tmp = null;
  -        try
  -        {
  -            tmp = (String) getPerm (User.LAST_NAME);
  -            if (tmp.length() == 0)
  -                tmp = null;
  -        }
  -        catch (Exception e)
  +
  +        tmp = (String) getPerm(User.LAST_NAME);
  +        if (tmp.length() == 0)
           {
  +            tmp = null;
           }
           return tmp;
       }
   
       /**
  -      * The user is considered logged in if they have not timed out.
  -      *
  -      * @return True if the user has logged in.
  -      */
  +     * The user is considered logged in if they have not timed out.
  +     *
  +     * @return True if the user has logged in.
  +     */
       public boolean hasLoggedIn()
       {
           Boolean tmp = getHasLoggedIn();
  +
           if (tmp != null && tmp.booleanValue())
  +        {
               return true;
  +        }
           else
  +        {
               return false;
  +        }
       }
   
       /**
  -      * This method reports whether or not the user has been confirmed
  -      * in the system by checking the <code>CONFIRM_VALUE</code>
  -      * column to see if it is equal to <code>CONFIRM_DATA</code>.
  -      *
  -      * @return True if the user has been confirmed.
  -      */
  +     * This method reports whether or not the user has been confirmed
  +     * in the system by checking the <code>CONFIRM_VALUE</code>
  +     * column to see if it is equal to <code>CONFIRM_DATA</code>.
  +     *
  +     * @return True if the user has been confirmed.
  +     */
       public boolean isConfirmed()
       {
           return ((String) getTemp(CONFIRM_VALUE, "")).equals(CONFIRM_DATA);
       }
   
  -
       /**
  -      * Increments the permanent hit counter for the user.
  -      */
  +     * Increments the permanent hit counter for the user.
  +     */
       public void incrementAccessCounter()
       {
           setAccessCounter(getAccessCounter() + 1);
       }
   
       /**
  -      * Increments the session hit counter for the user.
  -      */
  +     * Increments the session hit counter for the user.
  +     */
       public void incrementAccessCounterForSession()
       {
           setAccessCounterForSession(getAccessCounterForSession() + 1);
       }
   
       /**
  -      * Remove an object from temporary storage and return the object.
  -      *
  -      * @param name The name of the object to remove.
  -      * @return An Object.
  -      */
  -    public Object removeTemp (String name)
  +     * Remove an object from temporary storage and return the object.
  +     *
  +     * @param name The name of the object to remove.
  +     * @return An Object.
  +     */
  +    public Object removeTemp(String name)
       {
  -        return tempStorage.remove (name);
  +        return tempStorage.remove(name);
       }
   
       /**
  -      * Sets the access counter for a user, saved in perm storage.
  -      *
  -      * @param cnt The new count.
  -      */
  +     * Sets the access counter for a user, saved in perm storage.
  +     *
  +     * @param cnt The new count.
  +     */
       public void setAccessCounter(int cnt)
       {
           setPerm(User.ACCESS_COUNTER, new Integer(cnt));
       }
   
       /**
  -      * Sets the session access counter for a user, saved in temp
  -      * storage.
  -      *
  -      * @param cnt The new count.
  -      */
  +     * Sets the session access counter for a user, saved in temp
  +     * storage.
  +     *
  +     * @param cnt The new count.
  +     */
       public void setAccessCounterForSession(int cnt)
       {
           setTemp(User.SESSION_ACCESS_COUNTER, new Integer(cnt));
       }
  +
       /**
        * Set the users confirmed variable
  -      *
  +     *
  +     * @param confirm The new confim value.
        */
       public void setConfirmed(String confirm)
       {
  -        getPerm (User.CONFIRM_VALUE, confirm);
  +        getPerm(User.CONFIRM_VALUE, confirm);
       }
   
  -
       /**
  -      * Sets the last access date for this User. This is the last time
  -      * that the user object was referenced.
  -      */
  +     * Sets the last access date for this User. This is the last time
  +     * that the user object was referenced.
  +     */
       public void setLastAccessDate()
       {
           lastAccessDate = new java.util.Date();
       }
   
       /**
  -      * Sets the create date for this User. This is the time at which
  -      * the user object was created.
  -      *
  -      * @param date The create date.
  -      */
  +     * Sets the create date for this User. This is the time at which
  +     * the user object was created.
  +     *
  +     * @param date The create date.
  +     */
       public void setCreateDate(java.util.Date date)
       {
           createDate = date;
       }
  +
       /**
        * Set the users Email
        *
  +     * @param email The new email.
        */
       public void setEmail(String email)
       {
  -        log.debug("setEmail("+email+")");
  +        log.debug("setEmail(" + email + ")");
           setPerm(User.EMAIL, email);
       }
   
       /**
  -      * Set the users First Name
  -      *
  -      */
  +     * Set the users First Name
  +     *
  +     * @param fname The new firstname.
  +     */
       public void setFirstName(String fname)
       {
           setPerm(User.FIRST_NAME, fname);
       }
   
       /**
  -      * Set last login date/time.
  -      *
  -      * @param date The last login date.
  -      */
  +     * Set last login date/time.
  +     *
  +     * @param date The last login date.
  +     */
       public void setLastLogin(java.util.Date date)
       {
           setPerm(User.LAST_LOGIN, date);
       }
   
       /**
  -      * Set the users Last Name
  -      * Sets the last name for this user.
  -      *
  -      *
  -      */
  +     * Set the users Last Name
  +     * Sets the last name for this user.
  +     *
  +     * @param lname The new lastname.
  +     */
       public void setLastName(String lname)
       {
           setPerm(User.LAST_NAME, lname);
       }
   
       /**
  -      * Set password.
  -      *
  -      * @param password The new password.
  -      */
  +     * Set password.
  +     *
  +     * @param password The new password.
  +     */
       public void setPassword(String password)
       {
           setPerm(User.PASSWORD, password);
       }
   
       /**
  -      * Put an object into permanent storage.
  -      *
  -      * @param name The object's name.
  -      * @param value The object.
  -      */
  -    public void setPerm (String name, Object value)
  +     * Put an object into permanent storage.
  +     *
  +     * @param name The object's name.
  +     * @param value The object.
  +     */
  +    public void setPerm(String name, Object value)
       {
           permStorage.put(name, value);
       }
   
       /**
  -      * This should only be used in the case where we want to save the
  -      * data to the database.
  -      *
  -      * @param stuff A Hashtable.
  -      */
  +     * This should only be used in the case where we want to save the
  +     * data to the database.
  +     *
  +     * @param stuff A Hashtable.
  +     */
       public void setPermStorage(Hashtable stuff)
       {
           this.permStorage = stuff;
       }
   
       /**
  -      * This should only be used in the case where we want to save the
  -      * data to the database.
  -      *
  -      * @return A Hashtable.
  -      */
  +     * This should only be used in the case where we want to save the
  +     * data to the database.
  +     *
  +     * @return A Hashtable.
  +     */
       public Hashtable getTempStorage()
       {
           if (this.tempStorage == null)
  +        {
               this.tempStorage = new Hashtable();
  +        }
           return this.tempStorage;
       }
   
       /**
  -      * This should only be used in the case where we want to save the
  -      * data to the database.
  -      *
  -      * @param storage A Hashtable.
  -      */
  +     * This should only be used in the case where we want to save the
  +     * data to the database.
  +     *
  +     * @param storage A Hashtable.
  +     */
       public void setTempStorage(Hashtable storage)
       {
           this.tempStorage = storage;
       }
   
       /**
  -      * This gets whether or not someone has logged in.  hasLoggedIn()
  -      * returns this value as a boolean.  This is private because you
  -      * should use hasLoggedIn() instead.
  -      *
  -      * @return True if someone has logged in.
  -      */
  +     * This gets whether or not someone has logged in.  hasLoggedIn()
  +     * returns this value as a boolean.  This is private because you
  +     * should use hasLoggedIn() instead.
  +     *
  +     * @return True if someone has logged in.
  +     */
       private Boolean getHasLoggedIn()
       {
  -        return (Boolean) getTemp (User.HAS_LOGGED_IN);
  +        return (Boolean) getTemp(User.HAS_LOGGED_IN);
       }
   
       /**
  -      * This sets whether or not someone has logged in.  hasLoggedIn()
  -      * returns this value.
  -      *
  -      * @param value Whether someone has logged in or not.
  -      */
  -    public void setHasLoggedIn (Boolean value)
  +     * This sets whether or not someone has logged in.  hasLoggedIn()
  +     * returns this value.
  +     *
  +     * @param value Whether someone has logged in or not.
  +     */
  +    public void setHasLoggedIn(Boolean value)
       {
  -        setTemp (User.HAS_LOGGED_IN, value);
  +        setTemp(User.HAS_LOGGED_IN, value);
       }
   
       /**
  -      * Put an object into temporary storage.
  -      *
  -      * @param name The object's name.
  -      * @param value The object.
  -      */
  -    public void setTemp (String name, Object value)
  +     * Put an object into temporary storage.
  +     *
  +     * @param name The object's name.
  +     * @param value The object.
  +     */
  +    public void setTemp(String name, Object value)
       {
  -        tempStorage.put (name, value);
  +        tempStorage.put(name, value);
       }
   
       /**
  -      * A User object can have a variable Timeout which is defined in
  -      * minutes.  If the user has been timed out, then the
  -      * hasLoggedIn() value will return false.
  -      *
  -      * @param time The user's timeout.
  -      */
  +     * A User object can have a variable Timeout which is defined in
  +     * minutes.  If the user has been timed out, then the
  +     * hasLoggedIn() value will return false.
  +     *
  +     * @param time The user's timeout.
  +     */
       public void setTimeout(int time)
       {
           this.timeout = time;
       }
   
       /**
  -      * Sets the username for this user.
  -      *
  -      * @param username The user's username.
  -      */
  +     * Sets the username for this user.
  +     *
  +     * @param username The user's username.
  +     */
       public void setUserName(String username)
       {
  -        setPerm (User.USERNAME, username);
  +        setPerm(User.USERNAME, username);
       }
   
       /**
  -      * Updates the last login date in the database.
  -      *
  -      * @exception Exception a generic exception.
  -      */
  +     * Updates the last login date in the database.
  +     *
  +     * @exception Exception a generic exception.
  +     */
       public void updateLastLogin() throws Exception
       {
           setPerm(User.LAST_LOGIN, new java.util.Date());
       }
   
       /**
  -      * Implement this method if you wish to be notified when the User
  -      * has been Bound to the session.
  -      *
  -      * @param hsbe The HttpSessionBindingEvent.
  -      */
  +     * Implement this method if you wish to be notified when the User
  +     * has been Bound to the session.
  +     *
  +     * @param hsbe The HttpSessionBindingEvent.
  +     */
       public void valueBound(HttpSessionBindingEvent hsbe)
       {
           // Do not currently need this method.
       }
   
       /**
  -      * Implement this method if you wish to be notified when the User
  -      * has been Unbound from the session.
  -      *
  -      * @param hsbe The HttpSessionBindingEvent.
  -      */
  +     * Implement this method if you wish to be notified when the User
  +     * has been Unbound from the session.
  +     *
  +     * @param hsbe The HttpSessionBindingEvent.
  +     */
       public void valueUnbound(HttpSessionBindingEvent hsbe)
       {
           try
  @@ -782,31 +885,42 @@
           }
           catch (Exception e)
           {
  -            log.error("BaseUser.valueUnbobund(): "+
  -                    e.getMessage());
  +            log.error("BaseUser.valueUnbobund(): "
  +                + e.getMessage());
               log.error(e);
   
               // To prevent messages being lost in case the logging system
               // goes away before sessions get unbound on servlet container
               // shutdown, print the stcktrace to the container's console.
               ByteArrayOutputStream ostr = new ByteArrayOutputStream();
  +
               e.printStackTrace(new PrintWriter(ostr, true));
               String stackTrace = ostr.toString();
  +
               System.out.println(stackTrace);
           }
       }
   
  +    /**
  +     * Not implemented.
  +     * @return null
  +     */
       public String getName()
       {
           return null;
       }
   
  +    /**
  +     * Not implemented.
  +     * @param name the name of the User.
  +     */
       public void setName(String name)
       {
       }
   
       /**
        * Saves this object to the data store.
  +     * @throws Exception if it cannot be saved
        */
       public void save()
           throws Exception
  @@ -824,8 +938,8 @@
       /**
        * not implemented
        *
  -     * @param conn
  -     * @throws Exception
  +     * @param conn the database connection
  +     * @throws Exception if there is an error
        */
       public void save(Connection conn) throws Exception
       {
  @@ -835,8 +949,8 @@
       /**
        * not implemented
        *
  -     * @param dbname
  -     * @throws Exception
  +     * @param dbname the database name
  +     * @throws Exception if there is an error
        */
       public void save(String dbname) throws Exception
       {
  
  
  
  1.6       +225 -162  jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPUserManager.java
  
  Index: LDAPUserManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/LDAPUserManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LDAPUserManager.java	4 Jan 2003 03:56:34 -0000	1.5
  +++ LDAPUserManager.java	13 Jan 2003 20:09:45 -0000	1.6
  @@ -72,6 +72,7 @@
   import org.apache.turbine.util.security.PasswordMismatchException;
   import org.apache.turbine.util.security.UnknownEntityException;
   
  +
   /**
    * A UserManager performs {@link org.apache.turbine.om.security.User}
    * object related tasks on behalf of the
  @@ -95,31 +96,32 @@
    */
   public class LDAPUserManager implements UserManager
   {
  +
       /**
  -      * Check wether a specified user's account exists.
  -      *
  -      * The login name is used for looking up the account.
  -      *
  -      * @param user The user to be checked.
  -      * @return true if the specified account exists
  -      * @throws DataBackendException Error accessing the data backend.
  -      */
  +     * Check wether a specified user's account exists.
  +     *
  +     * The login name is used for looking up the account.
  +     *
  +     * @param user The user to be checked.
  +     * @return true if the specified account exists
  +     * @throws DataBackendException Error accessing the data backend.
  +     */
       public boolean accountExists(User user) throws DataBackendException
       {
           return accountExists(user.getUserName());
       }
   
       /**
  -      *
  -      * Check wether a specified user's account exists.
  -      * The login name is used for looking up the account.
  -      *
  -      * @param username The name of the user to be checked.
  -      * @return true if the specified account exists
  -      * @throws DataBackendException Error accessing the data backend.
  -      */
  +     *
  +     * Check wether a specified user's account exists.
  +     * The login name is used for looking up the account.
  +     *
  +     * @param username The name of the user to be checked.
  +     * @return true if the specified account exists
  +     * @throws DataBackendException Error accessing the data backend.
  +     */
       public boolean accountExists(String username)
  -            throws DataBackendException
  +        throws DataBackendException
       {
           try
           {
  @@ -134,17 +136,17 @@
       }
   
       /**
  -      * Retrieve a user from persistent storage using username as the
  -      * key.
  -      *
  -      * @param username the name of the user.
  -      * @return an User object.
  -      * @exception UnknownEntityException if the user's account does not
  -      *            exist in the database.
  -      * @exception DataBackendException Error accessing the data backend.
  -      */
  +     * Retrieve a user from persistent storage using username as the
  +     * key.
  +     *
  +     * @param username the name of the user.
  +     * @return an User object.
  +     * @exception UnknownEntityException if the user's account does not
  +     *            exist in the database.
  +     * @exception DataBackendException Error accessing the data backend.
  +     */
       public User retrieve(String username)
  -            throws UnknownEntityException, DataBackendException
  +        throws UnknownEntityException, DataBackendException
       {
           try
           {
  @@ -154,8 +156,9 @@
                * Define the search.
                */
               String userBaseSearch = LDAPSecurityConstants.getBaseSearch();
  -            String filter         = LDAPSecurityConstants.getUserNameAttribute();
  -            filter = "("+filter + "="+username + ")";
  +            String filter = LDAPSecurityConstants.getUserNameAttribute();
  +
  +            filter = "(" + filter + "=" + username + ")";
   
               /*
                * Create the default search controls.
  @@ -163,59 +166,62 @@
               SearchControls ctls = new SearchControls();
   
               NamingEnumeration answer =
  -                    ctx.search(userBaseSearch, filter, ctls);
  +                ctx.search(userBaseSearch, filter, ctls);
   
               if (answer.hasMore())
               {
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   LDAPUser ldapUser = createLDAPUser();
  -                ldapUser.setAttributes(attribs);
  +
  +                ldapUser.setLDAPAttributes(attribs);
                   ldapUser.setTemp("turbine.user", ldapUser);
   
                   return ldapUser;
               }
               else
               {
  -                throw new UnknownEntityException("The given user: " +
  -                        username + "\n does not exist.");
  +                throw new UnknownEntityException("The given user: "
  +                    + username + "\n does not exist.");
               }
           }
           catch (NamingException ex)
           {
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
       }
   
       /**
  -      * This is currently not implemented to behave as expected.  It
  -      * ignores the Criteria argument and returns all the users.
  -      *
  -      * Retrieve a set of users that meet the specified criteria.
  -      *
  -      * As the keys for the criteria, you should use the constants that
  -      * are defined in {@link User} interface, plus the the names
  -      * of the custom attributes you added to your user representation
  -      * in the data storage. Use verbatim names of the attributes -
  -      * without table name prefix in case of DB implementation.
  -      *
  -      * @param criteria The criteria of selection.
  -      * @return a List of users meeting the criteria.
  -      * @throws DataBackendException Error accessing the data backend.
  -      */
  +     * This is currently not implemented to behave as expected.  It
  +     * ignores the Criteria argument and returns all the users.
  +     *
  +     * Retrieve a set of users that meet the specified criteria.
  +     *
  +     * As the keys for the criteria, you should use the constants that
  +     * are defined in {@link User} interface, plus the the names
  +     * of the custom attributes you added to your user representation
  +     * in the data storage. Use verbatim names of the attributes -
  +     * without table name prefix in case of DB implementation.
  +     *
  +     * @param criteria The criteria of selection.
  +     * @return a List of users meeting the criteria.
  +     * @throws DataBackendException Error accessing the data backend.
  +     */
       public User[] retrieve(Criteria criteria)
           throws DataBackendException
       {
   
           Vector users = new Vector(0);
  +
           try
           {
               DirContext ctx = bindAsAdmin();
   
               String userBaseSearch = LDAPSecurityConstants.getBaseSearch();
  -            String filter         = LDAPSecurityConstants.getUserNameAttribute();
  -            filter = "("+filter+"=*)";
  +            String filter = LDAPSecurityConstants.getUserNameAttribute();
  +
  +            filter = "(" + filter + "=*)";
   
               /*
                * Create the default search controls.
  @@ -230,7 +236,8 @@
                   SearchResult sr = (SearchResult) answer.next();
                   Attributes attribs = sr.getAttributes();
                   LDAPUser ldapUser = createLDAPUser();
  -                ldapUser.setAttributes(attribs);
  +
  +                ldapUser.setLDAPAttributes(attribs);
                   ldapUser.setTemp("turbine.user", ldapUser);
                   users.add(ldapUser);
               }
  @@ -238,76 +245,92 @@
           catch (NamingException ex)
           {
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
   
           return (User[]) users.toArray(new User[users.size()]);
       }
   
       /**
  -      * Retrieve a user from persistent storage using username as the
  -      * key, and authenticate the user. The implementation may chose
  -      * to authenticate to the server as the user whose data is being
  -      * retrieved.
  -      *
  -      * @param username the name of the user.
  -      * @param password the user supplied password.
  -      * @return an User object.
  -      * @exception PasswordMismatchException if the supplied password was
  -      *            incorrect.
  -      * @exception UnknownEntityException if the user's account does not
  -      *            exist in the database.
  -      * @exception DataBackendException Error accessing the data backend.
  -      */
  +     * Retrieve a user from persistent storage using username as the
  +     * key, and authenticate the user. The implementation may chose
  +     * to authenticate to the server as the user whose data is being
  +     * retrieved.
  +     *
  +     * @param username the name of the user.
  +     * @param password the user supplied password.
  +     * @return an User object.
  +     * @exception PasswordMismatchException if the supplied password was
  +     *            incorrect.
  +     * @exception UnknownEntityException if the user's account does not
  +     *            exist in the database.
  +     * @exception DataBackendException Error accessing the data backend.
  +     */
       public User retrieve(String username, String password)
           throws PasswordMismatchException,
  -            UnknownEntityException,DataBackendException
  +            UnknownEntityException, DataBackendException
       {
           User user = retrieve(username);
  +
           authenticate(user, password);
           return user;
       }
   
       /**
  -      * This method is not yet implemented
  -      *
  -      * Save a User object to persistent storage. User's account is
  -      * required to exist in the storage.
  -      *
  -      * @param user an User object to store.
  -      * @exception UnknownEntityException if the user's account does not
  -      *            exist in the database.
  -      *
  -      */
  +     * Save a User object to persistent storage. User's account is
  +     * required to exist in the storage.
  +     *
  +     * @param user an User object to store.
  +     * @throws UnknownEntityException if the user's account does not
  +     *            exist in the database.
  +     * @throws DataBackendException if there is an LDAP error
  +     *
  +     */
       public void store(User user)
  -        throws UnknownEntityException,DataBackendException
  +        throws UnknownEntityException, DataBackendException
       {
           if (!accountExists(user))
           {
  -            throw new UnknownEntityException("The account '"+
  -                    user.getUserName() + "' does not exist");
  +            throw new UnknownEntityException("The account '"
  +                + user.getUserName() + "' does not exist");
  +        }
  +
  +        try
  +        {
  +            LDAPUser ldapUser = (LDAPUser) user;
  +            Attributes attrs = ldapUser.getLDAPAttributes();
  +            String name = ldapUser.getDN();
  +
  +            DirContext ctx = bindAsAdmin();
  +
  +            ctx.modifyAttributes(name, DirContext.REPLACE_ATTRIBUTE, attrs);
  +        }
  +        catch (NamingException ex)
  +        {
  +            throw new DataBackendException("NamingException caught", ex);
           }
       }
   
       /**
  -      * Authenticate a User with the specified password. If authentication
  -      * is successful the method returns nothing. If there are any problems,
  -      * exception was thrown.
  -      *
  -      * @param user a User object to authenticate.
  -      * @param password the user supplied password.
  -      * @exception PasswordMismatchException if the supplied password was
  -      *            incorrect.
  -      * @exception UnknownEntityException if the user's account does not
  -      *            exist in the database.
  -      * @exception DataBackendException Error accessing the data backend.
  -      */
  +     * Authenticate a User with the specified password. If authentication
  +     * is successful the method returns nothing. If there are any problems,
  +     * exception was thrown.
  +     *
  +     * @param user a User object to authenticate.
  +     * @param password the user supplied password.
  +     * @exception PasswordMismatchException if the supplied password was
  +     *            incorrect.
  +     * @exception UnknownEntityException if the user's account does not
  +     *            exist in the database.
  +     * @exception DataBackendException Error accessing the data backend.
  +     */
       public void authenticate(User user, String password)
           throws PasswordMismatchException,
  -        UnknownEntityException,
  -        DataBackendException
  +            UnknownEntityException,
  +            DataBackendException
       {
  -        LDAPUser ldapUser = (LDAPUser)user;
  +        LDAPUser ldapUser = (LDAPUser) user;
  +
           try
           {
               bind(ldapUser.getDN(), password);
  @@ -315,100 +338,137 @@
           catch (AuthenticationException ex)
           {
               throw new PasswordMismatchException(
  -                "The given password for: " +
  -                    ldapUser.getDN() + " is invalid\n");
  +                    "The given password for: "
  +                    + ldapUser.getDN() + " is invalid\n");
           }
           catch (NamingException ex)
           {
               throw new DataBackendException(
  -                "The LDAP server specified is unavailable",ex);
  +                    "The LDAP server specified is unavailable", ex);
           }
       }
   
       /**
  -      * This method is not yet implemented
  -      * Change the password for an User.
  -      *
  -      * @param user an User to change password for.
  -      * @param newPassword the new password.
  -      * @param oldPassword the old password.
  -      * @exception PasswordMismatchException if the supplied password was
  -      *            incorrect.
  -      * @exception UnknownEntityException if the user's account does not
  -      *            exist in the database.
  -      * @exception DataBackendException Error accessing the data backend.
  -      */
  -    public void changePassword(User user, String oldPassword, String newPassword)
  +     * This method is not yet implemented
  +     * Change the password for an User.
  +     *
  +     * @param user an User to change password for.
  +     * @param newPass the new password.
  +     * @param oldPass the old password.
  +     * @exception PasswordMismatchException if the supplied password was
  +     *            incorrect.
  +     * @exception UnknownEntityException if the user's account does not
  +     *            exist in the database.
  +     * @exception DataBackendException Error accessing the data backend.
  +     */
  +    public void changePassword(User user, String oldPass, String newPass)
           throws PasswordMismatchException,
               UnknownEntityException, DataBackendException
       {
           throw new DataBackendException(
  -            "The method changePassword has no implementation.");
  +                "The method changePassword has no implementation.");
       }
   
       /**
  -      * This method is not yet implemented
  -      * Forcibly sets new password for an User.
  -      *
  -      * This is supposed to be used by the administrator to change the forgotten or
  -      * compromised passwords. Certain implementatations of this feature
  -      * would require adminstrative level access to the authenticating
  -      * server / program.
  -      *
  -      * @param user an User to change password for.
  -      * @param password the new password.
  -      * @exception UnknownEntityException if the user's record does not
  -      *            exist in the database.
  -      * @exception DataBackendException Error accessing the data backend.
  -      */
  +     * This method is not yet implemented
  +     * Forcibly sets new password for an User.
  +     *
  +     * This is supposed to be used by the administrator to change the forgotten
  +     * or compromised passwords. Certain implementatations of this feature
  +     * would require adminstrative level access to the authenticating
  +     * server / program.
  +     *
  +     * @param user an User to change password for.
  +     * @param password the new password.
  +     * @exception UnknownEntityException if the user's record does not
  +     *            exist in the database.
  +     * @exception DataBackendException Error accessing the data backend.
  +     */
       public void forcePassword(User user, String password)
  -        throws UnknownEntityException,DataBackendException
  +        throws UnknownEntityException, DataBackendException
       {
           throw new DataBackendException(
  -            "The method forcePassword has no implementation.");
  +                "The method forcePassword has no implementation.");
       }
   
       /**
  -      * This method is not yet implemented
  -      * Creates new user account with specified attributes.
  -      *
  -      * @param user the object describing account to be created.
  -      * @throws DataBackendException Error accessing the data backend.
  -      * @throws EntityExistsException if the user account already exists.
  -      */
  +     * Creates new user account with specified attributes.
  +     *
  +     * @param user the object describing account to be created.
  +     * @param initialPassword Not used yet.
  +     * @throws DataBackendException Error accessing the data backend.
  +     * @throws EntityExistsException if the user account already exists.
  +     */
       public void createAccount(User user, String initialPassword)
  -        throws EntityExistsException,DataBackendException
  +        throws EntityExistsException, DataBackendException
       {
  -        throw new DataBackendException(
  -            "The method createAccount has no implementation.");
  +        if (accountExists(user))
  +        {
  +            throw new EntityExistsException("The account '"
  +                + user.getUserName() + "' already exist");
  +        }
  +
  +        try
  +        {
  +            LDAPUser ldapUser = (LDAPUser) user;
  +            Attributes attrs = ldapUser.getLDAPAttributes();
  +            String name = ldapUser.getDN();
  +
  +            DirContext ctx = bindAsAdmin();
  +
  +            ctx.bind(name, null, attrs);
  +        }
  +        catch (NamingException ex)
  +        {
  +            throw new DataBackendException("NamingException caught", ex);
  +        }
       }
   
       /**
  -      * This method is not yet implemented
  -      * Removes an user account from the system.
  -      *
  -      * @param user the object describing the account to be removed.
  -      * @throws DataBackendException Error accessing the data backend.
  -      * @throws UnknownEntityException if the user account is not present.
  -      */
  +     * Removes an user account from the system.
  +     *
  +     * @param user the object describing the account to be removed.
  +     * @throws DataBackendException Error accessing the data backend.
  +     * @throws UnknownEntityException if the user account is not present.
  +     */
       public void removeAccount(User user)
  -        throws UnknownEntityException,DataBackendException
  +        throws UnknownEntityException, DataBackendException
       {
  -        throw new DataBackendException(
  -            "The method removeAccount has no implementation.");
  +        if (!accountExists(user))
  +        {
  +            throw new UnknownEntityException("The account '"
  +                + user.getUserName() + "' does not exist");
  +        }
  +
  +        try
  +        {
  +            LDAPUser ldapUser = (LDAPUser) user;
  +            String name = ldapUser.getDN();
  +
  +            DirContext ctx = bindAsAdmin();
  +
  +            ctx.unbind(name);
  +        }
  +        catch (NamingException ex)
  +        {
  +            throw new DataBackendException("NamingException caught", ex);
  +        }
       }
   
       /**
        * Bind as the admin user.
  +     *
        * @throws NamingException when an error occurs with the named server.
  +     * @return a new DirContext.
        */
  -     public static DirContext bindAsAdmin()
  +    public static DirContext bindAsAdmin()
           throws NamingException
  -     {
  -        String adminUser      = LDAPSecurityConstants.getAdminUsername();
  -        String adminPassword  = LDAPSecurityConstants.getAdminPassword();
  +    {
  +        String adminUser = LDAPSecurityConstants.getAdminUsername();
  +        String adminPassword = LDAPSecurityConstants.getAdminPassword();
  +
           return bind(adminUser, adminPassword);
  -     }
  +    }
   
       /**
        * Creates an initial context.
  @@ -416,13 +476,14 @@
        * @param username admin username supplied in TRP.
        * @param password admin password supplied in TRP
        * @throws NamingException when an error occurs with the named server.
  +     * @return a new DirContext.
        */
       public static DirContext bind(String username, String password)
           throws NamingException
       {
           String host = LDAPSecurityConstants.getLDAPHost();
           String port = LDAPSecurityConstants.getLDAPPort();
  -        String providerURL  = new String("ldap://" + host + ":" + port);
  +        String providerURL = new String("ldap://" + host + ":" + port);
   
           String ldapProvider = LDAPSecurityConstants.getLDAPProvider();
   
  @@ -431,6 +492,7 @@
            * LDAP Provider.
            */
           Hashtable env = new Hashtable();
  +
           env.put(Context.INITIAL_CONTEXT_FACTORY, ldapProvider);
           env.put(Context.PROVIDER_URL, providerURL);
           env.put(Context.SECURITY_AUTHENTICATION, "simple");
  @@ -438,6 +500,7 @@
           env.put(Context.SECURITY_CREDENTIALS, password);
   
           DirContext ctx = new javax.naming.directory.InitialDirContext(env);
  +
           return ctx;
       }
   
  @@ -452,16 +515,16 @@
       {
           try
           {
  -            return (LDAPUser)TurbineSecurity.getUserInstance();
  +            return (LDAPUser) TurbineSecurity.getUserInstance();
           }
  -        catch(ClassCastException ex)
  +        catch (ClassCastException ex)
           {
  -            throw new DataBackendException("ClassCastException caught:", ex);
  +            throw new DataBackendException("ClassCastException:", ex);
           }
  -        catch(UnknownEntityException ex)
  +        catch (UnknownEntityException ex)
           {
  -            throw new DataBackendException("UnknownEntityException caught:", ex);
  +            throw new DataBackendException("UnknownEntityException:", ex);
           }
  -  }
  +    }
   
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/util ParseExceptionMessage.java

Posted by Stephen Haberman <st...@beachead.com>.
On Mon, Jan 13, 2003 at 10:53:05PM +0000, Henning P. Schmiedehausen wrote:
> Uh, I start to sound like Jon. :-) 

Hehehe.

- Stephen

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/util ParseExceptionMessage.java

Posted by Daniel Rall <dl...@collab.net>.
On Mon, 13 Jan 2003, Henning P. Schmiedehausen wrote:

> mpoeschl@apache.org writes:
> 
> >               Iterator groupsIterator = getAllGroups().elements();
> >  +            while (groupsIterator.hasNext())
> 
> Can we please start using the
> 
> 	for(Iterator it = ... ; it.hasNext(); )
> 	{
> 	}
> 
> 	pattern here?

+1

> Uh, I start to sound like Jon. :-) 

Heh ;-)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/security/ldap/util ParseExceptionMessage.java

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
mpoeschl@apache.org writes:

>               Iterator groupsIterator = getAllGroups().elements();
>  +            while (groupsIterator.hasNext())

Can we please start using the

	for(Iterator it = ... ; it.hasNext(); )
	{
	}

	pattern here?


Uh, I start to sound like Jon. :-) 

	Regards
		Henning

-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20   

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>