Skip to content
Open
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
33 changes: 4 additions & 29 deletions src/main/java/com/xebialabs/overthere/winrm/WinRmClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private static String getUUID() {

private Document sendRequest(final Document requestDocument, final SoapAction soapAction) {
if (enableKerberos) {
return runPrivileged(new PrivilegedSendMessage(requestDocument, soapAction));
return runPrivileged(requestDocument, soapAction);
} else {
return doSendRequest(requestDocument, soapAction);
}
Expand All @@ -351,46 +351,21 @@ private Document sendRequest(final Document requestDocument, final SoapAction so
/**
* Performs the JAAS login and run the sendRequest method within a privileged scope.
*/
private Document runPrivileged(final PrivilegedSendMessage privilegedSendMessage) {
private Document runPrivileged(final Document requestDocument, final SoapAction soapAction) {
final CallbackHandler handler = new ProvidedAuthCallback(username, password);
Document result;
try {
final LoginContext lc = new LoginContext("", null, handler, new KerberosJaasConfiguration(kerberosDebug, kerberosTicketCache));
lc.login();

result = Subject.doAs(lc.getSubject(), privilegedSendMessage);
result = Subject.callAs(lc.getSubject(), () -> doSendRequest(requestDocument, soapAction));
} catch (LoginException e) {
throw new WinRmRuntimeIOException("Login failure sending message on " + targetURL + " error: " + e.getMessage(),
privilegedSendMessage.getRequestDocument(), null, e);
} catch (PrivilegedActionException e) {
throw new WinRmRuntimeIOException("Failure sending message on " + targetURL + " error: " + e.getMessage(),
privilegedSendMessage.getRequestDocument(), null, e.getException());
requestDocument, null, e);
}
return result;
}

/**
* PrivilegedExceptionAction that wraps the internal sendRequest
*/
private class PrivilegedSendMessage implements PrivilegedExceptionAction<Document> {
private Document requestDocument;
private SoapAction soapAction;

private PrivilegedSendMessage(final Document requestDocument, final SoapAction soapAction) {
this.requestDocument = requestDocument;
this.soapAction = soapAction;
}

@Override
public Document run() throws Exception {
return WinRmClient.this.doSendRequest(requestDocument, soapAction);
}

public Document getRequestDocument() {
return requestDocument;
}
}

/**
* Internal sendRequest, performs the HTTP request and returns the result document.
*/
Expand Down