Java Code Examples for org.wildfly.swarm.container.Container#PostInitContext

The following examples show how to use org.wildfly.swarm.container.Container#PostInitContext . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EJBFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    SecurityFraction security = (SecurityFraction) initContext.fraction("security");

    if (security != null) {
        SecurityDomain ejbPolicy = security.subresources().securityDomains().stream().filter((e) -> e.getKey().equals("jboss-ejb-policy")).findFirst().orElse(null);
        if (ejbPolicy == null) {
            ejbPolicy = new SecurityDomain("jboss-ejb-policy")
                    .classicAuthorization(new ClassicAuthorization()
                            .policyModule(new PolicyModule("default")
                                    .code("Delegating")
                                    .flag(Flag.REQUIRED)));
            security.securityDomain(ejbPolicy);
        }
    }
}
 
Example 2
Source File: HawkularServerFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    SecurityFraction security = (SecurityFraction) initContext.fraction("security");

    security.securityDomain("keycloak", (domain) -> {
        domain.classicAuthentication((auth) -> {
            auth.loginModule("default", (login) -> {
                login.code("org.keycloak.adapters.jboss.KeycloakLoginModule");
                login.flag(Flag.REQUIRED);
            });
        });
    });

}
 
Example 3
Source File: EEFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    if (initContext.hasFraction("Messaging")) {
        if (this.subresources().defaultBindingsService() == null) {
            this.defaultBindingsService(new DefaultBindingsService());
        }
        this.subresources().defaultBindingsService()
                .jmsConnectionFactory("java:jboss/DefaultJMSConnectionFactory");
    }
}
 
Example 4
Source File: InfinispanFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    if (this.defaultFraction) {
        if (initContext.hasFraction("jgroups")) {
            clusteredDefaultFraction(initContext);
        } else {
            localDefaultFraction(initContext);
        }
    }
}
 
Example 5
Source File: MailFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    for (MailSession session : subresources().mailSessions()) {
        SMTPServer server = session.subresources().smtpServer();
        if (server != null && server instanceof EnhancedSMTPServer) {
            OutboundSocketBinding socketBinding = ((EnhancedSMTPServer) server).outboundSocketBinding();
            if (socketBinding != null) {
                initContext.outboundSocketBinding(socketBinding);
            }
        }
    }
}
 
Example 6
Source File: UndertowFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    if (this.keystorePassword != null & this.keystorePassword != null && this.alias != null) {
        ManagementCoreService management = (ManagementCoreService) initContext.fraction("management");
        if (management == null) {
            throw new RuntimeException("HTTPS configured but org.wildfly.swarm:management not available");
        }

        List<Server> servers = subresources().servers();

        for (Server server : servers) {
            if (server.subresources().httpsListeners().isEmpty()) {
                if (server.subresources().httpListener("default").socketBinding().equals("http")) {
                    server.httpsListener("default-https", (listener) -> {
                        listener.securityRealm("SSLRealm");
                        listener.socketBinding("https");
                    });
                }
            }
        }

        management.securityRealm("SSLRealm", (realm) -> {
            realm.sslServerIdentity((identity) -> {
                identity.keystorePath(this.keystorePath);
                identity.keystorePassword(this.keystorePassword);
                identity.alias(this.alias);
            });
        });
    }
}
 
Example 7
Source File: InfinispanFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
private InfinispanFraction clusteredDefaultFraction(Container.PostInitContext initContext) {
    cacheContainer("server",
            cc -> cc.defaultCache("default")
                    .alias("singleton")
                    .alias("cluster")
                    .jgroupsTransport(t -> t.lockTimeout(60000L))
                    .replicatedCache("default",
                            c -> c.mode(Mode.SYNC)
                                    .transactionComponent(t -> t.mode(TransactionComponent.Mode.BATCH))));
    if (initContext.hasFraction("undertow")) {
        cacheContainer("web",
                cc -> cc.defaultCache("dist")
                        .jgroupsTransport(t -> t.lockTimeout(60000L))
                        .distributedCache("dist",
                                c -> c.mode(Mode.ASYNC)
                                        .l1Lifespan(0L)
                                        .owners(2)
                                        .lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore()));
    }

    if (initContext.hasFraction("ejb")) {
        cacheContainer("ejb",
                cc -> cc.defaultCache("dist")
                        .alias("sfsb")
                        .jgroupsTransport(t -> t.lockTimeout(60000L))
                        .distributedCache("dist",
                                c -> c.mode(Mode.ASYNC)
                                        .l1Lifespan(0L)
                                        .owners(2)
                                        .lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(t -> t.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore()));

    }

    if (initContext.hasFraction("jpa")) {
        cacheContainer("hibernate",
                cc -> cc.defaultCache("local-query")
                        .jgroupsTransport(t -> t.lockTimeout(60000L))
                        .localCache("local-query",
                                c -> c.evictionComponent(ec -> ec.maxEntries(10000L).strategy(EvictionComponent.Strategy.LRU))
                                        .expirationComponent(ec -> ec.maxIdle(100000L)))
                        .invalidationCache("entity",
                                c -> c.mode(Mode.SYNC)
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.NON_XA))
                                        .evictionComponent(ec -> ec.maxEntries(10000L).strategy(EvictionComponent.Strategy.LRU))
                                        .expirationComponent(ec -> ec.maxIdle(100000L)))
                        .replicatedCache("timestamps", c -> c.mode(Mode.ASYNC)));
    }

    return this;
}
 
Example 8
Source File: InfinispanFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
private InfinispanFraction localDefaultFraction(Container.PostInitContext initContext) {
    cacheContainer("server",
            cc -> cc.defaultCache("default")
                    .localCache("default", c -> c.transactionComponent(t -> t.mode(TransactionComponent.Mode.BATCH)))
                    .remoteCommandThreadPool());

    if (initContext.hasFraction("undertow")) {
        cacheContainer("web",
                cc -> cc.defaultCache("passivation")
                        .localCache("passivation",
                                c -> c.lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore(fs -> fs.passivation(true).purge(false)))
                        .localCache("persistent",
                                c -> c.lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore(fs -> fs.passivation(false).purge(false))));
    }

    if (initContext.hasFraction("ejb")) {
        cacheContainer("ejb",
                cc -> cc.alias("sfsb")
                        .defaultCache("passivation")
                        .localCache("passivation",
                                c -> c.lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore(fs -> fs.passivation(true).purge(false)))
                        .localCache("persistent",
                                c -> c.lockingComponent(lc -> lc.isolation(LockingComponent.Isolation.REPEATABLE_READ))
                                        .transactionComponent(tc -> tc.mode(TransactionComponent.Mode.BATCH))
                                        .fileStore(fs -> fs.passivation(false).purge(false))));
    }

    if (initContext.hasFraction("jpa")) {
        cacheContainer("hibernate",
                cc -> cc.defaultCache("local-query")
                        .localCache("entity",
                                c -> c.transactionComponent(t -> t.mode(TransactionComponent.Mode.NON_XA))
                                        .evictionComponent(e -> e.strategy(EvictionComponent.Strategy.LRU).maxEntries(10000L))
                                        .expirationComponent(e -> e.maxIdle(100000L)))
                        .localCache("immutable-entity",
                                c -> c.transactionComponent(t -> t.mode(TransactionComponent.Mode.NON_XA))
                                        .evictionComponent(e -> e.strategy(EvictionComponent.Strategy.LRU).maxEntries(10000L))
                                        .expirationComponent(e -> e.maxIdle(100000L)))
                        .localCache("local-query",
                                c -> c.transactionComponent(t -> t.mode(TransactionComponent.Mode.NON_XA))
                                        .evictionComponent(e -> e.strategy(EvictionComponent.Strategy.LRU).maxEntries(10000L))
                                        .expirationComponent(e -> e.maxIdle(100000L)))
                        .localCache("timestamps"));
    }

    return this;
}
 
Example 9
Source File: KeycloakServerFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {

    if (System.getProperty("jboss.server.config.dir") == null) {
        try {
            //Path dir = Files.createTempDirectory("swarm-keycloak-config");
            File dir = TempFileManager.INSTANCE.newTempDirectory( "swarm-keycloak-config", ".d" );
            System.setProperty("jboss.server.config.dir", dir.getAbsolutePath() );
            Files.copy(getClass().getClassLoader().getResourceAsStream("keycloak-server.json"),
                    dir.toPath().resolve("keycloak-server.json"),
                    StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    InfinispanFraction infinispan = (InfinispanFraction) initContext.fraction("infinispan");

    CacheContainer cache = infinispan.subresources().cacheContainer("keycloak");
    if (cache == null) {
        infinispan.cacheContainer("keycloak", (c) -> c.jndiName("infinispan/Keycloak")
                .localCache("realms")
                .localCache("users")
                .localCache("sessions")
                .localCache("offlineSessions")
                .localCache("loginFailures"));
    }

    DatasourcesFraction datasources = (DatasourcesFraction) initContext.fraction("datasources");

    if (datasources.subresources().dataSource("KeycloakDS") == null) {
        if (datasources.subresources().jdbcDriver("h2") == null) {
            datasources.jdbcDriver("h2", (driver) -> {
                driver.driverModuleName("com.h2database.h2");
                driver.moduleSlot("main");
                driver.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
            });
        }

        datasources.dataSource("KeycloakDS", (ds) -> {
            ds.jndiName("java:jboss/datasources/KeycloakDS");
            ds.useJavaContext(true);
            ds.connectionUrl("jdbc:h2:${wildfly.swarm.keycloak.server.db:./keycloak};AUTO_SERVER=TRUE");
            ds.driverName("h2");
            ds.userName("sa");
            ds.password("sa");
        });
    }
}