Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Debug sysErrDebug = new PrintStreamDebug(System.err);
provider.setDebug(sysErrDebug);
```

or use java.util.logging:

```java
provider.setDebug(new LoggingDebug(DEBUG, debugLogger));
```

And you can add your own logging framework by extending `AbstractDebug`:

```java
Expand Down
1 change: 1 addition & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {
`java-library`
`maven-publish` // https://docs.gradle.org/current/userguide/publishing_maven.html
signing
id("com.diffplug.spotless") version "7.0.0.BETA4"
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
* This is an abstract class that provides helpful defaults for most of the Debug interface.
*
* There's three methods you have to implement, but the key/trust manager is taken care of for you.
*/
public abstract class AbstractDebug implements Debug {

public abstract void enter(String message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
package com.tersesystems.debugjsse;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLContextSpi;
import javax.net.ssl.TrustManagerFactory;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;

public class DebugJSSEProvider extends Provider {

private static String defaultKeyManagerAlgorithm;
private static String defaultTrustManagerAlgorithm;

public final static String NAME = "debugJSSE";
public final static Double VERSION = 1.0;
public final static String INFO = "Debug JSSE";

private static final String SSL_KEY_MANAGER_FACTORY_SECPROP = "ssl.KeyManagerFactory.algorithm";
private static final String SSL_TRUST_MANAGER_FACTORY_SECPROP = "ssl.TrustManagerFactory.algorithm";
private static final String KEY_MANAGER_FACTORY = "KeyManagerFactory";
private static final String TRUST_MANAGER_FACTORY = "TrustManagerFactory";
private static final String KEY_MANAGER_FACTORY = "KeyManagerFactory";
private static final String TRUST_MANAGER_FACTORY = "TrustManagerFactory";

private static boolean enabled = false;

Expand Down
33 changes: 33 additions & 0 deletions lib/src/main/java/com/tersesystems/debugjsse/LoggingDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.tersesystems.debugjsse;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This is a class that logs to the given logger at the given log level.
*/
public class LoggingDebug extends AbstractDebug {

private final Logger logger;
private final Level level;

public LoggingDebug(Level level, Logger logger) {
this.level = level;
this.logger = logger;
}

@Override
public void enter(String message) {
logger.log(level, message);
}

@Override
public void exit(String message) {
logger.log(level, message);
}

@Override
public void exception(String message, Exception e) {
logger.log(level, message);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.tersesystems.debugjsse;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
import java.io.PrintStream;

/**
* This is a class that prints to a PrintStream on debug output.
*/
public class PrintStreamDebug extends AbstractDebug {

private final PrintStream stream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.tersesystems.debugjsse;

/**
* This class writes to System.out for debugging output.
*/
public class SystemOutDebug extends PrintStreamDebug {
public SystemOutDebug() {
super(System.out);
Expand Down
Loading