Skip to content

Instantly share code, notes, and snippets.

@beargiles
beargiles / BasicKdcTest.java
Last active May 14, 2018
JAAS with Kerberos; Unit Test using Apache Hadoop Mini-KDC.
View BasicKdcTest.java
import java.io.File;
import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
View DnsBlockingSecurityManager.java
package com.invariantproperties.sandbox.securityManager;
import java.net.InetSocketAddress;
import java.net.SocketPermission;
import java.security.Permission;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@beargiles
beargiles / AdvancedTestCase.java
Created Aug 3, 2015
How to add database logging to JUnit3 TestCase.
View AdvancedTestCase.java
public class AdvancedTestCase extends TestCase {
public void run(TestResult result) {
AdvancedTestListener l = AdvancedTestListenerFactory.INSTANCE.newInstance();
result.addListener(l);
l.setName(getName());
// normally do this with reflection
MyTestedClass orig = ((MyAdvancedTest) this).obj;
MyFacadeClass facade = new MyFacadeClass(orig);
View ProtectedSecret.java
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
@beargiles
beargiles / H2withBrowser.java
Last active Apr 16, 2019
Create an embedded H2 instance and launch related web console.
View H2withBrowser.java
/**
* Simple code to create an embedded H2 server and launch associated web console.
*/
import java.sql.*;
import org.h2.jdbcx.JdbcConnectionPool;
import org.h2.tools.Server;
private static final String URL = "jdbc:h2:~/test;AUTO_SERVER=TRUE";
private static final String USERNAME = "sa";
private static final String PASSWORD = "";
You can’t perform that action at this time.