forked from 2pm.tech/traqtor
[Closes #3] Crypto added to core
parent
f06d2ebcb8
commit
50cf58da9a
@ -0,0 +1,13 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13-alpine
|
||||
volumes:
|
||||
- ../postgres/:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale=en_US.UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --lc-messages=en_US.UTF-8 --lc-monetary=en_US.UTF-8 --lc-numeric=en_US.UTF-8 --lc-time=en_US.UTF-8
|
||||
- POSTGRES_USER=traqtor
|
||||
- POSTGRES_PASSWORD=traqtor
|
||||
ports:
|
||||
- 10240:5432
|
||||
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
CURRENT_UID=$(id -u):$(id -g) docker-compose -f ./.dev/docker/dev-env.yml -p traqtor --compatibility up
|
||||
@ -1,53 +1,69 @@
|
||||
package two.pm.traqtor;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.apache.cayenne.ObjectContext;
|
||||
import org.apache.cayenne.configuration.Constants;
|
||||
import org.apache.cayenne.configuration.server.ServerRuntime;
|
||||
import org.apache.cayenne.crypto.CryptoModule;
|
||||
import org.apache.cayenne.di.Key;
|
||||
import org.apache.cayenne.log.JdbcEventLogger;
|
||||
import org.apache.cayenne.log.NoopJdbcEventLogger;
|
||||
import org.apache.cayenne.query.SQLExec;
|
||||
import org.apache.cayenne.resource.ResourceLocator;
|
||||
|
||||
@ApplicationScoped
|
||||
public class CayenneRuntimeFactory {
|
||||
|
||||
private static ServerRuntime runtime;
|
||||
|
||||
@Singleton
|
||||
public ServerRuntime cayenneRuntime() {
|
||||
if (runtime == null) {
|
||||
runtime = ServerRuntime.builder().addConfig("db/cayenne-traqtor.xml")
|
||||
.addModule(binder -> binder.bind(JdbcEventLogger.class).to(NoopJdbcEventLogger.class))
|
||||
.addModule(binder -> {
|
||||
binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocatorFix.class);
|
||||
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR))
|
||||
.to(ClassLoaderResourceLocatorFix.class);
|
||||
}).build();
|
||||
|
||||
ObjectContext context = runtime.newContext();
|
||||
SQLExec.query(
|
||||
"CREATE TABLE IF NOT EXISTS user (email VARCHAR(36) NULL, id VARBINARY(36) NOT NULL, PRIMARY KEY (id));")
|
||||
.execute(context);
|
||||
SQLExec.query(
|
||||
"CREATE SEQUENCE IF NOT EXISTS pk_user START WITH -9223372036854775808 INCREMENT BY 20 CACHE 1;")
|
||||
.execute(context);
|
||||
context.commitChanges();
|
||||
}
|
||||
private static ServerRuntime runtime;
|
||||
|
||||
@Singleton
|
||||
public ServerRuntime cayenneRuntime() {
|
||||
if (runtime == null) {
|
||||
|
||||
// ClassLoader classLoader = ;
|
||||
// File file = new File(classLoader.getFile());
|
||||
// System.out.println(file.getAbsolutePath());
|
||||
|
||||
return runtime;
|
||||
// return
|
||||
// ServerRuntime.builder().dataSource(dataSource).addConfig("db/cayenne-test.xml").addModule(binder
|
||||
// -> {
|
||||
// //
|
||||
// binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocatorFix.class);
|
||||
// // binder.bind(Key.get(ResourceLocator.class,
|
||||
// Constants.SERVER_RESOURCE_LOCATOR))
|
||||
// // .to(ClassLoaderResourceLocatorFix.class);
|
||||
// }).build();
|
||||
}
|
||||
runtime = ServerRuntime.builder().addConfig("db/cayenne-traqtor.xml")
|
||||
// .addModule(binder ->
|
||||
// binder.bind(JdbcEventLogger.class).to(NoopJdbcEventLogger.class))
|
||||
.addModule(binder -> {
|
||||
binder.bind(ResourceLocator.class)
|
||||
.to(ClassLoaderResourceLocatorFix.class);
|
||||
binder.bind(Key.get(ResourceLocator.class,
|
||||
Constants.SERVER_RESOURCE_LOCATOR))
|
||||
.to(ClassLoaderResourceLocatorFix.class);
|
||||
})
|
||||
.addModule(CryptoModule.extend()
|
||||
.keyStore(this.getClass().getClassLoader()
|
||||
.getResource("db/traqtor.keystore"),
|
||||
"secret".toCharArray(), "key0")
|
||||
.compress()
|
||||
// .useHMAC()
|
||||
.module())
|
||||
.build();
|
||||
|
||||
ObjectContext context = runtime.newContext();
|
||||
|
||||
SQLExec.query("CREATE TABLE IF NOT EXISTS system_user (id bigint NOT NULL, CRYPTO_password varchar(2048) NOT NULL, CRYPTO_email varchar(2048) NOT NULL, PRIMARY KEY (id));"
|
||||
+ "CREATE SEQUENCE IF NOT EXISTS pk_system_user INCREMENT 20 MINVALUE -9223372036854775807;")
|
||||
.execute(context);
|
||||
context.commitChanges();
|
||||
}
|
||||
return runtime;
|
||||
// return
|
||||
// ServerRuntime.builder().dataSource(dataSource).addConfig("db/cayenne-test.xml").addModule(binder
|
||||
// -> {
|
||||
// //
|
||||
// binder.bind(ResourceLocator.class).to(ClassLoaderResourceLocatorFix.class);
|
||||
// // binder.bind(Key.get(ResourceLocator.class,
|
||||
// Constants.SERVER_RESOURCE_LOCATOR))
|
||||
// // .to(ClassLoaderResourceLocatorFix.class);
|
||||
// }).build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,45 +1,12 @@
|
||||
package two.pm.traqtor;
|
||||
|
||||
import io.quarkus.runtime.annotations.QuarkusMain;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cayenne.ObjectContext;
|
||||
import org.apache.cayenne.configuration.server.ServerRuntime;
|
||||
import org.apache.cayenne.log.JdbcEventLogger;
|
||||
import org.apache.cayenne.log.NoopJdbcEventLogger;
|
||||
import org.apache.cayenne.query.SQLExec;
|
||||
import io.quarkus.runtime.Quarkus;
|
||||
|
||||
@QuarkusMain
|
||||
public class TraQtor {
|
||||
// public static ServerRuntime cayenneRuntime;
|
||||
|
||||
public static void main(String... args) {
|
||||
// if (cayenneRuntime == null) {
|
||||
|
||||
// .performInTransaction(() -> {
|
||||
// // ... do some changes
|
||||
// context.commitChanges();
|
||||
|
||||
// // ... do more changes
|
||||
// context.commitChanges();
|
||||
|
||||
// return true;
|
||||
// });
|
||||
|
||||
// Module cryptoExtensions = CryptoModule.extend()
|
||||
// .keyStore("file:///mykeystore", "keystorepassword".toCharArray(), "keyalias")
|
||||
// .compress()
|
||||
// .module();
|
||||
|
||||
// cayenneRuntime =
|
||||
// ServerRuntime.builder().addConfig("cayenne/cayenne-traqtor.xml")
|
||||
// .addModule(binder ->
|
||||
// binder.bind(JdbcEventLogger.class).to(NoopJdbcEventLogger.class)).build();
|
||||
|
||||
// }
|
||||
|
||||
System.out.println("Running main method");
|
||||
Quarkus.run(args);
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package two.pm.traqtor.db;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.cayenne.Cayenne;
|
||||
|
||||
import two.pm.traqtor.db.auto._SystemUser;
|
||||
|
||||
public class SystemUser extends _SystemUser {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public DTO dto() {
|
||||
return new DTO(Cayenne.longPKForObject(this), email, password);
|
||||
}
|
||||
|
||||
public final class DTO {
|
||||
|
||||
public String email;
|
||||
public String password;
|
||||
public String id;
|
||||
|
||||
public DTO(long id, String email, String password) {
|
||||
this.id = Long.toHexString(id);
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package two.pm.traqtor.db;
|
||||
|
||||
import two.pm.traqtor.db.auto._User;
|
||||
|
||||
public class User extends _User {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static class DTO {
|
||||
|
||||
public String email;
|
||||
public String id;
|
||||
|
||||
public DTO(String id, String email) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<graphs xmlns="http://cayenne.apache.org/schema/10/graph">
|
||||
<graph type="ER" scale="1.0">
|
||||
<entity name="user" x="23.0" y="20.0" width="35.0" height="62.0"/>
|
||||
<entity name="system_user" x="23.0" y="20.0" width="115.0" height="77.0"/>
|
||||
</graph>
|
||||
</graphs>
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue