Подключение к конечной точке NTLM - PullRequest
1 голос
/ 27 мая 2019
import java.util.ArrayList;
import java.util.List;

import javax.swing.plaf.synth.SynthSeparatorUI;
import javax.xml.namespace.QName;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.httpclient.auth.AuthPolicy;

import com.custom.ntlm.CustomNTLMAuthScheme;


public class TestNTLMAxis {

       public static void main(String[] args) {
             // TODO Auto-generated method stub
             System.out.println("Start of test.");

             String serviceURL = "xxxx";
             String endpointReference = null;

             AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, CustomNTLMAuthScheme.class);

             Options options = new Options();
        options.setTo(new EndpointReference(serviceURL));
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.AUTHENTICATE,Constants.VALUE_TRUE);

        List<String> authSchema = new ArrayList();
        authSchema.add(HttpTransportProperties.Authenticator.NTLM);        
        HttpTransportProperties.Authenticator ntlmAuthentication = new HttpTransportProperties.Authenticator();
        ntlmAuthentication.setAuthSchemes(authSchema);
        ntlmAuthentication.setUsername("xxxxxx");
        ntlmAuthentication.setPassword("xxxxxxx");
        ntlmAuthentication.setHost("xxx.xxx.xxx.xxx");
        ntlmAuthentication.setDomain("mydoamin");   
        ntlmAuthentication.setAllowedRetry(true);

        options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, ntlmAuthentication);
        options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_POST);

        try {

             ServiceClient sender = new ServiceClient();
            sender.engageModule(Constants.MODULE_ADDRESSING);             


            sender.setOptions(options);

            sender.cleanupTransport();

            OMElement result = sender.sendReceive(getPayload());


            XMLStreamWriter writer = XMLOutputFactory.newInstance()
                    .createXMLStreamWriter(System.out);
            result.serialize(writer);
            writer.flush();
        } catch (XMLStreamException e) {
            e.printStackTrace();
        } catch (FactoryConfigurationError e) {
            e.printStackTrace();
        } catch (Exception e) {
             e.printStackTrace();
        }  // I am getting a 415 unsupported media type

Я пытаюсь подключиться к конечной точке, защищенной с помощью аутентификации в активном каталоге, я использую посредник CustomNtlm, предложенный в блоге Nipuna, и получаю 401 несанкционированный, я выполнил все шаги в сообщении блога, упомянутом выше. Может ли кто-нибудь помочь мне.

Я пробовал код, указанный в блоге Нипуны. Я пытаюсь отправить сообщение json и ожидаю ответное сообщение json.

https://medium.com/@nipunadilhara/ntlm-authentication-for-wso2-esb-v6-2-0-9584c3e6713

 <class name="com.custom.ntlm.NTLMMediator">
    <property name="username" value="username"/>
    <property name="host" value="xxx.xxx.xxx.xxx"/>
    <property name="ntlmVersion" value="v2"/>
    <property name="domain" value="mydomain"/>
    <property name="password" value="xxxxxxxx"/>
</class>
<log level="full"/>
<class name="com.custom.ntlm.NTLMCalloutMediator">
    <property name="serviceURL" value="http://myhostname:myhostport"/>
    <property name="initAxis2ClientOptions" value="false"/>
</class>
<log level="full"/>
<header action="remove" name="To" scope="default"/>
<log level="full"/>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<send/>

 <class name="com.custom.ntlm.NTLMMediator">
    <property name="username" value="username"/>
    <property name="host" value="xxx.xxx.xxx.xxx"/>
    <property name="ntlmVersion" value="v2"/>
    <property name="domain" value="mydomain"/>
    <property name="password" value="xxxxxxxx"/>
</class>
<log level="full"/>
<class name="com.custom.ntlm.NTLMCalloutMediator">
    <property name="serviceURL" value="http://myhostname:myhostport"/>
    <property name="initAxis2ClientOptions" value="false"/>
</class>
<log level="full"/>
<header action="remove" name="To" scope="default"/>
<log level="full"/>
<property name="RESPONSE" scope="default" type="STRING" value="true"/>
<property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
<send/>

Проволочные бревна

  [2019-05-29 09:15:05,963] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "POST /solar/management/documentmanagement/savedocument HTTP/1.1[\r][\n]"
[2019-05-29 09:15:05,969] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: application/json[\r][\n]"
[2019-05-29 09:15:05,979] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "User-Agent: PostmanRuntime/7.13.0[\r][\n]"
[2019-05-29 09:15:05,980] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept: */*[\r][\n]"
[2019-05-29 09:15:05,981] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Cache-Control: no-cache[\r][\n]"
[2019-05-29 09:15:05,987] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Postman-Token: 03b5e8d9-06ab-4eae-98f4-c22085974d8e[\r][\n]"
[2019-05-29 09:15:05,995] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Host: 172.16.221.96:8280[\r][\n]"
[2019-05-29 09:15:06,000] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "accept-encoding: gzip, deflate[\r][\n]"
[2019-05-29 09:15:06,002] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "content-length: 532[\r][\n]"
[2019-05-29 09:15:06,007] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Connection: keep-alive[\r][\n]"
[2019-05-29 09:15:06,010] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[\r][\n]"
[2019-05-29 09:15:06,015] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "{[\n]"
[2019-05-29 09:15:06,020] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "systemName": "Main",[\n]"
[2019-05-29 09:15:06,021] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "authenticatedAdDomain": "domain",[\n]"
[2019-05-29 09:15:06,022] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "authenticatedAdUser": "johns",[\n]"
[2019-05-29 09:15:06,029] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "parentNodeName": "LEGISLATION",[\n]"
[2019-05-29 09:15:06,031] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "childNodeName": "Policy",[\n]"
[2019-05-29 09:15:06,036] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "fileMetaData": {[\n]"
[2019-05-29 09:15:06,037] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Document Title": "MyDocument",[\n]"
[2019-05-29 09:15:06,038] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Document Date": "2019-04-18 14:04:00.000",[\n]"
[2019-05-29 09:15:06,046] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Ref No": "REF000054-12",[\n]"
[2019-05-29 09:15:06,048] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Document Author": "John Smith",[\n]"
[2019-05-29 09:15:06,053] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Category": "50",[\n]"
[2019-05-29 09:15:06,053] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "        "Type": "Type1"[\n]"
[2019-05-29 09:15:06,054] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    },[\n]"
[2019-05-29 09:15:06,056] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "fileName": "TestResults.pdf",[\n]"
[2019-05-29 09:15:06,065] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "fileType": "Adobe Pdf",[\n]"
[2019-05-29 09:15:06,069] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "    "fileContent": "VGhpcyBpcyBmaWxlIGNvbnRlbnQ="[\n]"
[2019-05-29 09:15:06,070] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "}"
[2019-05-29 09:15:06,071] [] DEBUG - headers http-incoming-6 >> POST /solar/management/documentmanagement/savedocument HTTP/1.1
[2019-05-29 09:15:06,072] [] DEBUG - headers http-incoming-6 >> Content-Type: application/json
[2019-05-29 09:15:06,080] [] DEBUG - headers http-incoming-6 >> User-Agent: PostmanRuntime/7.13.0
[2019-05-29 09:15:06,082] [] DEBUG - headers http-incoming-6 >> Accept: */*
[2019-05-29 09:15:06,087] [] DEBUG - headers http-incoming-6 >> Cache-Control: no-cache
[2019-05-29 09:15:06,088] [] DEBUG - headers http-incoming-6 >> Postman-Token: 03b5e8d9-06ab-4eae-98f4-c22085974d8e
[2019-05-29 09:15:06,090] [] DEBUG - headers http-incoming-6 >> Host: 172.16.221.96:8280
[2019-05-29 09:15:06,099] [] DEBUG - headers http-incoming-6 >> accept-encoding: gzip, deflate
[2019-05-29 09:15:06,104] [] DEBUG - headers http-incoming-6 >> content-length: 532
[2019-05-29 09:15:06,105] [] DEBUG - headers http-incoming-6 >> Connection: keep-alive
[2019-05-29 09:15:06,252] [] DEBUG - NTLMMediator [NTLMMediator] mediate method Invoked.
[2019-05-29 09:15:06,255] [] DEBUG - NTLMMediator [NTLMMediator] NTLM version is: v2
[2019-05-29 09:15:06,278] []  INFO - LogMediator To: /solar/management/documentmanagement/savedocument, MessageID: urn:uuid:77031c2d-3b97-41fe-916e-f4784cad389e, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><userCode>johns</userCode></jsonObject></soapenv:Body></soapenv:Envelope>
[2019-05-29 09:15:06,294] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] mediate method Invoked.
[2019-05-29 09:15:06,298] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] Message : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><userCode>johns</userCode></jsonObject></soapenv:Body></soapenv:Envelope>
[2019-05-29 09:15:06,304] []  INFO - NTLMCalloutMediator Inside Mediator initClientoption : false
[2019-05-29 09:15:06,310] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] About to invoke service : http://192.168.12.98:8081/api/HTTPORBSY110Api
[2019-05-29 09:15:06,322] [] DEBUG - NTLMCalloutMediator [NTLMCalloutMediator] Request message payload : <jsonObject><userCode>johns</userCode></jsonObject>
[2019-05-29 09:15:06,342] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] processChallenge Invoked.
[2019-05-29 09:15:06,345] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] NTLM Scheme Authentication Method Invoked.
[2019-05-29 09:15:06,352] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] The NTLM version going to use is: v2
[2019-05-29 09:15:06,359] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type1Message Generated.
[2019-05-29 09:15:06,369] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] processChallenge Invoked.
[2019-05-29 09:15:06,371] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] NTLM Scheme Authentication Method Invoked.
[2019-05-29 09:15:06,372] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] The NTLM version going to use is: v2
[2019-05-29 09:15:06,373] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type2Message Received.
[2019-05-29 09:15:06,381] [] DEBUG - CustomNTLMAuthScheme [CustomNTLMAuthScheme] Type3Message Generated.
[2019-05-29 09:15:06,724] [] DEBUG - headers http-incoming-6 << HTTP/1.1 202 Accepted
[2019-05-29 09:15:06,725] [] DEBUG - headers http-incoming-6 << Date: Wed, 29 May 2019 07:15:06 GMT
[2019-05-29 09:15:06,730] [] DEBUG - headers http-incoming-6 << Transfer-Encoding: chunked
[2019-05-29 09:15:06,732] [] DEBUG - headers http-incoming-6 << Connection: keep-alive
[2019-05-29 09:15:06,738] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "HTTP/1.1 202 Accepted[\r][\n]"
[2019-05-29 09:15:06,745] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Date: Wed, 29 May 2019 07:15:06 GMT[\r][\n]"
[2019-05-29 09:15:06,747] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Transfer-Encoding: chunked[\r][\n]"
[2019-05-29 09:15:06,752] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "Connection: keep-alive[\r][\n]"
[2019-05-29 09:15:06,754] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
[2019-05-29 09:15:06,765] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "0[\r][\n]"
[2019-05-29 09:15:06,768] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 << "[\r][\n]"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...