diff options
19 files changed, 75 insertions, 44 deletions
diff --git a/src/main/java/org/openslx/imagemaster/App.java b/src/main/java/org/openslx/imagemaster/App.java index 9036977..34b50f8 100644 --- a/src/main/java/org/openslx/imagemaster/App.java +++ b/src/main/java/org/openslx/imagemaster/App.java @@ -9,6 +9,9 @@ import org.openslx.imagemaster.serverconnection.ImageProcessor; import org.openslx.imagemaster.thrift.server.BinaryListener; import org.slf4j.LoggerFactory; +/** + * The main class that starts all the services. + */ public class App { @@ -27,6 +30,7 @@ public class App // Init logging log.info( "Starting Application" ); + // Init the properties and load uploading images from database Globals.init(); ImageProcessor.init(); diff --git a/src/main/java/org/openslx/imagemaster/Globals.java b/src/main/java/org/openslx/imagemaster/Globals.java index b5ec686..78ecd70 100644 --- a/src/main/java/org/openslx/imagemaster/Globals.java +++ b/src/main/java/org/openslx/imagemaster/Globals.java @@ -9,12 +9,15 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.openslx.imagemaster.util.Util; +/** + * Class to hold global constants and properties from 'config/global.properties'. + */ public class Globals { private static Logger log = Logger.getLogger( Globals.class ); private static final Properties properties = new Properties(); - + /* CONSTANTS */ /** * The blocksize used for crc'ing. @@ -120,10 +123,10 @@ public class Globals { return Util.tryToParseInt( properties.getProperty( "ssl_socket_transmit_times" ) ); } - + public static int getCrcSchedulingInterval() { - return Util.tryToParseInt( properties.getProperty("crc_scheduling_interval") ); + return Util.tryToParseInt( properties.getProperty( "crc_scheduling_interval" ) ); } /* STRINGS */ diff --git a/src/main/java/org/openslx/imagemaster/db/DbImage.java b/src/main/java/org/openslx/imagemaster/db/DbImage.java index 6c64d06..dc2ab34 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbImage.java +++ b/src/main/java/org/openslx/imagemaster/db/DbImage.java @@ -10,6 +10,10 @@ import org.openslx.imagemaster.serverconnection.UploadingImage; import org.openslx.imagemaster.thrift.iface.ImageData; import org.openslx.imagemaster.util.Util; +/** + * Representing an image in the database. + * Is used to modify/update database entries. + */ public class DbImage { @@ -136,6 +140,7 @@ public class DbImage /** * Updates the missing blocks of an uploading image. + * * @param missingBlocks * @return */ @@ -152,6 +157,7 @@ public class DbImage /** * Updates the database with a new version of an image and its missing blocks. + * * @param version * @param amountBlocks */ @@ -168,6 +174,7 @@ public class DbImage /** * Marks an image as _deleted_ in the database. + * * @return */ public int delete() @@ -177,6 +184,7 @@ public class DbImage /** * Returns all images from database where blocks are still missing. + * * @return */ public static List<DbImage> getUploadingImages() @@ -190,6 +198,7 @@ public class DbImage /** * Returns the image that is corrsponding to a specified uuid. + * * @param uuid * @return */ diff --git a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java index f8bf036..fb35fb5 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java +++ b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java @@ -2,6 +2,10 @@ package org.openslx.imagemaster.db; import org.openslx.imagemaster.util.ByteArray; +/** + * Represents a satellite in the database. + * Is used to authenticate the satellite. + */ public class DbSatellite { diff --git a/src/main/java/org/openslx/imagemaster/db/DbUser.java b/src/main/java/org/openslx/imagemaster/db/DbUser.java index 7f83176..91e0615 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbUser.java +++ b/src/main/java/org/openslx/imagemaster/db/DbUser.java @@ -3,6 +3,9 @@ package org.openslx.imagemaster.db; import org.apache.log4j.Logger; import org.openslx.imagemaster.session.User; +/** + * Represents a user that can login against the masterserver. + */ public class DbUser extends User { diff --git a/src/main/java/org/openslx/imagemaster/db/LdapUser.java b/src/main/java/org/openslx/imagemaster/db/LdapUser.java index 39bbb69..2812755 100644 --- a/src/main/java/org/openslx/imagemaster/db/LdapUser.java +++ b/src/main/java/org/openslx/imagemaster/db/LdapUser.java @@ -28,7 +28,7 @@ import org.openslx.imagemaster.util.Sha512Crypt; /** * Represents a user instance that was queries (primarily) from LDAP. * Additional information that is not provided by the LDAP server might - * be fetched from other sources, like the local database. + * be fetched from other sources, like the local database (DbUser.java). */ public class LdapUser extends User { diff --git a/src/main/java/org/openslx/imagemaster/db/MySQL.java b/src/main/java/org/openslx/imagemaster/db/MySQL.java index 06496ea..3b5438d 100644 --- a/src/main/java/org/openslx/imagemaster/db/MySQL.java +++ b/src/main/java/org/openslx/imagemaster/db/MySQL.java @@ -21,6 +21,7 @@ import fi.evident.dalesbred.Database; */ class MySQL { + private static final Logger log = Logger.getLogger( MySQL.class ); private static Database db = null; diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java index 1428838..104d98d 100644 --- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java +++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java @@ -45,6 +45,7 @@ import org.openslx.imagemaster.thrift.iface.UserInfo; */ public class ApiServer { + /** * Request for authentication * @@ -83,32 +84,33 @@ public class ApiServer return new UserInfo( session.getUserId(), session.getFirstName(), session.getLastName(), session.getEMail() ); } - - public static UploadInfos submitImage( String serverSessionId, ImageData imageDescription, List<Integer> crcSums ) throws AuthorizationException, ImageDataException, UploadException + + public static UploadInfos submitImage( String serverSessionId, ImageData imageDescription, List<Integer> crcSums ) + throws AuthorizationException, ImageDataException, UploadException { // first check session of server if ( ServerSessionManager.getSession( serverSessionId ) == null ) { - throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessioId" ); - } + throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessioId" ); + } // then let the image processor decide what to do - return ImageProcessor.getUploadInfos(serverSessionId, imageDescription, crcSums); + return ImageProcessor.getUploadInfos( serverSessionId, imageDescription, crcSums ); } - + public static DownloadInfos getImage( String uuid, String serverSessionId, List<Integer> requestedBlocks ) throws AuthorizationException, ImageDataException { // first check session of server if ( ServerSessionManager.getSession( serverSessionId ) == null ) { - throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessionId" ); - } - - if (!DbImage.exists( uuid )) { + throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessionId" ); + } + + if ( !DbImage.exists( uuid ) ) { throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "UUID is not known by this server." ); } - + // then let the image processor decide what to do return ImageProcessor.getDownloadInfos( serverSessionId, uuid, requestedBlocks ); } - + /** * Start the server authentication of a uni/hs satellite server. * diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/Connection.java b/src/main/java/org/openslx/imagemaster/serverconnection/Connection.java index 28a9838..bfdb1bb 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/Connection.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/Connection.java @@ -1,5 +1,10 @@ package org.openslx.imagemaster.serverconnection; +/** + * This represents a connection. + * (When a satellite is up- or downloading an image from/to masterserver). + * It is used to help the ConnectionHandler and is storing infos. + */ public class Connection { /** diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java index 0447e68..7fa9c4e 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/ConnectionHandler.java @@ -27,6 +27,7 @@ import org.openslx.imagemaster.Globals; /** * Class to handle all incoming and outgoing connections. + * Also handles the authentication and the saving/delivering of images. */ public class ConnectionHandler implements IncomingEvent { @@ -140,7 +141,7 @@ public class ConnectionHandler implements IncomingEvent long actual; for ( Integer block : blocks ) { actual = block * Globals.blockSize; - uploader.prepareSendRange( actual, ( ( fileSize - actual ) < Globals.blockSize ) ? fileSize : ( block + 1 ) * Globals.blockSize ); + uploader.sendRange( actual, ( ( fileSize - actual ) < Globals.blockSize ) ? fileSize : ( block + 1 ) * Globals.blockSize ); uploader.sendFile( fileName ); } uploader.close(); @@ -186,7 +187,7 @@ public class ConnectionHandler implements IncomingEvent log.debug( "Block " + blockNumber + " was transmitted " + image.getTimesTransmitted( blockNumber ) + " time(s)." ); downloader.setOutputFilename( connections.get( token ).filepath ); - downloader.receiveBinary(); + downloader.readBinary(); } downloader.close(); } diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java b/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java index 68ae95d..1ad921b 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/CrcScheduler.java @@ -11,7 +11,8 @@ import org.openslx.imagemaster.Globals; import org.openslx.imagemaster.crcchecker.CrcChecker; /** - * Class to schedule crc checks. + * Class to schedule CRC checks. + * CRC checks of uploading images are so done parallel to the connection. */ public class CrcScheduler extends TimerTask { @@ -25,6 +26,7 @@ public class CrcScheduler extends TimerTask List<UploadingImage> list = ImageProcessor.getImagesToCheck(); log.debug( list ); Iterator<UploadingImage> iter = list.iterator(); + // iterate over the uploading images that need to be checked while ( iter.hasNext() ) { UploadingImage image = iter.next(); log.debug( "Checking blocks of " + image.getDbImage().imageName ); diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClient.java b/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClient.java index 5754a6b..630096f 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClient.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/DownloadingClient.java @@ -5,18 +5,13 @@ import java.util.List; import java.util.Map; /** - * Helper class for the ImageProcessor to know some things about the downloading client - * + * Helper class for the ImageProcessor and ConnectionHandler to know some things about the downloading client */ public class DownloadingClient { private final HashMap<String, ImageInfos> downloadingImages = new HashMap<>(); - DownloadingClient() - { - } - public void addDownload( String uuid, List<Integer> list, String token ) { downloadingImages.put( uuid, new ImageInfos( uuid, list, token ) ); diff --git a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java index f290bb6..b0b035b 100644 --- a/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java +++ b/src/main/java/org/openslx/imagemaster/serverconnection/UploadingImage.java @@ -10,7 +10,7 @@ import org.openslx.imagemaster.crcchecker.ImageFile; import org.openslx.imagemaster.db.DbImage; /** - * Helper class for ImageProcessor to save some infos about the images in the process list. + * Helper class for ImageProcessor and ConnectionHandler to save some infos about the images in the process list. */ public class UploadingImage { diff --git a/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java b/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java index ccd813e..6ef037c 100644 --- a/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java +++ b/src/main/java/org/openslx/imagemaster/serversession/ServerAuthenticator.java @@ -11,6 +11,9 @@ import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException; import org.openslx.imagemaster.util.AsymMessageVerifier; import org.openslx.imagemaster.util.RandomString; +/** + * Authenticating a server with message signing. + */ public class ServerAuthenticator { diff --git a/src/main/java/org/openslx/imagemaster/serversession/ServerSession.java b/src/main/java/org/openslx/imagemaster/serversession/ServerSession.java index d5e86f2..28b143e 100644 --- a/src/main/java/org/openslx/imagemaster/serversession/ServerSession.java +++ b/src/main/java/org/openslx/imagemaster/serversession/ServerSession.java @@ -4,7 +4,6 @@ import org.openslx.imagemaster.Globals; /** * Holds the session id of the server and manages the timeout. - * */ public class ServerSession { diff --git a/src/main/java/org/openslx/imagemaster/serversession/ServerSessionManager.java b/src/main/java/org/openslx/imagemaster/serversession/ServerSessionManager.java index 47abf0e..49e9ebe 100644 --- a/src/main/java/org/openslx/imagemaster/serversession/ServerSessionManager.java +++ b/src/main/java/org/openslx/imagemaster/serversession/ServerSessionManager.java @@ -11,10 +11,7 @@ import org.openslx.imagemaster.thrift.iface.ServerSessionData; import org.openslx.imagemaster.util.Hash; /** - * Manages all server sessions and kicks timeouted sessions. - * - * @author nils - * + * Manages all server sessions and kicks timed out sessions. */ public class ServerSessionManager { diff --git a/src/main/java/org/openslx/imagemaster/serversession/ServerUser.java b/src/main/java/org/openslx/imagemaster/serversession/ServerUser.java index d3a4d62..3549621 100644 --- a/src/main/java/org/openslx/imagemaster/serversession/ServerUser.java +++ b/src/main/java/org/openslx/imagemaster/serversession/ServerUser.java @@ -1,7 +1,11 @@ package org.openslx.imagemaster.serversession; +/** + * The ServerUser that is hold in a ServerSession + */ public class ServerUser { + public final String organization, address; public ServerUser(String organization, String address) diff --git a/src/main/java/org/openslx/imagemaster/session/Authenticator.java b/src/main/java/org/openslx/imagemaster/session/Authenticator.java index 5f59a85..5d1b728 100644 --- a/src/main/java/org/openslx/imagemaster/session/Authenticator.java +++ b/src/main/java/org/openslx/imagemaster/session/Authenticator.java @@ -7,8 +7,12 @@ import org.openslx.imagemaster.db.LdapUser; import org.openslx.imagemaster.thrift.iface.AuthenticationError; import org.openslx.imagemaster.thrift.iface.AuthenticationException; +/** + * Authenticates a user against a backend (ldap here) + */ public class Authenticator { + private static Logger log = Logger.getLogger( Authenticator.class ); /** @@ -21,29 +25,21 @@ public class Authenticator */ public static User authenticate( String username, String password ) throws AuthenticationException { - // DbUser user = DbUser.forLogin( username ); - // if ( user == null || !Sha512Crypt.verifyPassword( password, user.password ) ) { - // log.debug( "Login failed: " + username ); - // throw new AuthenticationException( AuthenticationError.INVALID_CREDENTIALS, "Invalid username or password!" ); - // } - // log.debug( "Login successful: " + username ); - String login = username; - if (username.split( "@" ).length == 2) { + if ( username.split( "@" ).length == 2 ) { log.info( "username is in username@organization format" ); // we are in username@organization format - // --> get prefix DbSatellite satellite = DbSatellite.fromOrganization( username.split( "@" )[1] ); - if (satellite == null) + if ( satellite == null ) throw new AuthenticationException( AuthenticationError.INVALID_CREDENTIALS, "Unkown Organization." ); login = satellite.getPrefix() + "_" + username.split( "@" )[0]; - } else if (username.split( "_" ).length != 2) { + } else if ( username.split( "_" ).length != 2 ) { log.info( "username is not in a valid format." ); - throw new AuthenticationException(AuthenticationError.INVALID_CREDENTIALS, "Credentials must be in (username@organization) or (prefix@username)"); + throw new AuthenticationException( AuthenticationError.INVALID_CREDENTIALS, "Credentials must be in (username@organization) or (prefix@username)" ); } log.info( "Logging in with: " + login ); - + LdapUser user = LdapUser.forLogin( login, password ); // throws exception if credentials are invalid if ( user == null ) { log.debug( "Login failed: " + username ); diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java index df7cea4..595c059 100644 --- a/src/main/java/org/openslx/imagemaster/util/Util.java +++ b/src/main/java/org/openslx/imagemaster/util/Util.java @@ -5,6 +5,9 @@ import java.util.Random; import org.apache.log4j.Logger; +/** + * Some utilities to make our lives easier. + */ public class Util { |