What I am trying to do :
I am trying to connect to Web Portal [that uses https]using Java. I have written code for supplying user credentials using Authenticator class.When I run the program I get an Exception:
"java.lang.UnsupportedOperationException: Not supported yet"
I have the code posted :
public class Main {
public class MyAuthenticator extends Authenticator {
protected PasswordAuthentication getpasswordAuthentication() {
String username = "username";
String password = "password";
// Return the information
return new PasswordAuthentication(username, password.toCharArray());
}
@Override
public Result authenticate(HttpExchange he) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
public static void main(String[] args) {
// TODO code application logic here
TrustManager[] trustClients = new TrustManager[]{
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
throw new UnsupportedOperationException("Not supported yet.");
}
public X509Certificate[] getAcceptedIssuers() {
return null;
//throw new UnsupportedOperationException("Not supported yet.");
}
}
};
try {
SSLContext sslcontext = SSLContext.getInstance("SSL");
sslcontext.init(null, trustClients, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());
} catch (Exception e) {
System.out.println("in 1st catch " + e);
}
try {
URL url = new URL("https://someURL.server.com/fmk/jsp/ltpaLogin.jsp");
URLConnection urlconnection = url.openConnection();
System.out.println(urlconnection);
System.out.print(urlconnection.getInputStream().toString());
} catch (Exception e) {
System.out.println("in 2ndcatch " + e.getMessage());
}
}
}
the exception "java.lang.UnsupportedOperationException: Not supported yet"is raised in the 2nd Try.Is my approach correct ? if not is there any alternative to do so ?
When I open the page in web browser I get the login page;Once I supply my credentials the web portal is displayed
Can any one please suggest how to hit the webportal and supply my credentials and check the authentication is success or not ? Any sample code snippets will be really helpful Thanks in advance..