summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-10-08 14:54:52 +0200
committerBjörn Hagemeister2014-10-08 14:54:52 +0200
commit13505318b1d71de2fa599e53d8d113144f4a0dfd (patch)
treed4e7b61b93ad7dd2275932be2a4c25b594c9cca6 /src
parentSupport new API methods, changed DB scheme, updated .sql script (diff)
downloadmasterserver-13505318b1d71de2fa599e53d8d113144f4a0dfd.tar.gz
masterserver-13505318b1d71de2fa599e53d8d113144f4a0dfd.tar.xz
masterserver-13505318b1d71de2fa599e53d8d113144f4a0dfd.zip
Implemented publishUser(sessionId, UserInfo) in ApiServer.
Plus added method for inserting user into user database with given UserInfo.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/imagemaster/db/DbUser.java8
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java14
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java1
3 files changed, 20 insertions, 3 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbUser.java b/src/main/java/org/openslx/imagemaster/db/DbUser.java
index 46c5130..1806f1d 100644
--- a/src/main/java/org/openslx/imagemaster/db/DbUser.java
+++ b/src/main/java/org/openslx/imagemaster/db/DbUser.java
@@ -81,6 +81,14 @@ public class DbUser extends User
user.login, user.password, user.organizationId, user.firstName, user.lastName, user.eMail );
return false;
}
+
+ public static boolean insertOrUpdate(UserInfo userInfo) {
+ log.debug( "Inserted user '" + userInfo.userId + "' into db." );
+ int ret = MySQL.update(
+ "INSERT INTO user (organizationid, firstname, lastname, email) VALUES (?, ?, ?, ?)",
+ userInfo.organizationId, userInfo.firstName, userInfo.lastName, userInfo.eMail );
+ return (ret != 0);
+ }
public static List<UserInfo> findUser( String organizationId, String searchTerm )
{
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index 1323ec6..ada6a21 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -164,10 +164,18 @@ public class ApiServer
return ( ServerSessionManager.getSession( serverSessionId ) != null );
}
- public static boolean publishUser( String serverSessionId, UserInfo user )
+ public static boolean publishUser( String serverSessionId, UserInfo user ) throws AuthorizationException
{
- // TODO
- return false;
+ // Check session.
+ if (SessionManager.getSessionFromSessionId( serverSessionId ) == null) {
+ throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "Session ID not valid" );
+ }
+ if (DbUser.forLogin( user.userId ) == null) {
+ // User not known by server. Insert into server database.
+ return DbUser.insertOrUpdate( user );
+ }
+ // Else user is already known by server. Do nothing.
+ return true;
}
public static List<UserInfo> findUser( String sessionId, String organizationId, String searchTerm ) throws AuthorizationException
diff --git a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
index 3b8ebec..d28c736 100644
--- a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
+++ b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java
@@ -88,6 +88,7 @@ public class ImageServerHandler implements ImageServer.Iface
@Override
public boolean publishUser( String serverSessionId, UserInfo user )
+ throws AuthorizationException
{
return ApiServer.publishUser( serverSessionId, user );
}