So I'm new to codename1, Im trying to log into a server using HTLM, How would I achieve this?
I cannot find any resources that help with this issue.
So I'm new to codename1, Im trying to log into a server using HTLM, How would I achieve this?
I cannot find any resources that help with this issue.
As found here https://docs.oracle.com/javase/8/docs/technotes/guides/net/http-auth.html
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
public class RunHttpSpnego {
static final String kuser = "username"; // your account name
static final String kpass = password; // retrieve password for your account
static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
// I haven't checked getRequestingScheme() here, since for NTLM
// and Negotiate, the usrname and password are all the same.
System.err.println("Feeding username and password for " + getRequestingScheme());
return (new PasswordAuthentication(kuser, kpass.toCharArray()));
}
}
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL(args[0]);
InputStream ins = url.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
String str;
while((str = reader.readLine()) != null)
System.out.println(str);
}
}
NTLM requires native support from the OS. What you did there will work on JavaSE where the simulator is running but will not work on the device.
To get this to work on the device you will need native code NTLM Authentication with HttpURLConnection describes how this is done for Android. To implement that you will need to create a native interface and call this code within the native interface:
jcifs.Config.registerSmbURLHandler();
From that point on the rest should work from Codename One. Notice that you will need to also place the library that's required within the native/android directory.
The iOS side of the fence should work with this how to send NTLM request in iOS
Specifically this block:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: _host
port: 80
protocol: @"http"
realm: _host
authenticationMethod:NSURLAuthenticationMethodNTLM];