1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package org.openslx.imagemaster.db.mappers;
import java.sql.SQLException;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.imagemaster.db.Database;
import org.openslx.imagemaster.db.MysqlConnection;
import org.openslx.imagemaster.db.MysqlStatement;
import org.openslx.util.Json;
import com.google.gson.annotations.SerializedName;
public class DbPendingSatellite
{
private static final Logger LOGGER = LogManager.getLogger( DbPendingSatellite.class );
public static int add( UserInfo user, String displayName, List<String> address, String modulus, String exponent )
throws SQLException
{
try ( MysqlConnection connection = Database.getConnection() ) {
MysqlStatement stmt = connection.prepareStatement( "INSERT INTO satellite"
+ " (dateline, userid, organizationid, satellitename, addresses, publickey)"
+ " VALUES (UNIX_TIMESTAMP(), :userid, :organizationid, :satellitename, :addresses, :pubkey)" );
stmt.setString( "userid", user.userId );
stmt.setString( "organizationid", user.organizationId );
stmt.setString( "satellitename", displayName );
stmt.setString( "addresses", Json.serialize( address ) );
stmt.setString( "pubkey", Json.serialize( new KeyWrapper( modulus, exponent ) ) );
stmt.executeUpdate();
int key = stmt.lastInsertId();
connection.commit();
return key;
} catch ( SQLException e ) {
LOGGER.error( "Query failed in DbPendingSatellite.add()", e );
throw e;
}
}
private static class KeyWrapper
{
@SerializedName( "type" )
public String type;
@SerializedName( "modulus" )
public String modulus;
@SerializedName( "exponent" )
public String exponent;
public KeyWrapper( String modulus, String exponent )
{
this.type = "RSA";
this.modulus = modulus;
this.exponent = exponent;
}
}
}
|