diff options
author | Simon Rettberg | 2014-10-15 20:39:03 +0200 |
---|---|---|
committer | Simon Rettberg | 2014-10-15 20:39:03 +0200 |
commit | 1b653f8f1210254ad71949ebc52ed7500951e92a (patch) | |
tree | c6bc8fcddbcd65f84eb00f1956be71dad0effcba | |
parent | Implement registerSatellite RPC (diff) | |
download | masterserver-1b653f8f1210254ad71949ebc52ed7500951e92a.tar.gz masterserver-1b653f8f1210254ad71949ebc52ed7500951e92a.tar.xz masterserver-1b653f8f1210254ad71949ebc52ed7500951e92a.zip |
Implement suffixList for getOrganizations, added stub for updateSatelliteAddress
4 files changed, 58 insertions, 5 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java index 4d70bef..f882977 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java +++ b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; +import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; @@ -18,10 +19,11 @@ public class DbSatellite { private static final Logger LOG = Logger.getLogger( DbSatellite.class ); - private String organizationId, address, name, publickeyString; + private String organizationId, address, name, publickeyString, authMethod; private PublicKey publickey = null; + private List<String> suffixList = null; - public DbSatellite( String organizationId, String address, String name, String publickeyString ) + public DbSatellite( String organizationId, String address, String name, String authMethod, String publickeyString ) { this.organizationId = organizationId; this.address = address; @@ -34,7 +36,7 @@ public class DbSatellite return MySQL .findUniqueOrNull( DbSatellite.class, - "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.publickey FROM satellite WHERE satellite.organizationid = ? LIMIT 1", + "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.authmethod, satellite.publickey FROM satellite WHERE satellite.organizationid = ? LIMIT 1", organizationId ); } @@ -43,7 +45,7 @@ public class DbSatellite return MySQL .findUniqueOrNull( DbSatellite.class, - "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.publickey FROM satellite" + "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.authmethod, satellite.publickey FROM satellite" + " INNER JOIN satellite_suffix USING (organizationid)" + " WHERE satellite_suffix.suffix = ? LIMIT 1", suffix ); @@ -57,7 +59,14 @@ public class DbSatellite */ public static List<OrganizationData> asOrganizationDataList() { - return MySQL.findAll( OrganizationData.class, "SELECT satellite.organizationid, satellite.name, satellite.authmethod FROM satellite" ); + List<DbSatellite> sats = MySQL.findAll( + DbSatellite.class, + "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.authmethod, satellite.publickey FROM satellite" ); + List<OrganizationData> orgData = new ArrayList<>(); + for ( DbSatellite sat : sats ) { + orgData.add( new OrganizationData( sat.getOrganizationId(), sat.getName(), sat.getAuthenticationMethod(), sat.getSuffixList() ) ); + } + return orgData; } public static DbSatellite fromPrefix( String prefix ) @@ -84,6 +93,18 @@ public class DbSatellite return organizationId; } + public String getAuthenticationMethod() + { + return authMethod; + } + + public List<String> getSuffixList() + { + if ( this.suffixList == null ) + this.suffixList = DbSatelliteSuffix.forSatellite( this ); + return this.suffixList; + } + /** * Get the public key of this organization, if known and valid. * diff --git a/src/main/java/org/openslx/imagemaster/db/DbSatelliteSuffix.java b/src/main/java/org/openslx/imagemaster/db/DbSatelliteSuffix.java new file mode 100644 index 0000000..a22d694 --- /dev/null +++ b/src/main/java/org/openslx/imagemaster/db/DbSatelliteSuffix.java @@ -0,0 +1,18 @@ +package org.openslx.imagemaster.db; + +import java.util.List; + +public class DbSatelliteSuffix +{ + + public static List<String> forOrganization( String organizationId ) + { + return MySQL.findAll( String.class, "SELECT satellite_suffix.suffix FROM satellite_suffix WHERE organizationid = ?", organizationId ); + } + + public static List<String> forSatellite( DbSatellite satellite ) + { + return forOrganization( satellite.getOrganizationId() ); + } + +} diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java index 0927e16..e265045 100644 --- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java +++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java @@ -233,4 +233,12 @@ public class ApiServer } return DbPendingSatellite.add( organizationId, address, modulus, exponent ); } + + public static boolean updateSatelliteAddress( String serverSessionId, String address ) throws AuthorizationException + { + if ( ServerSessionManager.getSession( serverSessionId ) == null ) + throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessionId" ); + // TODO: Implement + return false; + } } 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 2ef66c5..fbe6d6b 100644 --- a/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java +++ b/src/main/java/org/openslx/imagemaster/thrift/server/ImageServerHandler.java @@ -105,4 +105,10 @@ public class ImageServerHandler implements ImageServer.Iface { return ApiServer.registerSatellite( organizationId, address, modulus, exponent ); } + + @Override + public boolean updateSatelliteAddress( String serverSessionId, String address ) throws TException + { + return ApiServer.updateSatelliteAddress( serverSessionId, address ); + } } |