You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Yves PIEL <yp...@gmail.com> on 2017/08/22 20:16:57 UTC
NTLM Authentication
Hello,
I want to connect on MS CRM OData services. Currently we have only NTLM
authentication and I can connect with it on soap web services with axis2.
With Olingo I have a 401 unauthorized. Here is how I try to connect :
--------------------------------------------------------------------------
public final static void main(String[] args) {
try {
ODataClient client = ODataClientFactory.getClient();
ODataServiceDocumentRequest req =
client.getRetrieveRequestFactory().getServiceDocumentRequest(Resources.SERVICEROOT);
String host = Resources.HOST;
//String host = InetAddress.getLocalHost().getHostName();
NTLMAuthHttpClientFactory ntlm = new
NTLMAuthHttpClientFactory(Resources.USERNAME, Resources.PASSWORD, host,
Resources.DOMAIN);
client.getConfiguration().setHttpClientFactory(ntlm);
ODataRetrieveResponse<ClientServiceDocument> res = req.execute();
} catch (Exception e) {
e.printStackTrace();
}
}.
--------------------------------------------------------------------------
Here is the console output:
--------------------------------------------------------------------------
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
org.apache.olingo.client.api.communication.ODataClientErrorException: (401)
Unauthorized [HTTP/1.1 401 Unauthorized]
at
org.apache.olingo.client.core.communication.header.ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:75)
at
org.apache.olingo.client.core.communication.request.AbstractRequest.checkResponse(AbstractRequest.java:54)
at
org.apache.olingo.client.core.communication.request.AbstractODataRequest.doExecute(AbstractODataRequest.java:310)
at
org.apache.olingo.client.core.communication.request.retrieve.ODataServiceDocumentRequestImpl.execute(ODataServiceDocumentRequestImpl.java:57)
at
org.apache.olingo.client.core.communication.request.retrieve.ODataServiceDocumentRequestImpl.execute(ODataServiceDocumentRequestImpl.java:37)
at
org.talend.training.mscrm20216.OData.MSCrm2016OData.main(MSCrm2016OData.java:47)
--------------------------------------------------------------------------
When I look at network frames with Wireshark, there is only one HTTP
request with the 401 response/Type 1 negotiation trame, but client doesn't
send the next request with credentials.
What am I missing on authentication ?
Best regards,
Yves
Re: NTLM Authentication
Posted by Yves PIEL <yp...@gmail.com>.
In fact I was defining ntlm after after the call so that why I had 401...
^__^
The correct way :
---------------------------------------
ODataClient client = ODataClientFactory.getClient();
NTLMAuthHttpClientFactory ntlm = new
NTLMAuthHttpClientFactory(Resources.USERNAME,
Resources.PASSWORD, Resources.HOST, Resources.DOMAIN);
client.getConfiguration().setHttpClientFactory(ntlm);
ODataServiceDocumentRequest req = client.
getRetrieveRequestFactory().getServiceDocumentRequest(
Resources.SERVICEROOT);
---------------------------------------
2017-08-22 22:16 GMT+02:00 Yves PIEL <yp...@gmail.com>:
> Hello,
>
> I want to connect on MS CRM OData services. Currently we have only NTLM
> authentication and I can connect with it on soap web services with axis2.
>
> With Olingo I have a 401 unauthorized. Here is how I try to connect :
> --------------------------------------------------------------------------
> public final static void main(String[] args) {
> try {
> ODataClient client = ODataClientFactory.getClient();
> ODataServiceDocumentRequest req = client.
> getRetrieveRequestFactory().getServiceDocumentRequest(
> Resources.SERVICEROOT);
>
> String host = Resources.HOST;
> //String host = InetAddress.getLocalHost().getHostName();
>
> NTLMAuthHttpClientFactory ntlm = new NTLMAuthHttpClientFactory(Resources.USERNAME,
> Resources.PASSWORD, host, Resources.DOMAIN);
> client.getConfiguration().setHttpClientFactory(ntlm);
>
> ODataRetrieveResponse<ClientServiceDocument> res = req.execute();
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> }.
> --------------------------------------------------------------------------
>
> Here is the console output:
> --------------------------------------------------------------------------
> SLF4J: Defaulting to no-operation (NOP) logger implementation
> SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
> details.
> org.apache.olingo.client.api.communication.ODataClientErrorException:
> (401) Unauthorized [HTTP/1.1 401 Unauthorized]
> at org.apache.olingo.client.core.communication.header.
> ODataErrorResponseChecker.checkResponse(ODataErrorResponseChecker.java:75)
> at org.apache.olingo.client.core.communication.request.
> AbstractRequest.checkResponse(AbstractRequest.java:54)
> at org.apache.olingo.client.core.communication.request.
> AbstractODataRequest.doExecute(AbstractODataRequest.java:310)
> at org.apache.olingo.client.core.communication.request.retrieve.
> ODataServiceDocumentRequestImpl.execute(ODataServiceDocumentRequestImp
> l.java:57)
> at org.apache.olingo.client.core.communication.request.retrieve.
> ODataServiceDocumentRequestImpl.execute(ODataServiceDocumentRequestImp
> l.java:37)
> at org.talend.training.mscrm20216.OData.MSCrm2016OData.main(
> MSCrm2016OData.java:47)
> --------------------------------------------------------------------------
>
> When I look at network frames with Wireshark, there is only one HTTP
> request with the 401 response/Type 1 negotiation trame, but client doesn't
> send the next request with credentials.
>
> What am I missing on authentication ?
>
> Best regards,
> Yves
>