Skip to content
Praveen edited this page Sep 13, 2018 · 4 revisions

Authenticating

There are three way to instantiate the WhdAuth object. The enumeration com.whd.Util.WHD_AUTH_TYPE defines the three types.

Using password and username

        String uri = "http://localhost:8081";
        
        String username = "username";
        String password = "password";
        
        try{
            WhdAuth auth = new WhdAuth(uri, WHD_AUTH_TYPE.PASSWORD, username, password);
            auth.authenticate(); // Verifies if credentials are valid
        }
        catch(WhdException e){
            System.out.println("WHD Exception caught");
            // exceptionType() will return WhdExceptionType.AUTH_FAILURE if WHD returned 401 Unauthorized
            System.out.println("Exception Type: "+e.getExceptionType());
            System.out.println("Exception Comment: "+e.getComment());
        }

Using Session Key

        try{
            WhdAuth auth = new WhdAuth(uri, WHD_AUTH_TYPE.SESSION_KEY, username, null);
            auth.authenticate(password); // password is passed here, to obtain the SessionKey
        }
        catch(WhdException e){
            System.out.println("WHD Exception caught");
            System.out.println("Exception Type: "+e.getExceptionType());
            System.out.println("Exception Comment: "+e.getComment());
        }

If you already have a SessionKey and want to reuse it.

Note Session Keys expire after 30 minutes of inactivity.

        WhdAuth auth = new WhdAuth(uri, WHD_AUTH_TYPE.SESSION_KEY, username, sessionkey);

Using API Key

        WhdAuth auth = new WhdAuth(uri, WHD_AUTH_TYPE.API_KEY, username, apikey);
Clone this wiki locally