Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
File Repository
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Genesys PGR
File Repository
Commits
c9d5e0cc
Commit
c9d5e0cc
authored
Feb 19, 2019
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FTP: CWD only to existing folders
parent
887342e4
Pipeline
#8978
passed with stage
in 5 minutes and 2 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
17 deletions
+41
-17
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/FtpRunAs.java
...java/org/genesys/filerepository/service/ftp/FtpRunAs.java
+2
-0
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/RepositoryFileSystemFactory.java
...lerepository/service/ftp/RepositoryFileSystemFactory.java
+31
-13
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/TemporaryBytesManager.java
...sys/filerepository/service/ftp/TemporaryBytesManager.java
+2
-3
file-repository-ftpserver/src/test/java/org/genesys/filerepository/service/ftp/FtpServerTest.java
...org/genesys/filerepository/service/ftp/FtpServerTest.java
+6
-1
No files found.
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/FtpRunAs.java
View file @
c9d5e0cc
...
@@ -69,6 +69,8 @@ public class FtpRunAs {
...
@@ -69,6 +69,8 @@ public class FtpRunAs {
try
{
try
{
return
runnable
.
run
();
return
runnable
.
run
();
}
catch
(
Throwable
e
)
{
throw
e
;
}
finally
{
}
finally
{
if
(
ftpUser
!=
null
&&
ftpUser
.
user
!=
null
)
{
if
(
ftpUser
!=
null
&&
ftpUser
.
user
!=
null
)
{
LOG
.
trace
(
"Switching back from {}"
,
ftpUser
.
user
.
getUsername
());
LOG
.
trace
(
"Switching back from {}"
,
ftpUser
.
user
.
getUsername
());
...
...
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/RepositoryFileSystemFactory.java
View file @
c9d5e0cc
...
@@ -42,7 +42,6 @@ import org.slf4j.Logger;
...
@@ -42,7 +42,6 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.security.core.AuthenticationException
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -241,9 +240,25 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -241,9 +240,25 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
public
boolean
changeWorkingDirectory
(
final
String
dir
)
{
public
boolean
changeWorkingDirectory
(
final
String
dir
)
{
final
Path
normalized
=
Paths
.
get
(
getAbsolutePath
()).
resolve
(
dir
).
normalize
().
toAbsolutePath
();
final
Path
normalized
=
Paths
.
get
(
getAbsolutePath
()).
resolve
(
dir
).
normalize
().
toAbsolutePath
();
LOG
.
info
(
"CWD this={} dir={} normalized={}"
,
getAbsolutePath
(),
dir
,
normalized
);
LOG
.
info
(
"CWD this={} dir={} normalized={}"
,
getAbsolutePath
(),
dir
,
normalized
);
this
.
cwd
(
normalized
);
if
(
"/"
.
equals
(
normalized
.
toString
()))
{
// TODO Check if such path exists?
this
.
cwd
(
normalized
);
return
true
;
return
true
;
}
// Check if such path exists?
try
{
RepositoryFolder
folder
=
repositoryService
.
getFolder
(
normalized
);
if
(
folder
!=
null
)
{
this
.
cwd
(
normalized
);
return
true
;
}
else
{
LOG
.
warn
(
"CWD to non-existent folder {} normalized={}"
,
dir
,
normalized
.
toString
());
return
false
;
}
}
catch
(
InvalidRepositoryPathException
e
)
{
LOG
.
warn
(
"CWD to non-existent folder {} normalized={}"
,
dir
,
normalized
.
toString
(),
e
);
return
false
;
}
}
}
};
};
...
@@ -271,10 +286,10 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -271,10 +286,10 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
try
{
try
{
return
isDirectory
(
path
)
?
return
isDirectory
(
path
)
?
// directory
// directory
directory
(
path
,
this
)
directory
(
"/"
.
equals
(
path
.
toString
())
?
path
:
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
getFolder
(
path
).
getFolderPath
())
,
this
)
// or file
// or file
:
file
(
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
getFile
(
path
.
getParent
(),
path
.
getFileName
().
toString
())),
this
);
:
file
(
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
getFile
(
path
.
getParent
(),
path
.
getFileName
().
toString
())),
this
);
}
catch
(
final
AuthenticationException
e
)
{
}
catch
(
final
AuthenticationException
e
)
{
LOG
.
warn
(
"Authentication problem {}"
,
e
.
getMessage
(),
e
);
LOG
.
warn
(
"Authentication problem {}"
,
e
.
getMessage
(),
e
);
...
@@ -282,7 +297,7 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -282,7 +297,7 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
}
catch
(
InvalidRepositoryPathException
e
)
{
}
catch
(
InvalidRepositoryPathException
e
)
{
throw
new
FtpException
(
e
.
getMessage
());
throw
new
FtpException
(
e
.
getMessage
());
}
catch
(
NoSuchRepositoryFileException
e
)
{
}
catch
(
NoSuchRepositoryFileException
e
)
{
LOG
.
warn
(
"No such file {}"
,
file
);
LOG
.
debug
(
"No such file {}: {}"
,
file
,
e
.
getMessage
()
);
return
new
CanBeAnythingFile
(
path
.
getParent
(),
path
.
getFileName
().
toString
())
{
return
new
CanBeAnythingFile
(
path
.
getParent
(),
path
.
getFileName
().
toString
())
{
...
@@ -290,8 +305,8 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -290,8 +305,8 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
public
boolean
mkdir
()
{
public
boolean
mkdir
()
{
LOG
.
debug
(
"MKDIR {}"
,
path
);
LOG
.
debug
(
"MKDIR {}"
,
path
);
try
{
try
{
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
ensureFolder
(
path
));
RepositoryFolder
repositoryFolder
=
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
ensureFolder
(
path
));
return
true
;
return
repositoryFolder
!=
null
;
}
catch
(
InvalidRepositoryPathException
e
)
{
}
catch
(
InvalidRepositoryPathException
e
)
{
LOG
.
warn
(
"{}"
,
e
.
getMessage
(),
e
);
LOG
.
warn
(
"{}"
,
e
.
getMessage
(),
e
);
return
false
;
return
false
;
...
@@ -300,7 +315,7 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -300,7 +315,7 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
@Override
@Override
public
boolean
delete
()
{
public
boolean
delete
()
{
return
fals
e
;
return
tru
e
;
}
}
@Override
@Override
...
@@ -309,7 +324,10 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
...
@@ -309,7 +324,10 @@ public class RepositoryFileSystemFactory implements FileSystemFactory, Initializ
if
(
path
.
getParent
()
!=
null
)
{
if
(
path
.
getParent
()
!=
null
)
{
LOG
.
debug
(
"MKDIR {}"
,
path
.
getParent
());
LOG
.
debug
(
"MKDIR {}"
,
path
.
getParent
());
try
{
try
{
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
ensureFolder
(
path
.
getParent
()));
RepositoryFolder
repositoryFolder
=
FtpRunAs
.
asFtpUser
(
user
,
()
->
repositoryService
.
ensureFolder
(
path
.
getParent
()));
if
(
repositoryFolder
==
null
)
{
throw
new
InvalidRepositoryPathException
(
"Folder not created "
+
path
.
getParent
());
}
return
bytesManager
.
newFile
(
user
,
path
);
return
bytesManager
.
newFile
(
user
,
path
);
}
catch
(
InvalidRepositoryPathException
e
)
{
}
catch
(
InvalidRepositoryPathException
e
)
{
LOG
.
warn
(
"{}"
,
e
.
getMessage
(),
e
);
LOG
.
warn
(
"{}"
,
e
.
getMessage
(),
e
);
...
...
file-repository-ftpserver/src/main/java/org/genesys/filerepository/service/ftp/TemporaryBytesManager.java
View file @
c9d5e0cc
...
@@ -89,13 +89,12 @@ public class TemporaryBytesManager {
...
@@ -89,13 +89,12 @@ public class TemporaryBytesManager {
FtpRunAs
.
asFtpUser
(
user
,
()
->
{
FtpRunAs
.
asFtpUser
(
user
,
()
->
{
final
byte
[]
bytes
=
readTempFileToBytes
(
tempFile
);
final
byte
[]
bytes
=
readTempFileToBytes
(
tempFile
);
try
{
try
{
repositoryService
.
addFile
(
parent
,
filename
,
null
,
bytes
,
null
);
LOG
.
info
(
"Synchronizing file={} with repository path={} originalFilename={}"
,
tempFile
.
getAbsolutePath
(),
parent
,
filename
);
return
repositoryService
.
addFile
(
parent
,
filename
,
null
,
bytes
,
null
);
}
catch
(
InvalidRepositoryPathException
|
InvalidRepositoryFileDataException
e
)
{
}
catch
(
InvalidRepositoryPathException
|
InvalidRepositoryFileDataException
e
)
{
LOG
.
warn
(
"Error synchronizing new file parent={} filename={} with repository: {}"
,
parent
,
filename
,
e
.
getMessage
());
LOG
.
warn
(
"Error synchronizing new file parent={} filename={} with repository: {}"
,
parent
,
filename
,
e
.
getMessage
());
throw
new
IOException
(
e
);
throw
new
IOException
(
e
);
}
}
LOG
.
info
(
"Synchronized file={} with repository path={} originalFilename={}"
,
tempFile
.
getAbsolutePath
(),
parent
,
filename
);
return
null
;
});
});
}
}
};
};
...
...
file-repository-ftpserver/src/test/java/org/genesys/filerepository/service/ftp/FtpServerTest.java
View file @
c9d5e0cc
...
@@ -387,7 +387,8 @@ public class FtpServerTest {
...
@@ -387,7 +387,8 @@ public class FtpServerTest {
try
(
InputStream
local
=
new
ByteArrayInputStream
(
TEST_FILE_CONTENTS
.
getBytes
()))
{
try
(
InputStream
local
=
new
ByteArrayInputStream
(
TEST_FILE_CONTENTS
.
getBytes
()))
{
assertThat
(
ftp
.
storeFile
(
"/a/b/c/d/e/f/g"
,
local
),
is
(
true
));
assertThat
(
ftp
.
storeFile
(
"/a/b/c/d/e/f/g"
,
local
),
is
(
true
));
}
}
debugListFiles
(
ftp
);
for
(
final
String
dir
:
new
String
[]
{
"/"
,
"/a"
,
"/a/b"
,
"/a/b/c"
,
"/a/b/c/d"
,
"/a/b/c/d/e"
,
"/a/b/c/d/e"
,
"/a/b/c/d/e/f"
})
{
for
(
final
String
dir
:
new
String
[]
{
"/"
,
"/a"
,
"/a/b"
,
"/a/b/c"
,
"/a/b/c/d"
,
"/a/b/c/d/e"
,
"/a/b/c/d/e"
,
"/a/b/c/d/e/f"
})
{
assertThat
(
ftp
.
changeWorkingDirectory
(
dir
),
is
(
true
));
assertThat
(
ftp
.
changeWorkingDirectory
(
dir
),
is
(
true
));
debugListFiles
(
ftp
);
debugListFiles
(
ftp
);
...
@@ -484,6 +485,10 @@ public class FtpServerTest {
...
@@ -484,6 +485,10 @@ public class FtpServerTest {
ftp
.
setFileTransferMode
(
FTP
.
ASCII_FILE_TYPE
);
ftp
.
setFileTransferMode
(
FTP
.
ASCII_FILE_TYPE
);
ftp
.
cwd
(
"folder"
);
ftp
.
cwd
(
"folder"
);
assertThat
(
ftp
.
printWorkingDirectory
(),
is
(
"/"
));
ftp
.
makeDirectory
(
"folder"
);
ftp
.
cwd
(
"folder"
);
assertThat
(
ftp
.
printWorkingDirectory
(),
is
(
"/folder"
));
assertThat
(
ftp
.
printWorkingDirectory
(),
is
(
"/folder"
));
try
(
InputStream
local
=
new
ByteArrayInputStream
(
TEST_FILE_CONTENTS
.
getBytes
()))
{
try
(
InputStream
local
=
new
ByteArrayInputStream
(
TEST_FILE_CONTENTS
.
getBytes
()))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment