summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2015-09-10 15:14:45 +0200
committerSimon Rettberg2015-09-10 15:14:45 +0200
commitfb7fd15b7a140a3bb983f75bc5d6deed708ef579 (patch)
treea0b6fd549f18416693d66efd8ead5ea580aba853 /src
parentStuff (diff)
downloadmasterserver-fb7fd15b7a140a3bb983f75bc5d6deed708ef579.tar.gz
masterserver-fb7fd15b7a140a3bb983f75bc5d6deed708ef579.tar.xz
masterserver-fb7fd15b7a140a3bb983f75bc5d6deed708ef579.zip
Fixes (backwards compat)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/imagemaster/db/mappers/DbPendingSatellite.java2
-rw-r--r--src/main/java/org/openslx/imagemaster/db/mappers/DbSatellite.java7
-rw-r--r--src/main/java/org/openslx/imagemaster/db/mappers/DbUser.java35
-rw-r--r--src/main/java/org/openslx/imagemaster/db/models/LocalUser.java4
-rw-r--r--src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java7
-rw-r--r--src/main/java/org/openslx/imagemaster/session/Authenticator.java9
-rw-r--r--src/main/java/org/openslx/imagemaster/util/Util.java16
7 files changed, 37 insertions, 43 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/mappers/DbPendingSatellite.java b/src/main/java/org/openslx/imagemaster/db/mappers/DbPendingSatellite.java
index 906d49e..472d249 100644
--- a/src/main/java/org/openslx/imagemaster/db/mappers/DbPendingSatellite.java
+++ b/src/main/java/org/openslx/imagemaster/db/mappers/DbPendingSatellite.java
@@ -19,7 +19,7 @@ public class DbPendingSatellite
throws SQLException
{
try ( MysqlConnection connection = Database.getConnection() ) {
- MysqlStatement stmt = connection.prepareStatement( "INSERT INTO pending_satellite"
+ MysqlStatement stmt = connection.prepareStatement( "INSERT INTO satellite"
+ " (dateline, userid, organizationid, satellitename, addresses, publickey)"
+ " VALUES (UNIX_TIMESTAMP(), :userid, :organizationid, :satellitename, :addresses, :pubkey)", true );
stmt.setString( "userid", user.userId );
diff --git a/src/main/java/org/openslx/imagemaster/db/mappers/DbSatellite.java b/src/main/java/org/openslx/imagemaster/db/mappers/DbSatellite.java
index 811ac67..2f72436 100644
--- a/src/main/java/org/openslx/imagemaster/db/mappers/DbSatellite.java
+++ b/src/main/java/org/openslx/imagemaster/db/mappers/DbSatellite.java
@@ -45,7 +45,12 @@ public class DbSatellite
List<Satellite> list = new ArrayList<>();
while ( rs.next() ) {
List<String> al = Arrays.asList( Json.deserialize( rs.getString( "addresses" ), String[].class ) );
- list.add( new Satellite( al, rs.getString( "satellitename" ), ByteBuffer.wrap( rs.getBytes( "certsha256" ) ) ) );
+ byte[] certBytes = rs.getBytes( "certsha256" );
+ ByteBuffer cert = null;
+ if ( certBytes != null ) {
+ cert = ByteBuffer.wrap( certBytes );
+ }
+ list.add( new Satellite( al, rs.getString( "satellitename" ), cert ) );
}
return list;
} catch ( SQLException e ) {
diff --git a/src/main/java/org/openslx/imagemaster/db/mappers/DbUser.java b/src/main/java/org/openslx/imagemaster/db/mappers/DbUser.java
index 349b023..9cde273 100644
--- a/src/main/java/org/openslx/imagemaster/db/mappers/DbUser.java
+++ b/src/main/java/org/openslx/imagemaster/db/mappers/DbUser.java
@@ -24,13 +24,12 @@ public class DbUser
private static final Logger LOGGER = Logger.getLogger( DbUser.class );
private static final String localUserSql = "SELECT"
- + " user.userid, user.login, user.password, user.organizationid, user.firstname, user.lastname, user.email,"
- + " organization.address FROM user"
- + " LEFT JOIN organization USING (organizationid)";
+ + " user.userid, user.password, user.organizationid, user.firstname, user.lastname, user.email"
+ + " FROM user";
private static LocalUser localFromRs( ResultSet rs ) throws SQLException
{
- return new LocalUser( rs.getInt( "userid" ), rs.getString( "login" ), rs.getString( "password" ),
+ return new LocalUser( rs.getString( "userid" ), rs.getString( "password" ),
rs.getString( "organizationid" ), rs.getString( "firstname" ), rs.getString( "lastname" ), rs.getString( "email" ),
Role.TUTOR );
}
@@ -47,8 +46,8 @@ public class DbUser
{
try ( MysqlConnection connection = Database.getConnection() ) {
MysqlStatement stmt = connection.prepareStatement( localUserSql
- + " WHERE user.login = :login" );
- stmt.setString( "login", login );
+ + " WHERE user.userid = :userid" );
+ stmt.setString( "userid", login );
ResultSet rs = stmt.executeQuery();
if ( !rs.next() )
return null;
@@ -67,30 +66,6 @@ public class DbUser
return user.toUserInfo();
}
- /**
- * Query database for user with given userId
- *
- * @param userid
- * @return instance of DbUser for matching entry from DB, or null if not
- * found
- * @throws SQLException
- */
- public static LocalUser forLogin( final int userId ) throws SQLException
- {
- try ( MysqlConnection connection = Database.getConnection() ) {
- MysqlStatement stmt = connection.prepareStatement( localUserSql
- + " WHERE user.userid = :userid" );
- stmt.setInt( "userid", userId );
- ResultSet rs = stmt.executeQuery();
- if ( !rs.next() )
- return null;
- return localFromRs( rs );
- } catch ( SQLException e ) {
- LOGGER.error( "Query failed in DbUser.forLogin()", e );
- throw e;
- }
- }
-
public static LocalUser forLogin( String login, String password ) throws SQLException
{
LocalUser user = forLogin( login );
diff --git a/src/main/java/org/openslx/imagemaster/db/models/LocalUser.java b/src/main/java/org/openslx/imagemaster/db/models/LocalUser.java
index 4e0d4fb..644373b 100644
--- a/src/main/java/org/openslx/imagemaster/db/models/LocalUser.java
+++ b/src/main/java/org/openslx/imagemaster/db/models/LocalUser.java
@@ -15,12 +15,10 @@ public class LocalUser
public final String firstName, lastName;
public final String eMail;
public final Role role;
- public final int userId;
- public LocalUser( int userId, String login, String password, String organizationId, String firstName, String lastName, String eMail,
+ public LocalUser( String login, String password, String organizationId, String firstName, String lastName, String eMail,
Role tutor )
{
- this.userId = userId;
this.login = login;
this.organizationId = organizationId;
this.password = password;
diff --git a/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java b/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java
index 2504a3d..6b2769b 100644
--- a/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java
+++ b/src/main/java/org/openslx/imagemaster/localrpc/JsonUser.java
@@ -1,5 +1,6 @@
package org.openslx.imagemaster.localrpc;
+import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.Role;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.util.Util;
@@ -7,6 +8,8 @@ import org.openslx.imagemaster.util.Util;
public class JsonUser
{
+ private static final Logger LOGGER = Logger.getLogger( JsonUser.class );
+
private String userId = null;
private String organizationId = null;
private String firstName = null;
@@ -20,9 +23,11 @@ public class JsonUser
try {
role = Role.valueOf( this.role );
} catch ( Exception e ) {
+ LOGGER.warn( "Invalid role: " + this.role );
return null;
}
- if ( Util.isEmpty( userId ) || Util.isEmpty( organizationId ) || Util.isEmpty( lastName ) || Util.isEmpty( mail ) )
+ if ( Util.isEmpty( userId, "userId", LOGGER ) || Util.isEmpty( organizationId, "orgId", LOGGER )
+ || Util.isEmpty( lastName, "lastName", LOGGER ) || Util.isEmpty( mail, "mail", LOGGER ) )
return null;
UserInfo ui = new UserInfo( userId, firstName, lastName, mail, organizationId );
ui.role = role;
diff --git a/src/main/java/org/openslx/imagemaster/session/Authenticator.java b/src/main/java/org/openslx/imagemaster/session/Authenticator.java
index 91f3127..ea7e581 100644
--- a/src/main/java/org/openslx/imagemaster/session/Authenticator.java
+++ b/src/main/java/org/openslx/imagemaster/session/Authenticator.java
@@ -4,7 +4,9 @@ import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.AuthorizationError;
+import org.openslx.bwlp.thrift.iface.InvocationError;
import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.TInvocationException;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.db.mappers.DbUser;
import org.openslx.imagemaster.db.models.LocalUser;
@@ -23,9 +25,10 @@ public class Authenticator
* @param username
* @param password
* @return
+ * @throws TInvocationException
* @throws TAuthenticationException
*/
- public static UserInfo authenticate( String username, String password ) throws TAuthorizationException
+ public static UserInfo authenticate( String username, String password ) throws TAuthorizationException, TInvocationException
{
String login = username;
@@ -35,11 +38,11 @@ public class Authenticator
try {
user = DbUser.forLogin( login, password );
} catch ( SQLException e ) {
- user = null;
+ throw new TInvocationException( InvocationError.INTERNAL_SERVER_ERROR, "Could not connect to database" );
} // throws exception if credentials are invalid
if ( user == null ) {
log.debug( "Login failed: " + username );
- throw new TAuthorizationException( AuthorizationError.GENERIC_ERROR, "Something went wrong." );
+ throw new TAuthorizationException( AuthorizationError.INVALID_CREDENTIALS, "Invalid Username or password" );
}
log.debug( "Login succesful: " + username );
diff --git a/src/main/java/org/openslx/imagemaster/util/Util.java b/src/main/java/org/openslx/imagemaster/util/Util.java
index 79589c4..e9146e0 100644
--- a/src/main/java/org/openslx/imagemaster/util/Util.java
+++ b/src/main/java/org/openslx/imagemaster/util/Util.java
@@ -16,7 +16,7 @@ import org.apache.log4j.Logger;
public class Util
{
- private static Logger log = Logger.getLogger( Util.class );
+ private static Logger LOGGER = Logger.getLogger( Util.class );
/**
* Check if the given object is null, abort program if true.
@@ -35,7 +35,7 @@ public class Util
{
if ( something == null ) {
if ( message != null )
- log.fatal( "[NOTNULL] " + message, new NullPointerException() );
+ LOGGER.fatal( "[NOTNULL] " + message, new NullPointerException() );
System.exit( 2 );
}
}
@@ -57,7 +57,7 @@ public class Util
{
if ( number == 0 ) {
if ( message != null )
- log.fatal( "[NOTNULL] " + message, new NullPointerException() );
+ LOGGER.fatal( "[NOTNULL] " + message, new NullPointerException() );
System.exit( 2 );
}
}
@@ -75,7 +75,7 @@ public class Util
{
if ( something == null || something.isEmpty() ) {
if ( message != null )
- log.fatal( "[NOTNULL] " + message, new NullPointerException() );
+ LOGGER.fatal( "[NOTNULL] " + message, new NullPointerException() );
System.exit( 2 );
}
}
@@ -123,6 +123,14 @@ public class Util
return str != null && !str.isEmpty();
}
+ public static boolean isEmpty( String str, String message, Logger logger )
+ {
+ if ( str != null && !str.isEmpty() )
+ return false;
+ logger.debug( message );
+ return true;
+ }
+
/**
* Tries to parse an int. Returns 0 on error.
*