-
Notifications
You must be signed in to change notification settings - Fork 1
Authenticating
Praveen edited this page Sep 13, 2018
·
4 revisions
There are three way to instantiate the WhdAuth
object.
The enumeration com.whd.Util.WHD_AUTH_TYPE
defines the three types.
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());
}
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);
WhdAuth auth = new WhdAuth(uri, WHD_AUTH_TYPE.API_KEY, username, apikey);