Skip to content

Instantly share code, notes, and snippets.

@Component(service=UkelonnDatabase.class, immediate=true)
public class PGUkelonnDatabaseProvider implements UkelonnDatabase {
@Activate
public void activate(Map<String, Object> config) {
createDatasource(config);
try(Connection connect = getConnection()) {
... (create schema and insert initial data)
} catch (Exception e) {
logError("Failed to create ukelonn database schema in the PostgreSQL ukelonn database", e);
@Component(service=UkelonnService.class, immediate=true)
public class UkelonnServiceProvider extends UkelonnServiceBase {
private UkelonnDatabase database;
@Activate
public void activate() {
// Nothing to do here
}
@Reference
@Component(service=UkelonnService.class, immediate=true)
public class UkelonnServiceProvider extends UkelonnServiceBase {
...
@Override
public Account getAccount(String username) {
try(Connection connection = database.getConnection()) {
try(PreparedStatement statement = connection.prepareStatement("select * from accounts_view where username=?")) {
statement.setString(1, username);
try(ResultSet resultset = statement.executeQuery()) {
if (resultset.next())
<feature name="authservice-with-dbrealm-and-session">
<feature>authservice-web-security-dbrealm</feature>
<feature>authservice-web-security-memorysession</feature>
<feature>authservice-users</feature>
<feature>authservice-web-security</feature>
</feature>
<feature name="authservice-user-admin">
<feature>authservice-with-dbrealm-and-session</feature>
<feature>authservice-user-management-frontend</feature>
</feature>
<feature name="authservice-with-derby-dbrealm-and-session">
<feature>authservice-db-derby-test</feature>
<feature>authservice-with-dbrealm-and-session</feature>
</feature>
<feature name="authservice-with-postgresql-dbrealm-and-session">
<feature>authservice-db-postgresql</feature>
<feature>authservice-with-dbrealm-and-session</feature>
</feature>
karaf@root()> feature:repo-add mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
Adding feature url mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
karaf@root()> feature:install authservice-with-derby-dbrealm-and-session
karaf@root()>
karaf@root()> feature:repo-add mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
Adding feature url mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
karaf@root()> feature:install authservice-with-postgresql-dbrealm-and-session
karaf@root()>
karaf@root()> config:edit no.priv.bang.ukelonn.db.postgresql.PGUkelonnDatabaseProvider
karaf@root()> config:property-set ukelonn.db.jdbc.url "jdbc:postgresql:///ukelonn"
karaf@root()> config:property-set ukelonn.db.jdbc.user "karaf"
karaf@root()> config:property-set ukelonn.db.jdbc.password "karaf"
karaf@root()> config:update
karaf@root()>