Ignore:
Timestamp:
Oct 10, 2011, 3:32:34 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #329: Set active project when using FTP

I have implemented the third alternative. A project can be set active when logging in by using a login name as: username<projectname>.

Location:
extensions/net.sf.basedb.ftp/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.ftp/trunk/.classpath

    r1398 r1399  
    33  <classpathentry kind="src" path="src"/>
    44  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    5   <classpathentry kind="lib" path="lib/compile/BASE2Core.jar" sourcepath="/Base2/src/core"/>
    6   <classpathentry kind="lib" path="lib/compile/BASE2Webclient.jar"/>
    75  <classpathentry kind="lib" path="lib/compile/slf4j-api-1.5.2.jar"/>
    86  <classpathentry kind="lib" path="META-INF/lib/ftplet-api-1.0.5.jar"/>
  • extensions/net.sf.basedb.ftp/trunk/README

    r1382 r1399  
    4646== Tips and tricks ==
    4747
     48 * To activate a project when logging in via FTP, use a login name like
     49   `username<projectname>`, where `username` is the usual login and
     50   `projectname` is the name of the project to set active. This is useful
     51   to access files that has been shared to a project, but note that
     52   the path must be accessible all they way from the root. If no project
     53   with the given name can be found, the user is logged in without an
     54   active project.
     55
    4856 * If you want to try out an SSL enabled FTP server, but doesn't have
    4957   a certificate, you may create one with the following command:
  • extensions/net.sf.basedb.ftp/trunk/build.xml

    r1398 r1399  
    131131  </target>
    132132 
     133  <target
     134    name="install"
     135    depends="jar"
     136    >
     137    <fail unless="base.plugins" message="base.plugins is not set to the path of BASE plug-ins directory." />
     138    <copy todir="${base.plugins}">
     139      <fileset file="${jar.name}" />
     140    </copy>
     141    <echo>Copied '${jar.name}' to '${base.plugins}'.</echo>
     142  </target>
     143
    133144  <target name="update-version">
    134145    <echo>Setting version to: ${version}</echo>
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseUser.java

    r1381 r1399  
    3636import net.sf.basedb.core.DbControl;
    3737import net.sf.basedb.core.Directory;
     38import net.sf.basedb.core.Include;
     39import net.sf.basedb.core.ItemQuery;
    3840import net.sf.basedb.core.PermissionDeniedException;
     41import net.sf.basedb.core.Project;
    3942import net.sf.basedb.core.SessionControl;
    4043import net.sf.basedb.core.SystemItems;
     44import net.sf.basedb.core.Type;
    4145import net.sf.basedb.core.User;
     46import net.sf.basedb.core.query.Expressions;
     47import net.sf.basedb.core.query.Hql;
     48import net.sf.basedb.core.query.Restrictions;
    4249
    4350/**
     
    5966  SessionControl sc;
    6067  private User user;
     68  private Project project;
    6169  private BaseFtpFile home;
    6270 
     
    93101 
    94102  /**
    95     Get the {@link Application#sessionCacheTimeout() value
     103    Get the {@link Application#sessionCacheTimeout()} value
    96104    and convert it to seconds.
    97105  */
     
    261269 
    262270  /**
     271    Activate the project with the given name.
     272    @param name The name of the project, or null to deactive
     273  */
     274  public void setProject(String name)
     275  {
     276    if (!isLoggedIn()) return;
     277   
     278    if (name == null)
     279    {
     280      log.info("Deactivating current project: " + project);
     281      this.project = null;
     282      sc.setActiveProject(null);
     283      return;
     284    }
     285   
     286    log.info("Looking up project: " + name);
     287   
     288    ItemQuery<Project> projectQuery = Project.getQuery();
     289    projectQuery.include(Include.MINE, Include.SHARED);
     290    projectQuery.restrict(Restrictions.eq(Hql.property("name"), Expressions.parameter("name", name, Type.STRING)));
     291
     292    DbControl dc = null;
     293    try
     294    {
     295      dc = sc.newDbControl();
     296      List<Project> projects = projectQuery.list(dc);
     297      log.debug("Found " + projects.size() + " projects for name: " + name);
     298      if (projects.size() > 0)
     299      {
     300        this.project = projects.get(0);
     301        log.info("Activating project: " + project);
     302        sc.setActiveProject(project);
     303      }
     304    }
     305    catch (RuntimeException ex)
     306    {
     307      log.error("Failed to activate project: name=" + name, ex);
     308      throw ex;
     309    }
     310    finally
     311    {
     312      if (dc != null) dc.close();
     313    }   
     314  }
     315
     316 
     317  /**
    263318    Logout and close the session.
    264319  */
  • extensions/net.sf.basedb.ftp/trunk/src/net/sf/basedb/clients/ftp/BaseUserManager.java

    r1381 r1399  
    175175        String login = auth.getUsername();
    176176        String pwd = auth.getPassword();
     177        String project = null;
    177178        String ip = auth.getUserMetadata().getInetAddress().getHostAddress();
     179       
     180        /*
     181          If login has pattern like 'username<project>' we extract the
     182          login and project from it.
     183         */
     184        if (login != null && login.endsWith(">"))
     185        {
     186          int index = login.indexOf("<");
     187          if (index > 0 && index < login.length()-1)
     188          {
     189            project = login.substring(index+1, login.length()-1);
     190            login = login.substring(0,  index);
     191          }
     192        }
    178193       
    179194        log.info("Trying to authenticate: login=" + login);
    180195        log.debug("password=" + pwd);
     196        log.debug("project=" + project);
    181197        log.debug("ip=" + ip);
    182198       
     
    186202          user.login(pwd, ip, ftpClientIsInstalled ? BaseFtpServer.CLIENT_ID : null);
    187203          log.info("Login successful: login=" + login);
     204          if (project != null) user.setProject(project);
    188205        }
    189206        catch (Exception ex)
Note: See TracChangeset for help on using the changeset viewer.