Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Thomas Darimont thomasdarimont

🏠
Working from home
View GitHub Profile
@thomasdarimont
thomasdarimont / AesCipher.php
Last active Jul 13, 2020
Example for 128bit AES with Java and PHP
View AesCipher.php
<?php
class AesCipher {
private const OPENSSL_CIPHER_NAME = "aes-128-cbc";
private const CIPHER_KEY_LEN = 16; //128 bits
private static function fixKey($key) {
if (strlen($key) < AesCipher::CIPHER_KEY_LEN) {
@thomasdarimont
thomasdarimont / readme.md
Last active Jul 7, 2020
Example for decoding a JWT Payload with your Shell (bash, zsh...)
View readme.md

Setup

Add this to your .profile, .bashrc, .zshrc...

decode_base64_url() {
  local len=$((${#1} % 4))
  local result="$1"
  if [ $len -eq 2 ]; then result="$1"'=='
  elif [ $len -eq 3 ]; then result="$1"'=' 
  fi
  echo "$result" | tr '_-' '/+' | openssl enc -d -base64
@thomasdarimont
thomasdarimont / Main.java
Created Jun 26, 2020
Embedded Keycloak Spring Boot Starter example
View Main.java
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
@SpringBootApplication(exclude = LiquibaseAutoConfiguration.class)
public class Main {
public static void main(String[] args) {
@thomasdarimont
thomasdarimont / DynamicIdpRedirectAuthenticator.java
Last active Jun 22, 2020
DynamicIdpRedirectAuthenticator with configurable fallback
View DynamicIdpRedirectAuthenticator.java
package com.github.thomasdarimont.keycloak.auth.dynamicidp;
import lombok.extern.jbosslog.JBossLog;
import org.keycloak.OAuth2Constants;
import org.keycloak.authentication.AuthenticationFlowContext;
import org.keycloak.authentication.AuthenticationFlowError;
import org.keycloak.authentication.Authenticator;
import org.keycloak.constants.AdapterConstants;
import org.keycloak.events.Errors;
import org.keycloak.models.AuthenticatorConfigModel;
@thomasdarimont
thomasdarimont / ConditionalOtpFormAuthenticator.java
Last active Jun 21, 2020
Keycloak Conditional OTP Step-by-Step
View ConditionalOtpFormAuthenticator.java
package org.keycloak.authentication.authenticators.browser;
import org.keycloak.authentication.AuthenticationFlowContext;
import org.keycloak.models.RoleModel;
import org.keycloak.models.UserModel;
import javax.ws.rs.core.MultivaluedMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@thomasdarimont
thomasdarimont / keycloak_db_overview_4.0.0.CR1-SNAPSHOT.svg
Created Jan 7, 2018
Keycloak Database Overview 4.0.0.CR1-SNAPSHOT (06bb6f00e5)
View keycloak_db_overview_4.0.0.CR1-SNAPSHOT.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View KeycloakAdminClientExample.java
package de.tdlabs.training.keycloak;
import static java.util.Arrays.asList;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.representations.idm.CredentialRepresentation;
@thomasdarimont
thomasdarimont / App.java
Last active Jun 10, 2020
Example for defining a refreshable Groovy Script in Spring Boot with Java Config - at least thats the current state of affairs :)
View App.java
package demo;
import java.util.concurrent.TimeUnit;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@thomasdarimont
thomasdarimont / main.rs
Created Jun 9, 2020
Rust experiments: Calculator
View main.rs
use core::fmt;
use std::io::{self, Write};
#[derive(Debug, Clone, Copy)]
enum BinaryOperator {
ADD,
SUB,
MUL,
DIV,
MOD,
@thomasdarimont
thomasdarimont / RsyncOverSsh_Fast_Documentation.md
Created Nov 12, 2019 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)
View RsyncOverSsh_Fast_Documentation.md

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
You can’t perform that action at this time.