Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"java.lang.UnsupportedOperationException: Not supported yet."

Tags:

java

ssl

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..

like image 200
ManiVI Avatar asked Nov 29 '22 04:11

ManiVI


2 Answers

Have you seen this code fragment ?

    @Override
    public Result authenticate(HttpExchange he) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

It's precisely the one that will throw the aforementionned exception each time you try to authenticate.

So, to my mind, the solution to your authentication problem is quite simple : implement this method.

like image 98
Riduidel Avatar answered Dec 06 '22 02:12

Riduidel


if you don't want implement this method :

    @Override
    public Result authenticate(HttpExchange he) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

take it easy , only delete this line of method :

throw new UnsupportedOperationException("Not supported yet.");
like image 39
mehdi shahdoost Avatar answered Dec 06 '22 04:12

mehdi shahdoost