Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Thomas Darimont thomasdarimont

🏠
Working from home
View GitHub Profile
@thomasdarimont
thomasdarimont / haproxy-servers.cfg
Created Jun 16, 2021 — forked from rduplain/haproxy-servers.cfg
Rewrite haproxy configuration and reload service.
View haproxy-servers.cfg
# Edit this file then run `update-haproxy haproxy-servers.cfg`.
# Alternatively, use a shell pipeline to build server list `... | update-haproxy`.
server demo1 127.0.0.1:8001 check cookie demo1 weight 100
server demo2 127.0.0.1:8002 check cookie demo2 weight 100
server demo3 127.0.0.1:8003 check cookie demo3 weight 0
server demo4 127.0.0.1:8004 check cookie demo3 weight 0
@thomasdarimont
thomasdarimont / readme.md
Last active May 30, 2021
Run an Embedded Keycloak Server with JBang
View readme.md

The example uses the embedded Spring Boot Keycloak Server to quickly spin up a new Keycloak instance.

Create JBang script with

jbang init spring-keycloak-server

Adapt spring-keycloak-server script.

Run the Keycloak server via:

@thomasdarimont
thomasdarimont / README-fail2ban-keycloak.md
Created May 18, 2021 — forked from drmalex07/README-fail2ban-keycloak.md
Use fail2ban to block brute-force attacks to keycloak server. #keycloak #fail2ban #brute-force-attack
View README-fail2ban-keycloak.md

Add regular-expression filter under /etc/fail2ban/filter.d/keycloak.conf:

[INCLUDES]

before = common.conf

[Definition]

_threadName = [a-z][-_0-9a-z]*(\s[a-z][-_0-9a-z]*)*
_userId = (null|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})
@thomasdarimont
thomasdarimont / OnceDemo.java
Created Apr 29, 2021
Java experiment for an golang like "sync.Once" primitive
View OnceDemo.java
package demo.once;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.invoke.MutableCallSite;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Supplier;
@thomasdarimont
thomasdarimont / ModuleFileAccessExample.java
Created Apr 29, 2021
Example for reading the modules file in $JAVA_HOME/lib/modules
View ModuleFileAccessExample.java
package wb.java17;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
View readme.md
alias kcadm="docker run --net=host -i --user=1000:1000 --rm -v $(echo $HOME)/.acme/.keycloak:/opt/jboss/.keycloak:z --entrypoint /opt/jboss/keycloak/bin/kcadm.sh jboss/keycloak:12.0.4"
@thomasdarimont
thomasdarimont / readme.md
Created Apr 28, 2021
Keycloak-Snippet get current access token
View readme.md
    ```java
    KeycloakSession session = ResteasyProviderFactory.getContextData(KeycloakSession.class);
    AuthenticationManager.AuthResult authResult = new AppAuthManager.BearerTokenAuthenticator(session).authenticate();
    AccessToken token = authResult.getToken();
    ```
@thomasdarimont
thomasdarimont / MainMethodFinder.java
Last active Apr 15, 2021
MainMethodFinder is a simple CLI Tool to find runnable main Methods in JDK Libraries.
View MainMethodFinder.java
package wb.java17;
import jdk.internal.org.objectweb.asm.ClassReader;
import jdk.internal.org.objectweb.asm.ClassVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
@thomasdarimont
thomasdarimont / index.html
Created Apr 13, 2021
html custom progress-bar example
View index.html
<html>
<head>
<style>
.progress {
width: 100px;
background-color: gray;
text-align: right;
}
.progress-bar {