09-06-2012 11:54 AM
Hi,
When running TestMain (from Java BWS Sample), I can successfully get as far as initializing credentials, but at the line
GetUsersResponse response = _bws.getUsers(request);
it produces a 401 error.
Starting to intiialize credentials...
Credentials initialized.
Starting to retrieve users...
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportExce
at com.sun.xml.internal.ws.transport.http.client.Http
We use Active Directory, and the username/pw in the java code are my own, which I use to log onto the BAS console.
I'm running the java script locally on my pc. The encoded username is "8,16,0,1,1,0;amarasnybas.ad.dpw-ama.com00"
Any ideas please?
Thank you.
09-08-2012 09:42 PM
Did you modify the code to use the Active Directory Authenticator? If not it would be trying to authenticate your username and password against a non-existent BAS account which would explain the 401.
09-10-2012 09:35 AM
This may not be the best way to do it, but I modified setup() to include a call to GetAuthenticatorsRequest(); and used the authenticator it returned in GetEncodedUsernameRequest(), which seemed to do the trick.
private static boolean setup() {
String strBASURL=System.getProperty("basurl");
URL serviceUrl = null;
URL utilServiceUrl=null;
//The Metadata object includes information about this application, it is included with every call
_meta.setClientVersion(_clientVersion);
_meta.setOrganizationUid("0"); //Not used currently, set to "0"
_meta.setLocale(_locale);
try {
serviceUrl = new URL("https://" + strBASURL + "/enterprise/admin/ws?wsdl");
utilServiceUrl = new URL("https://" + strBASURL + "/enterprise/admin/util/ws?wsdl");
} catch (MalformedURLException e) {
System.err.println("Cannot initialize the wsdl");
return false;
}
//Initialize our web service stubs that will be used for all calls
_myBWSService = new BWSService(serviceUrl);
_bws = _myBWSService.getBWS();
_myBWSUtilService = new BWSUtilService(utilServiceUrl);
_bwsUtil = _myBWSUtilService.getBWSUtil();
String username=System.getProperty("username");
String password=System.getProperty("password");
GetAuthenticatorsRequest request2 = new GetAuthenticatorsRequest();
request2.setMetadata(_meta);
GetAuthenticatorsResponse response2 = _bwsUtil.getAuthenticators(request2);
if (response2.getReturnStatus().getCode().compareTo("
{ System.out.println("Error occurred: " + response2.getReturnStatus().getMessage());
}
else if (response2.getAuthenticators() != null)
{ for (Authenticator itr:response2.getAuthenticators())
{ System.out.println(itr.getName() + ", " + itr.getUid() + ", " + (itr.getAuthenticatorType().isINTERNAL() ? "internal" : "plugin"));
authenticator = itr;
}
}
GetEncodedUsernameRequest request=new GetEncodedUsernameRequest();
request.setMetadata(_meta);
request.setUsername(username);
request.setOrgUid("0");
String domainName = "ad.dpw-ama.com";
//set credentialType
CredentialType credentialType = new CredentialType();
credentialType.setPASSWORD(true);
credentialType.setValue(password);
request.setCredentialType(credentialType);
//"authenticator" was returned from the getAuthenticators() API
//BlackBerry Administration Service authentication requires only a username and password
//(identical to the BAS Web Console)
request.setAuthenticator(authenticator);
//PLUGIN authentication, ex. "Active Directory", also requires a "domain" to be set
//(identical to the BAS Web Console)
if(authenticator.getAuthenticatorType().isPLUGIN
{ request.setDomain(domainName);
}
GetEncodedUsernameResponse geurResponse= _bwsUtil.getEncodedUsername(request);
if (geurResponse.getReturnStatus().getCode().compareT
System.out.println("Error occurred: " + geurResponse.getReturnStatus().getMessage());
return false;
}
String myEncodeUsername = geurResponse.getEncodedUsername();
//Set http basic authentication on the web service
BindingProvider bp = (BindingProvider)_bws;
bp.getRequestContext().put(BindingProvider.USERN
bp.getRequestContext().put(BindingProvider.PASSW
return true;
}
Thanks very much!