From 397af7dbf782e39809b78074699c3a125412e62f Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 2 Oct 2014 18:50:15 +0200 Subject: Implement API methods getPublicImages, getOrganizations --- .../org/openslx/imagemaster/server/ApiServer.java | 29 +++++++++++----------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/openslx/imagemaster/server/ApiServer.java') diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java index 6c5413f..aaad0db 100644 --- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java +++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java @@ -3,7 +3,6 @@ package org.openslx.imagemaster.server; import java.nio.ByteBuffer; import java.util.List; -import org.apache.thrift.TException; import org.openslx.imagemaster.db.DbImage; import org.openslx.imagemaster.db.DbSatellite; import org.openslx.imagemaster.serverconnection.ImageProcessor; @@ -25,8 +24,6 @@ import org.openslx.imagemaster.thrift.iface.ImageDataError; import org.openslx.imagemaster.thrift.iface.ImageDataException; import org.openslx.imagemaster.thrift.iface.InvalidTokenException; import org.openslx.imagemaster.thrift.iface.OrganizationData; -import org.openslx.imagemaster.thrift.iface.ServerAuthenticationError; -import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException; import org.openslx.imagemaster.thrift.iface.ServerSessionData; import org.openslx.imagemaster.thrift.iface.SessionData; import org.openslx.imagemaster.thrift.iface.UploadData; @@ -121,16 +118,16 @@ public class ApiServer * @throws ServerAuthenticationException when organization is invalid/unknown */ public static ByteBuffer startServerAuthentication( String organizationId ) - throws ServerAuthenticationException + throws AuthenticationException { if ( organizationId == null || organizationId.isEmpty() ) - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization" ); + throw new AuthenticationException( AuthenticationError.INVALID_ORGANIZATION, "Empty organization" ); DbSatellite satellite = DbSatellite.fromOrganizationId( organizationId ); if ( satellite == null ) - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization: '" + organizationId + "'" ); + throw new AuthenticationException( AuthenticationError.INVALID_ORGANIZATION, "Unknown organization: '" + organizationId + "'" ); if ( satellite.getPubkey() == null ) - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); + throw new AuthenticationException( AuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); return ServerAuthenticator.startServerAuthentication( organizationId ); } @@ -141,20 +138,18 @@ public class ApiServer * @param challengeResponse the encrypted string * @return session data iff the authentication was successful * @throws AuthenticationException - * @throws TException */ public static ServerSessionData serverAuthenticate( String organizationId, - ByteBuffer challengeResponse ) throws ServerAuthenticationException, - TException + ByteBuffer challengeResponse ) throws AuthenticationException { if ( organizationId == null || challengeResponse == null ) { - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization or challengeResponse" ); + throw new AuthenticationException( AuthenticationError.INVALID_ORGANIZATION, "Empty organization or challengeResponse" ); } DbSatellite satellite = DbSatellite.fromOrganizationId( organizationId ); if ( satellite == null ) - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); + throw new AuthenticationException( AuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); if ( satellite.getPubkey() == null ) - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); + throw new AuthenticationException( AuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); final ServerUser serverUser = ServerAuthenticator.serverAuthenticate( satellite, challengeResponse ); @@ -181,7 +176,11 @@ public class ApiServer public static List getOrganizations() { - // TODO Auto-generated method stub - return null; + return DbSatellite.asOrganizationDataList(); + } + + public static List getPublicImages( String sessionId, int page ) + { + return DbImage.asImageDataList( page * 100, ( page + 1 ) * 100 ); } } -- cgit v1.2.3-55-g7522