Skip to content

Instantly share code, notes, and snippets.

View trexinc's full-sized avatar

Alex Yaroslavsky trexinc

  • Cato Networks
  • Tel Aviv
View GitHub Profile
@Slf4j
@SpringBootApplication
public class Application implements ApplicationRunner, Runnable, ExitCodeGenerator {
private final SomeAppLogic someAppLogic;
private final Thread mainThread;
private int exitCode = 0;
public static void main(String[] args) {
System.exit(SpringApplication.exit(SpringApplication.run(Application.class, args)));
@trexinc
trexinc / build.gradle
Created July 13, 2020 16:00
bootRun with profile config
//Override profile when running locally
bootRun {
environment SPRING_PROFILES_ACTIVE: environment.SPRING_PROFILES_ACTIVE ?: "local"
}
@trexinc
trexinc / application.properties
Created July 13, 2020 15:44
Profile configurations for local, password and okta
#access open to all pages
spring.profiles.active=local
#require password for /admin
spring.profiles.active=password
spring.security.user.name=<user>
spring.security.user.password=<password>
#require Okta login for /admin
#in Okta dashboard, the web app login redirect URI must be set to (can be localhost if needed):
@trexinc
trexinc / WebSecurityConfig.java
Created July 13, 2020 15:40
Multiple spring web security configs
@Configuration
class WebSecurityConfig {
@Profile("local")
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@EnableWebSecurity
public static class SecurityDisabledConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// allow all requests
@trexinc
trexinc / application.properties
Created July 13, 2020 15:30
Spring Okta config
spring.security.oauth2.client.registration.okta.client-id=<client>
spring.security.oauth2.client.registration.okta.client-secret=<client-secret>
spring.security.oauth2.client.provider.okta.issuer-uri=https://<your-company>.okta.com/oauth2/default
@trexinc
trexinc / SecurityOktaConfig.java
Created July 13, 2020 15:14
Spring WebSecurity example for Okta
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@EnableWebSecurity
public class SecurityOktaConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
// require authenticated access to all resources
.anyRequest().authenticated()
// set logout URL
.and().logout().logoutSuccessUrl("/")
@trexinc
trexinc / DockerComposeContainerWithEnv.java
Created March 21, 2020 02:08
Example of passing environment variables to compose using DockerComposeContainer
private static final String PULSAR = "pulsar://pulsar:6650";
new DockerComposeContainer(new File("docker-compose/consumer.docker-compose.yml"))
.withEnv("PULSAR_NETWORK", pulsarNetworkName)
.withEnv("PULSAR", PULSAR)
.waitingFor("main-consumer_1", Wait.forLogMessage(".*Consumer started.*", 1))
.start();
@trexinc
trexinc / better-other.docker-compose.yml
Created March 21, 2020 02:01
All redefining external network name through an environment variable
version: '3'
services:
some-service:
image: openjdk:8-jre-alpine
networks:
- pulsar-net
networks:
pulsar-net:
external:
name: $PULSAR_NETWORK
@trexinc
trexinc / GetNetworkName.java
Last active March 21, 2020 12:56
Get defined networks from a DockerComposeContainer object
ContainerState cs = (ContainerState)pulsarEnv.getContainerByServiceName("pulsar_1").get();
Map<String, ContainerNetwork> cns = cs.getCurrentContainerInfo().getNetworkSettings().getNetworks();
// We know that the compose file defines exactly one network, so get its name
String pulsarNetworkName = cns.keySet().iterator().next();
@trexinc
trexinc / StartPulsar.java
Last active March 21, 2020 01:22
Example code of starting and waiting for loading of a compose file with TestContainers
import org.testcontainers.containers.DockerComposeContainer
final int PULSAR_ADMIN_PORT = 8080;
final int PULSAR_DATA_PORT = 6650;
new DockerComposeContainer("pulsar", new File("docker-compose/pulsar.docker-compose.yml"))
.withExposedService("pulsar_1", PULSAR_ADMIN_PORT,
Wait.forHttp("/metrics").forStatusCode(200).forPort(PULSAR_ADMIN_PORT))
.withExposedService("pulsar_1", PULSAR_DATA_PORT, Wait.forListeningPort())
.start();