Nullpointer in play.db.ebean.DefaultEbeanConfig

java
configuration

#1

'm looking for a solution to encrypt my Database of the Play-Application. The App uses already Ebean.io. I saw that I can encrypt the Database with the Solution of Ebean. There for I configure the application.conf

ebean {
 default = ["models.*"]
 encryptKeyManager = models.BasicEncryptKeyManager
}

After this step I implemented a own ServerStartup like this:

public class CustomServerConfigStartup implements ServerConfigStartup {

    @Override
    public void onStart(ServerConfig serverConfig) {
        serverConfig.setEncryptKeyManager(new BasicEncryptKeyManager());
    }
}

class BasicEncryptKeyManager implements EncryptKeyManager {

    @Override
    public EncryptKey getEncryptKey(String tableName, String columnName) {
        return new CustomEncryptKey(tableName, columnName);
    }

    @Override
    public void initialise() {
        //Do nothing (yet)
    }

}

class CustomEncryptKey implements EncryptKey {

    private String tableName;

    private String columnName;

    public CustomEncryptKey(String tableName, String columnName) {
        this.tableName = tableName;
        this.columnName = columnName;
    }

    @Override
    public String getStringValue() {
        return play.Configuration.root().getString("play.http.secret.key") + "::" + this.tableName + "::" + this.columnName;
    }
}

I annoted all values of the entities with @Encrypted.

@Entity
public class Settings extends Model {
    @Id
    public Long id;
    @Encrypted
    public String title;
}

I thought the Exception is the Reason of Ebean so I created a post in the GoogleGroup of Ebean https://groups.google.com/forum/?hl=de#!topic/ebean/7wD1pZIhu8U. But they said this Exception is a Play-Exception so now I’m here.

Is there any Solution to encrypt the Database with Ebean or some other technologies?


(Jörg Bergner) #2

Are there any news? - We have exactly the same problem!


(Marcos Pereira) #3

Hi @jonasWolff,

So, here is what is happening:

When using play-ebean, it reads the default configuration from ebean.default, but you can declare other Ebean servers like:

ebean.orders = ["models.Order", "models.OrderItem"]

Since you have ebean.encryptKeyManager, with encryptKeyManager as a direct child of ebean, it is being parsed as a Ebean server, but it lacks other configurations and then there is a failure. You can try something like this:

ebean {
  default = ["models.*"]
}

ebean-security {
  encryptKeyManager = models.BasicEncryptKeyManager
}

I’ve just invented ebean-security, it has no relations with play-ebean and so no conflicts are expected.

Best.