Commit cb9a66ff authored by Dustin Jenkins's avatar Dustin Jenkins
Browse files

Story 1734: Added UserRequestReader test and implementation for JSON.

parent 7da562b5
Loading
Loading
Loading
Loading
+63 −76
Original line number Diff line number Diff line
@@ -67,9 +67,8 @@
************************************************************************
-->


<!DOCTYPE project>
<project name="cadcAccessControl-Server" default="build" basedir=".">

  <property environment="env"/>
  <property file="local.build.properties"/>

@@ -102,7 +101,8 @@
  <property name="unboundid" value="${ext.lib}/unboundid-ldapsdk-se.jar"/>
  <property name="xerces" value="${ext.lib}/xerces.jar"/>

    <property name="jars" value="${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}:${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${wsUtil}" />
  <property name="jars"
            value="${javacsv}:${jdom2}:${log4j}:${servlet}:${unboundid}:${xerces}:${cadcAccessControl}:${cadcLog}:${cadcRegistry}:${cadcUtil}:${cadcUWS}:${wsUtil}"/>

  <target name="build" depends="compile">
    <jar jarfile="${build}/lib/${project}.jar"
@@ -121,29 +121,16 @@
  <property name="objenesis" value="${ext.dev}/objenesis.jar"/>
  <property name="asm" value="${ext.dev}/asm.jar"/>

    <property name="testingJars"    value="${jars}:${json}:${easyMock}:${junit}:${xmlunit}:${cglib}:${asm}:${objenesis}" />

    <target name="resources">
        <copy todir="${build}/class">
            <fileset dir="config">
                <include name="**.properties" />
            </fileset>
        </copy>
    </target>
  <property name="testingJars"
            value="${jars}:${json}:${easyMock}:${junit}:${xmlunit}:${cglib}:${asm}:${objenesis}"/>

    <target name="test" depends="compile,compile-test,resources">
        <echo message="Running test suite..." />
        <junit printsummary="yes" haltonfailure="yes" fork="yes">
            <classpath>
                <pathelement path="${build}/class"/>
                <pathelement path="${build}/test/class"/>
                <pathelement path="${testingJars}"/>
            </classpath>
            <test name="ca.nrc.cadc.ac.server.ldap.LdapUserDAOTest" />
            <!--<test name="ca.nrc.cadc.ac.server.web.users.UserActionFactoryTest" />-->
            <!--<test name="ca.nrc.cadc.ac.server.web.users.UsersActionTest" />-->
            <formatter type="plain" usefile="false" />
        </junit>
  <target name="setup-test">
    <echo>******************</echo>
    <echo>******************</echo>
    <echo>Don't forget to set the ca.nrc.cadc.util.PropertiesReader.dir system property first!</echo>
    <echo>e.g. ant -Dca.nrc.cadc.util.PropertiesReader.dir=test clean build test</echo>
    <echo>******************</echo>
    <echo>******************</echo>
  </target>

</project>
+3 −2
Original line number Diff line number Diff line
@@ -140,9 +140,10 @@ public class PluginFactory
    @SuppressWarnings("unchecked")
    public <T extends Principal> UserPersistence<T> getUserPersistence()
    {
        UserPersistence<T> ret = null;
        UserPersistence ret = null;
        String name = UserPersistence.class.getName();
        String cname = config.getProperty(name);

        if (cname == null)
        {
            ret = new LdapUserPersistence<T>();
@@ -152,7 +153,7 @@ public class PluginFactory
            try
            {
                Class<?> c = Class.forName(cname);
                ret = (UserPersistence<T>) c.newInstance();
                ret = (UserPersistence) c.newInstance();
            }
            catch (Exception ex)
            {
+8 −8
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ import ca.nrc.cadc.net.TransientException;

import com.unboundid.ldap.sdk.DN;

public abstract interface UserPersistence<T extends Principal>
public interface UserPersistence<T extends Principal>
{
    /**
     * Get all user names.
@@ -88,7 +88,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public Collection<String> getUserNames()
    Collection<String> getUserNames()
            throws TransientException, AccessControlException;
    
    /**
@@ -101,7 +101,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract User<T> addUser(UserRequest<T> user)
    User<T> addUser(UserRequest<T> user)
        throws TransientException, AccessControlException;
    
    /**
@@ -115,7 +115,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract User<T> getUser(T userID)
    User<T> getUser(T userID)
        throws UserNotFoundException, TransientException, 
               AccessControlException;
    
@@ -130,7 +130,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract User<T> modifyUser(User<T> user)
    User<T> modifyUser(User<T> user)
        throws UserNotFoundException, TransientException, 
               AccessControlException;
    
@@ -143,7 +143,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract void deleteUser(T userID)
    void deleteUser(T userID)
        throws UserNotFoundException, TransientException, 
               AccessControlException;
    
@@ -160,7 +160,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract Collection<DN> getUserGroups(T userID, boolean isAdmin)
    Collection<DN> getUserGroups(T userID, boolean isAdmin)
        throws UserNotFoundException, TransientException,
               AccessControlException;
    
@@ -176,7 +176,7 @@ public abstract interface UserPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     */
    public abstract boolean isMember(T userID, String groupID)
    boolean isMember(T userID, String groupID)
        throws UserNotFoundException, TransientException,
               AccessControlException;
}
+5 −6
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ import ca.nrc.cadc.ac.xml.UserWriter;

import java.security.Principal;

public class CreateUserAction extends UsersAction
public class CreateUserAction<T extends Principal> extends UsersAction
{
    private final InputStream inputStream;

@@ -90,11 +90,10 @@ public class CreateUserAction extends UsersAction
    public Object run()
        throws Exception
    {
        UserPersistence userPersistence = getUserPersistence();
        UserRequest userRequest = UserRequestReader.read(this.inputStream);
        User<? extends Principal> newUser = userPersistence.addUser(userRequest);
        this.response.setContentType(acceptedContentType);
        writeUser(newUser, this.response.getWriter());
        UserPersistence<Principal> userPersistence = getUserPersistence();
        UserRequest<Principal> userRequest = readUserRequest(this.inputStream);
        User<Principal> newUser = userPersistence.addUser(userRequest);
        writeUser(newUser);
        logUserInfo(newUser.getUserID().getName());
        return null;
    }
+5 −7
Original line number Diff line number Diff line
@@ -69,10 +69,10 @@

import ca.nrc.cadc.ac.User;
import ca.nrc.cadc.ac.server.UserPersistence;
import ca.nrc.cadc.ac.xml.UserWriter;

import java.security.Principal;


public class GetUserAction extends UsersAction
{
    private final Principal userID;
@@ -83,13 +83,11 @@ public class GetUserAction extends UsersAction
        this.userID = userID;
    }

    public Object run()
        throws Exception
    public Object run() throws Exception
    {
        UserPersistence userPersistence = getUserPersistence();
        User<? extends Principal> user = userPersistence.getUser(userID);
        this.response.setContentType(acceptedContentType);
        writeUser(user, this.response.getWriter());
        UserPersistence<Principal> userPersistence = getUserPersistence();
        User<Principal> user = userPersistence.getUser(userID);
        writeUser(user);
        return null;
    }

Loading