diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/server/ApiServer.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/server/ApiServer.java | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java index ce20020..b39a517 100644 --- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java +++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java @@ -119,15 +119,17 @@ public class ApiServer * key of the requesting satellite server * @throws ServerAuthenticationException when organization is invalid/unknown */ - public static String startServerAuthentication( String organization ) + public static ByteBuffer startServerAuthentication( String organization ) throws ServerAuthenticationException { - if ( organization == null || organization.isEmpty() ) { + if ( organization == null || organization.isEmpty() ) throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization" ); - } - if ( DbSatellite.fromOrganization( organization ) == null ) { - throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); - } + + DbSatellite satellite = DbSatellite.fromOrganization( organization ); + if ( satellite == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization: '" + organization + "'" ); + if ( satellite.getPubkey() == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); return ServerAuthenticator.startServerAuthentication( organization ); } @@ -148,11 +150,12 @@ public class ApiServer throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Empty organization or challengeResponse" ); } DbSatellite satellite = DbSatellite.fromOrganization( organization ); - if ( satellite == null ) { + if ( satellite == null ) throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_ORGANIZATION, "Unknown organization" ); - } - final ServerUser serverUser = ServerAuthenticator.serverAuthenticate( - organization, satellite.getAddress(), challengeResponse ); + if ( satellite.getPubkey() == null ) + throw new ServerAuthenticationException( ServerAuthenticationError.INVALID_KEY, "There is no public key known for your organization." ); + + final ServerUser serverUser = ServerAuthenticator.serverAuthenticate( satellite, challengeResponse ); final ServerSession session = new ServerSession( serverUser ); return ServerSessionManager.addSession( session ); |