head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2001.07.30.18.10.13;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2001.07.30.16.42.03;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.07.27.22.59.32;	author stack;	state Exp;
branches;
next	1.2;

1.2
date	2001.07.27.22.07.44;	author leonardr;	state Exp;
branches;
next	1.1;

1.1
date	2001.07.27.19.18.00;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Added XML-RPC hyperlink and made correction to JavaDoc.
@
text
@/* ================================================================
 * Copyright (c) 2001 CollabNet.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by CollabNet <http://www.collab.net/>."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 *
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 *
 * 5. Products derived from this software may not use the "Tigris" or
 * "Helm" names nor may "Tigris" or "Helm" appear in their names without
 * prior written permission of CollabNet.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CollabNet.
 */

package org.tigris.helm.tool.handler;

import java.util.*;

import org.apache.turbine.util.Log;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;

/**
 * Used to handle user information calls made via
 * <a href="http://xml-rpc.com/">XML-RPC</a>.
 *
 * @@author <a href="mailto:leonardr@@collab.net">Leonard Richardson</a>
 */
public class UserHandler extends HelmHandler
{
    /**
     * Returns a user specified by ID.
     *
     * @@return Hash of user properties.  If user does not exist, we return 
     *         empty hash (XML-RPC does not support nulls or passing of 
     *         exceptions).
     */
    public Hashtable getUserInfo(String auth, int userID)
        throws Exception
    {
        validateAuth(auth);
        User u = null;

        try
        {
            u = UserPeer.getInstance(String.valueOf(userID));
        }
        catch( DoesNotExist dne )
        {
            // Do not propagate.  Instead return empty hash to xmlrpc client.
        }
 
        return (u == null ? new Hashtable(0) : u.asHashtable());
    }

    /**
     * Returns a user specified by domain and login name.
     *
     * @@return Hash of user properties.  If user does not exist, we return 
     *         empty hash (XML-RPC does not support nulls or passing of 
     *         exceptions).
     */
    public Hashtable getUserInfo(String auth, String domainName, 
                                 String loginName)
        throws Exception
    {
        validateAuth(auth);
        User u = null;

        try
        {
            Domain domain = ProjectPeer.getDomain(domainName);
            u = UserPeer.getInstanceByLoginName(domain, loginName);
        }
        catch( DoesNotExist dne )
        {
            // Do not propagate.  Instead return empty hash to xmlrpc client.
        }

        return (u == null ? new Hashtable(0) : u.asHashtable());
    }

    /**
     * Returns a Vector of users corresponding to the given Vector of
     * userIDs.
     */
    public Vector getUserInfo(String auth, Vector userIDs)
        throws Exception
    {
        validateAuth(auth);
        
        Vector users = new Vector(0);
        for (Iterator i = userIDs.iterator(); i.hasNext();)
        {
            try
            {
                Integer t = (Integer)i.next();
                User u = UserPeer.getInstance(String.valueOf(t));
                users.addElement(u.asHashtable());
            }
            catch( DoesNotExist dne )
            {
                // Do not propagate exception.  Keep looping.
            }
        }
        return users;
    }

    /**
     * Returns true if the given user/password combination is valid.
     *
     * @@return Valid or not.  If user or domain does not exist, return 
     *         false (XML-RPC does not support nulls or passing of exceptions).
     */
    public boolean isValidLogin(String auth, String domainName, 
                                String userName, String password)
        throws Exception
    {
        validateAuth(auth);
        boolean valid = false;
        try
        {
            Domain domain = ProjectPeer.getDomain(domainName);
            valid = UserPeer.isValidLogin(domain, userName, password);
        }
        catch( DoesNotExist dne )
        {
            // Do not propagate this exception.
        }

        return valid;
    }
}
@


1.4
log
@Black magic to get rid of weird casting error.
@
text
@d57 2
a58 1
 * Used to handle permission calls made via XML-RPC.
a64 7
     * Empty constructor.
     */
    public UserHandler()
    {
    }

    /**
d86 1
a86 1
        return ( u != null )? u.asHashtable(): new Hashtable( );
d113 1
a113 1
        return ( u != null )? u.asHashtable(): new Hashtable( );
@


1.3
log
@Stop DoesNotExit exception and null values being returned to xmlrpc clients.

There is no provision for null values in the xmlrpc spec. and exceptions show
on the client as a general exception in the java client while the perl
client just does 'die'.

I also set the package to suit this location.
@
text
@d136 2
a137 1
                User u = UserPeer.getInstance(i.next().toString());
@


1.2
log
@New method which acts as a bulk getUserInfo.
@
text
@d47 1
a47 1
package org.tigris.helm.security;
d53 1
d72 4
a79 1
        Hashtable user = null;
d81 12
a92 3
        User u = UserPeer.getInstance(String.valueOf(userID));
        user = u.asHashtable();
        return user;
d97 4
d107 13
a119 5
        Hashtable user = null;
        Domain domain = ProjectPeer.getDomain(domainName);
        User u = UserPeer.getInstanceByLoginName(domain, loginName);
        user = u.asHashtable();
        return user;
d131 1
a131 1
        Vector users = new Vector(userIDs.size());
d134 9
a142 2
            User u = UserPeer.getInstance(i.next().toString());
            users.addElement(u.asHashtable());
d148 4
a151 1
     * Returns true iff the given user/password combination is valid.
d158 12
a169 2
        Domain domain = ProjectPeer.getDomain(domainName);
        return UserPeer.isValidLogin(domain, userName, password);
@


1.1
log
@Factored out user code into a separate XML-RPC handler.
@
text
@d98 18
@

