summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Schwabe2014-06-23 15:12:57 +0200
committerNils Schwabe2014-06-23 15:12:57 +0200
commite37fd784eefe513eda7ab946dcf92b8e8fe1b8a6 (patch)
tree7f7fe48fd392223ee63166467f6342553b2ddc77
parentForgot thrift file (diff)
downloadmasterserver-e37fd784eefe513eda7ab946dcf92b8e8fe1b8a6.tar.gz
masterserver-e37fd784eefe513eda7ab946dcf92b8e8fe1b8a6.tar.xz
masterserver-e37fd784eefe513eda7ab946dcf92b8e8fe1b8a6.zip
Fix some issues with the ftp connection and the ftp user management
Remove some not needed imports from various files
-rw-r--r--src/main/java/org/openslx/imagemaster/db/DbUser.java20
-rw-r--r--src/main/java/org/openslx/imagemaster/ftp/ImageProcessor.java4
-rw-r--r--src/main/java/org/openslx/imagemaster/ftp/MasterFtpServer.java2
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java10
-rw-r--r--src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java1
-rw-r--r--src/main/java/org/openslx/imagemaster/util/Util.java18
-rw-r--r--src/test/java/org/openslx/imagemaster/ServerTest.java22
7 files changed, 42 insertions, 35 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbUser.java b/src/main/java/org/openslx/imagemaster/db/DbUser.java
index 8cf4b55..ffc9d1a 100644
--- a/src/main/java/org/openslx/imagemaster/db/DbUser.java
+++ b/src/main/java/org/openslx/imagemaster/db/DbUser.java
@@ -71,4 +71,24 @@ public class DbUser extends User
return user.username;
}
+ /**
+ * Checks if a user with id (userid@organization) exists
+ * @param id
+ * @return whether ther user exists
+ */
+ public static boolean exists( String id )
+ {
+ String user = id.split( "@" )[0];
+ String organization = id.split( "@" )[1];
+
+ DbUser dbUser = MySQL.findUniqueOrNull( DbUser.class,
+ "SELECT user.userid, user.username, user.password, user.organization, user.firstname, user.lastname, user.email, satellite.address FROM user"
+ + " LEFT JOIN satellite USING (organization)"
+ + " WHERE user.username = ? AND user.organization = ? LIMIT 1", user, organization);
+
+ if ( dbUser == null ) return false;
+
+ return true;
+ }
+
}
diff --git a/src/main/java/org/openslx/imagemaster/ftp/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/ftp/ImageProcessor.java
index a9a7fc4..2e480dc 100644
--- a/src/main/java/org/openslx/imagemaster/ftp/ImageProcessor.java
+++ b/src/main/java/org/openslx/imagemaster/ftp/ImageProcessor.java
@@ -122,8 +122,8 @@ public class ImageProcessor
throw new ImageDataException(ImageDataError.INVALID_DATA, "UUID not valid.");
} else if (imageData.imageName.length() < 5 || imageData.imageName.length() > 50) {
throw new ImageDataException(ImageDataError.INVALID_DATA, "ImageName not valid. (Length must be 5 to 50)");
- } else if (DbUser.getUserIdByName( imageData.imageOwner ) != 0) {
- throw new ImageDataException(ImageDataError.INVALID_DATA, "ImageOwner not valid.");
+ } else if (!DbUser.exists( imageData.imageOwner )) {
+ throw new ImageDataException(ImageDataError.INVALID_DATA, "ImageOwner not known.");
} else if ( imageData.fileSize <= 0 ) {
throw new ImageDataException(ImageDataError.INVALID_DATA, "Filesize needs to be greater than 0.");
}
diff --git a/src/main/java/org/openslx/imagemaster/ftp/MasterFtpServer.java b/src/main/java/org/openslx/imagemaster/ftp/MasterFtpServer.java
index dff45b5..c24b318 100644
--- a/src/main/java/org/openslx/imagemaster/ftp/MasterFtpServer.java
+++ b/src/main/java/org/openslx/imagemaster/ftp/MasterFtpServer.java
@@ -211,7 +211,7 @@ public class MasterFtpServer implements Runnable
authorities.add( new WritePermission() );
} else if (mode == Mode.DOWNLOADING) {
// the downloading satellite may access the whole dir, but this is restricted in MasterFtplet
- dir = Globals.getPropertyString( Globals.PropString.FTPBASEDIR );
+ dir = Globals.getPropertyString( Globals.PropString.IMAGEDIR );
// downloading satellite is only allowed to read
file = fileName;
}
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index a36f201..52783d9 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -184,6 +184,10 @@ public class ApiServer
synchronized ( App.ftpServer.users ) {
if (!App.ftpServer.users.containsKey( ftpUser )) {
throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "Image with this data was not submitted before." );
+ } else {
+ if ( App.ftpServer.users.get( ftpUser ).getMode() == MasterFtpServer.Mode.DOWNLOADING ) {
+ throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "Your were downloading and not uploading." );
+ }
}
}
@@ -191,7 +195,7 @@ public class ApiServer
File userDirectory = new File( Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + ftpUser );
File[] list = userDirectory.listFiles();
- if ( list.length != 1 ) {
+ if ( list == null || list.length != 1 ) {
// user uploaded too many files
return false;
}
@@ -218,7 +222,7 @@ public class ApiServer
if (image == null) throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "No image found with uuid '" + uuid + "'");
- FtpCredentials ftpCredentials = App.ftpServer.addUser( serverSessionId, MasterFtpServer.Mode.DOWNLOADING, image.imagePath );
+ FtpCredentials ftpCredentials = App.ftpServer.addUser( serverSessionId, MasterFtpServer.Mode.DOWNLOADING, new File(image.imagePath).getName() );
// TODO: what is happening here?
if (ftpCredentials == null) return null;
@@ -231,6 +235,8 @@ public class ApiServer
if ( !App.ftpServer.users.containsKey( ftpUser ))
return false;
+ log.info( "User: '" + ftpUser + "' finished download and gets deleted." );
+
// download is done, user can be removed now
App.ftpServer.removeUser( ftpUser );
diff --git a/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java b/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java
index e2a0a0e..ccd7ced 100644
--- a/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java
+++ b/src/main/java/org/openslx/imagemaster/util/AsymMessageVerifier.java
@@ -14,7 +14,6 @@ import java.security.cert.CertificateException;
import java.security.spec.X509EncodedKeySpec;
import org.openslx.imagemaster.db.DbKey;
-import org.openslx.imagemaster.db.DbSatellite;
public class AsymMessageVerifier
{
diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java
index 9805c21..fb13c86 100644
--- a/src/main/java/org/openslx/imagemaster/util/Util.java
+++ b/src/main/java/org/openslx/imagemaster/util/Util.java
@@ -1,27 +1,9 @@
package org.openslx.imagemaster.util;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.security.InvalidKeyException;
-import java.security.Key;
-import java.security.KeyPair;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.Signature;
-import java.security.SignatureException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
import java.util.Random;
import org.apache.log4j.Logger;
-import org.openslx.imagemaster.Globals;
-import org.openslx.imagemaster.Globals.PropString;
public class Util
{
diff --git a/src/test/java/org/openslx/imagemaster/ServerTest.java b/src/test/java/org/openslx/imagemaster/ServerTest.java
index 969af13..946b33f 100644
--- a/src/test/java/org/openslx/imagemaster/ServerTest.java
+++ b/src/test/java/org/openslx/imagemaster/ServerTest.java
@@ -66,17 +66,17 @@ public class ServerTest extends TestCase
assertTrue(true);
}
- public void testSomething() throws TException {
- TTransport transport = new TSocket("localhost", 9090);
- transport.open();
-
- TProtocol protocol = new TBinaryProtocol(transport);
- Client client = new Client(protocol);
-
- assertTrue( "Could not ping server", client.ping() );
-
- client.getImage( "8fbaf5cb-ebf6-11e3-996b-f5a55bd7273c", "" );
- }
+// public void testSomething() throws TException {
+// TTransport transport = new TSocket("localhost", 9090);
+// transport.open();
+//
+// TProtocol protocol = new TBinaryProtocol(transport);
+// Client client = new Client(protocol);
+//
+// assertTrue( "Could not ping server", client.ping() );
+//
+// client.getImage( "8fbaf5cb-ebf6-11e3-996b-f5a55bd7273c", "" );
+// }
/**
* Test the authentication