cloudsoft / winrm4j

Apache License 2.0
93 stars 55 forks source link

Authorization Loop Detected #73

Open ravirajamiyer opened 7 years ago

ravirajamiyer commented 7 years ago

I tried a simple WinRM client example using the code as follows, and unable to execute the command successfully due to Exception.

Here is the code I am using, with the IP address and credentials masked for security reasons. Any idea what could be wrong in this simple code. Thanks ` public class WinRMClient {

public static void main(String [] args) {
    WinRmClientContext context = WinRmClientContext.newInstance();

    WinRmTool.Builder builder = WinRmTool.Builder.builder("10.101.**.**", "Administrator", "****");
    builder.setAuthenticationScheme(AuthSchemes.NTLM);
    builder.port(5985);
    builder.useHttps(false);
    builder.context(context);
    WinRmTool tool =  builder.build();

    tool.executePs("echo hi");

    context.shutdown();
}

} `

Here is the exception I am seeing:

12:52:26.136 [main] WARN org.apache.cxf.phase.PhaseInterceptorChain - Interceptor for {http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd}WinRmService#{http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd}Create has thrown exception, unwinding now org.apache.cxf.interceptor.Fault: Could not send Message. at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:514) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:423) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:324) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:277) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:139) at com.sun.proxy.$Proxy45.create(Unknown Source) at io.cloudsoft.winrm4j.client.WinRmClient$4.call(WinRmClient.java:779) at io.cloudsoft.winrm4j.client.WinRmClient$4.call(WinRmClient.java:774) at io.cloudsoft.winrm4j.client.WinRmClient.winrmCallRetryConnFailure(WinRmClient.java:871) at io.cloudsoft.winrm4j.client.WinRmClient.doCreateService_3_InitializeClientAndService(WinRmClient.java:774) at io.cloudsoft.winrm4j.client.WinRmClient.doCreateServiceWithBean(WinRmClient.java:612) at io.cloudsoft.winrm4j.client.WinRmClient.createService(WinRmClient.java:518) at io.cloudsoft.winrm4j.client.WinRmClient.getService(WinRmClient.java:502) at io.cloudsoft.winrm4j.client.WinRmClient.command(WinRmClient.java:316) at io.cloudsoft.winrm4j.winrm.WinRmTool.executeCommand(WinRmTool.java:243) at io.cloudsoft.winrm4j.winrm.WinRmTool.executePs(WinRmTool.java:258) at com.***.windows.WinRMClient.main(WinRMClient.java:20) Caused by: java.io.IOException: Authorization loop detected on Conduit "{http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd}WinRmPort.http-conduit" on URL "http://10.***.**.**:5985/wsman" with realm "null" at org.apache.cxf.transport.http.HTTPConduit.detectAuthorizationLoop(HTTPConduit.java:1937) at org.apache.cxf.transport.http.HTTPConduit.access$600(HTTPConduit.java:149) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.authorizationRetransmit(HTTPConduit.java:1515) at org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream.authorizationRetransmit(AsyncHTTPConduit.java:800) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.processRetransmit(HTTPConduit.java:1446) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleRetransmits(HTTPConduit.java:1420) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1554) at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1356) at org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit$AsyncWrappedOutputStream.close(AsyncHTTPConduit.java:415) at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:653) at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) ... 19 common frames omitted 1

neykov commented 7 years ago

Hi @ravirajamiyer. It means that authentication failed - either your credentials are not valid or the server is misconfigured. There's an open issue on this - https://github.com/cloudsoft/winrm4j/issues/55. See some tips for troubleshooting this here

DarkEden commented 6 years ago

Hi, I'be the same issue with this client configuration : Client NetworkDelayms = 5000 URLPrefix = wsman AllowUnencrypted = true Auth Basic = true Digest = true Kerberos = true Negotiate = true Certificate = false CredSSP = false DefaultPorts HTTP = 5985 HTTPS = 5986 TrustedHosts = *

I can connect with this powershell command : Enter-PSSession -ComputerName 10.129.134.233 -Credential Administrator and after enter my password but not with WinRM4J.

Can you help me ?

nbahramzad commented 5 years ago

I just got done dealing with the same issue. In my case, I needed to prefix the <AD Domain>\<username> or <local username> with a ./ and that solved my problem.