Skip to content

Commit

Permalink
Fixes bug in FTP service that prevents some clients from changing the…
Browse files Browse the repository at this point in the history
… directory.
  • Loading branch information
cmorgner committed Dec 2, 2016
1 parent 2f1b36e commit 2d00694
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ public class StructrFileSystemView implements FileSystemView {
private String workingDir = "/";

public StructrFileSystemView(final User user) {

try (Tx tx = StructrApp.getInstance().tx()) {

org.structr.web.entity.User structrUser = (org.structr.web.entity.User) AuthHelper.getPrincipalForCredential(AbstractUser.name, user.getName());

securityContext = SecurityContext.getInstance(structrUser, AccessMode.Backend);

this.user = new StructrFtpUser(securityContext, structrUser);

tx.success();

} catch (FrameworkException fex) {
logger.error("Error while initializing file system view", fex);
}
Expand Down Expand Up @@ -94,27 +94,27 @@ public FtpFile getWorkingDirectory() throws FtpException {
try (Tx tx = StructrApp.getInstance(securityContext).tx()) {

AbstractFile structrWorkingDir = FileHelper.getFileByAbsolutePath(securityContext, workingDir);

tx.success();

if (structrWorkingDir == null || structrWorkingDir instanceof FileBase) {
return new StructrFtpFolder(securityContext, null);
}

return new StructrFtpFolder(securityContext, (Folder) structrWorkingDir);

} catch (FrameworkException fex) {
logger.error("Error in changeWorkingDirectory()", fex);
}

return null;
}

@Override
public boolean changeWorkingDirectory(String requestedPath) throws FtpException {

try (Tx tx = StructrApp.getInstance(securityContext).tx()) {

final StructrFtpFolder newWorkingDirectory = (StructrFtpFolder) getFile(requestedPath);

workingDir = newWorkingDirectory.getAbsolutePath();
Expand All @@ -131,9 +131,16 @@ public boolean changeWorkingDirectory(String requestedPath) throws FtpException
}

@Override
public FtpFile getFile(String requestedPath) throws FtpException {
public FtpFile getFile(final String rawRequestedPath) throws FtpException {

String requestedPath = rawRequestedPath;

// remove trailing slash
if (requestedPath.endsWith("/")) {
requestedPath = requestedPath.substring(0, requestedPath.length() - 1);
}

logger.info("Requested path: {}", requestedPath);
logger.info("Requested path: {}, cleaned to {}", rawRequestedPath, requestedPath);

try (Tx tx = StructrApp.getInstance(securityContext).tx()) {

Expand Down

0 comments on commit 2d00694

Please sign in to comment.