Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
ramagirinagarjuna
Posts: 6
Registered: ‎11-29-2012
My Device: Blackberry9800
My Carrier: Blackberry

How to overcome Authentication issue in my blackberry application?

Hi,

Im trying to call a webservice which  has NTLM type authentication.I heard that Blackberry does support NTLM authentication with the aid of BES. All we need to do is set Authentication=true in  MDS-CS of BES and from coding part we just need to do BASIC authentication scheme. Is it true?...if it is true, then why  im not able to make the connection.Im sending the credentials along with the Url from my application but im getting 401 response.

The code i have written is

 

murl=http://myrequiredurl.com/

String mparams=username.gettext()+":"+password.gettext();

byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0,login.length(),false, false);

ConnectionFactory connectionFactory = new ConnectionFactory();
  ConnectionDescriptor connDescriptor = (ConnectionDescriptor) connectionFactory.getConnection(mUrl);
  

  if (connDescriptor != null) {
   try {

    connection = (HttpConnection) connDescriptor.getConnection();
    connection.setRequestMethod(HttpConnection.POST);
    connection.setRequestProperty("Content-Type","application/xwww-form-urlencoded");
    //connection.setRequestProperty("Content-Length", String.valueOf(mParams.length));
    connection.setRequestProperty("Authorization", "Basic " + new String(mParams));
    responseCode = connection.getResponseCode();

    }

catch(Exception e){}

 

If this is not the way to make a connection for NTLM authenticated webservices, please help me to do so.

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to overcome Authentication issue in my blackberry application?

I don't really understand the various authentication mechanisms, sorry.

 

But what I do know is that for MDS processing, you can not put the login information into the request until you have been asked for it.  In other words, you should not add this header:

connection.setRequestProperty("Authorization", "Basic " + new String(mParams));

until you have actually had a 401.

 

There is something in the BES processing where it tries to cache something.  Mark Sohm explained it once on a Thread here - if you search you might find it.

 

Anyway, have a look at this KB article which demonstrates one way to retry the connection after you get a 401.

http://supportforums.blackberry.com/t5/Java-Development/Implement-basic-HTTP-authentication/ta-p/445...

Please use plain text.
Developer
simon_hain
Posts: 15,956
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to overcome Authentication issue in my blackberry application?

if you want to use ntlm you should not use basic auth, you should use that only after a 401 as a fallback.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
ramagirinagarjuna
Posts: 6
Registered: ‎11-29-2012
My Device: Blackberry9800
My Carrier: Blackberry

Re: How to overcome Authentication issue in my blackberry application?

Yes i have did in the same way which you had told. Even now im getting the response code as 401. My doubt is that, is it the correct way to append username : password  for NTLM authentication ? we write this syntax(username : password)  for BASIC autnetication scheme. will this method even work for NTLM?..please simon help me in this issue

Please use plain text.
New Contributor
ramagirinagarjuna
Posts: 6
Registered: ‎11-29-2012
My Device: Blackberry9800
My Carrier: Blackberry

Re: How to overcome Authentication issue in my blackberry application?

Hi peter,

I have tried doing the same way as it was in the example provided by you. But of no use, Please help me in making an HttpConnection with server authentication model as NTLM. The example you provided was of BASIC authentication.

Please use plain text.
Developer
simon_hain
Posts: 15,956
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to overcome Authentication issue in my blackberry application?

you do not add username/password for ntlm, the bb smartphone does not support it.

the MDS supports it, so you can use it only with an enterprise activated device. it is more a task for IT support, as a developer you don't do anything.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
ramagirinagarjuna
Posts: 6
Registered: ‎11-29-2012
My Device: Blackberry9800
My Carrier: Blackberry

Re: How to overcome Authentication issue in my blackberry application?

Hi simon,peter

without authentication how can i access an protected webservice and for every user the data from the server gets changed .without knowing particular user who has launched application how can i dispaly the content from the server?..if im wrong please explain me in detailed way what exactly is happening when i try to connect an NTLM authenticated webservice.

 

Lets assume im trying the whole thing from a blackberry deivce,not from simulator.

Please use plain text.
Developer
simon_hain
Posts: 15,956
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to overcome Authentication issue in my blackberry application?

the MDS adds the authentification.

check if "Support HTTP Authentication" is set to True in the MDS-CS settings on the BES.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.