Skip to content

Commit

Permalink
Merge pull request #425 from dmlloyd/ely-474
Browse files Browse the repository at this point in the history
[ELY-474] Minor simplification/cleanup in SASL utility class
  • Loading branch information
dmlloyd committed Apr 29, 2016
2 parents 06f42d2 + e915bcb commit 80f6b2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
Expand Up @@ -18,13 +18,10 @@

package org.wildfly.security.sasl.util;

import java.lang.reflect.UndeclaredThrowableException;
import java.security.PrivilegedActionException;

import javax.security.sasl.SaslClient;
import javax.security.sasl.SaslException;

import org.wildfly.security.ParametricPrivilegedExceptionAction;
import org.wildfly.common.function.ExceptionUnaryOperator;
import org.wildfly.security.auth.client.AuthenticationContext;

/**
Expand All @@ -36,7 +33,7 @@
public final class AuthenticationContextSaslClient extends AbstractDelegatingSaslClient {

private AuthenticationContext context;
private ParametricPrivilegedExceptionAction<byte[], byte[]> challengeAction = delegate::evaluateChallenge;
private ExceptionUnaryOperator<byte[], SaslException> challengeAction = delegate::evaluateChallenge;

/**
* Construct a new instance.
Expand All @@ -60,17 +57,7 @@ public AuthenticationContextSaslClient(final SaslClient delegate) {
}

public byte[] evaluateChallenge(final byte[] challenge) throws SaslException {
try {
return context.run(challenge, challengeAction);
} catch (PrivilegedActionException e) {
try {
throw e.getCause();
} catch (SaslException | RuntimeException | Error rethrow) {
throw rethrow;
} catch (Throwable throwable) {
throw new UndeclaredThrowableException(throwable);
}
}
return context.runExFunction(challengeAction, challenge);
}

public void dispose() throws SaslException {
Expand Down
Expand Up @@ -18,13 +18,10 @@

package org.wildfly.security.sasl.util;

import java.lang.reflect.UndeclaredThrowableException;
import java.security.PrivilegedActionException;

import javax.security.sasl.SaslServer;
import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer;

import org.wildfly.security.ParametricPrivilegedExceptionAction;
import org.wildfly.common.function.ExceptionUnaryOperator;
import org.wildfly.security.auth.client.AuthenticationContext;

/**
Expand All @@ -36,7 +33,7 @@
public final class AuthenticationContextSaslServer extends AbstractDelegatingSaslServer {

private AuthenticationContext context;
private ParametricPrivilegedExceptionAction<byte[], byte[]> responseAction = delegate::evaluateResponse;
private ExceptionUnaryOperator<byte[], SaslException> responseAction = delegate::evaluateResponse;

/**
* Construct a new instance.
Expand All @@ -59,18 +56,8 @@ public AuthenticationContextSaslServer(final SaslServer delegate) {
context = AuthenticationContext.captureCurrent();
}

public byte[] evaluateResponse(final byte[] challenge) throws SaslException {
try {
return context.run(challenge, responseAction);
} catch (PrivilegedActionException e) {
try {
throw e.getCause();
} catch (SaslException | RuntimeException | Error rethrow) {
throw rethrow;
} catch (Throwable throwable) {
throw new UndeclaredThrowableException(throwable);
}
}
public byte[] evaluateResponse(final byte[] response) throws SaslException {
return context.runExFunction(responseAction, response);
}

public void dispose() throws SaslException {
Expand Down

0 comments on commit 80f6b2a

Please sign in to comment.