12-08-2011 07:21 AM
Hi,
A few months ago I created an application that use the Blackberry enterprise server API. When we updated our BES to 5.0.3 I also updated my app to use the Web services for Enterprise Administration instead.
Now I need to add a few features to my app. One of them is the possibility to create blackberry enabled user from our exchange server. I read the doc of the Web services for Enterprise Administration and I didn't find anywhere the possibility to do so. I did find the possibility to do so with the old API with the emailexchangews.
Did I miss something, or do I have to add the emailexchangews to my proxy?
12-08-2011 07:45 AM - edited 12-08-2011 10:25 AM
Hi and welcome to the forums!
BAA and BWS are completely mutually exclusive, so you should not mix the web services. The ability to create users is completely supported in BWS through the BWS#createUsers() call. A piece of sample code accompanies each call in the API documentation:
http://www.blackberry.com/developers/docs/bws/ente
Let me know if you experience any difficulties implementing the code from the sample.
Regards,
01-25-2012 11:54 PM - edited 01-26-2012 11:48 AM
Hi, I also am using BWS to create users, but finding it difficult using the same code given in the API docs:
Error occured: ONE_OR_MORE_FAILURES
Individual responses - Code: USER_CREATION_FAILED Message: Failed to create user: Internal error
NewUser newUser=new NewUser(); UserAttributes userAttributes=new UserAttributes(); //enable user to logon with BAS authenticator userAttributes.setAuthenticator(createUserStub.adAuthenticator);//Active Directory userAttributes.setLoginName("jtanner"); userAttributes.setLoginPassword("pA$$wrd2"); userAttributes.setDisplayName("jtanner"); userAttributes.setRoleUid(createUserStub.defaultRo le.getUid()); userAttributes.setDomain("test.com"); //use this mail account AccountAttributes accountAttributes=new AccountAttributes(); accountAttributes.setEmailAddress("jtanner@test.co m"); newUser.setUserAttributes(userAttributes); newUser.setAccountAttributes(accountAttributes); //randomly select a BlackBerry Enterprise Server to create the user on newUser.setServer(null); createUsersRequest.getNewUsers().add(newUser); CreateUsersResponse createUsersResponse = createUserStub._bws.createUsers(createUsersRequest ); if (createUsersResponse.getReturnStatus().getCode().c ompareTo("SUCCESS")!=0) { System.out.println("Error occured: " + createUsersResponse.getReturnStatus().getCode()); } for (IndividualResponse itr:createUsersResponse.getIndividualResponses()) { System.out.println("Individual responses - Code: " + itr.getReturnStatus().getCode() + " Message: " + itr.getReturnStatus().getMessage()); if (itr.getReturnStatus().getCode().compareTo("SUCCES S")==0) { System.out.println("User created. Uid is: " + itr.getUid()); } }
Thanks!
Sean
01-26-2012 09:32 AM
Hi Sean,
Can you create the user using the same information through the BAS console?
01-26-2012 12:02 PM
Hello Garett- yes I just did.
Thanks,
Sean
01-26-2012 12:17 PM
There may be an issue with the special characters used in the password, could you try standard characters to see if it helps to resolve the issue. If not, please post a full code sample that can be used to reproduce the issue.
01-26-2012 12:32 PM
Hi Garett- thanks for your quick reply. See below:
Error occured: ONE_OR_MORE_FAILURES
Individual responses - Code: USER_CREATION_FAILED Message: Failed to create user: Internal error
package biz.mytechlab.bes.test; import java.net.MalformedURLException; import java.net.URL; import javax.xml.ws.BindingProvider; import com.rim.ws.enterprise.admin.Authenticator; import com.rim.ws.enterprise.admin.AuthenticatorType; import com.rim.ws.enterprise.admin.AccountAttributes; import com.rim.ws.enterprise.admin.BWS; import com.rim.ws.enterprise.admin.BWSService; import com.rim.ws.enterprise.admin.BWSUtil; import com.rim.ws.enterprise.admin.BWSUtilService; import com.rim.ws.enterprise.admin.CreateUsersRequest; import com.rim.ws.enterprise.admin.CreateUsersResponse; import com.rim.ws.enterprise.admin.Device; import com.rim.ws.enterprise.admin.GetAuthenticatorsRequest; import com.rim.ws.enterprise.admin.GetAuthenticatorsRespo nse; import com.rim.ws.enterprise.admin.GetEncodedUsernameRequ est; import com.rim.ws.enterprise.admin.GetEncodedUsernameResp onse; import com.rim.ws.enterprise.admin.GetRolesRequest; import com.rim.ws.enterprise.admin.GetRolesResponse; import com.rim.ws.enterprise.admin.GetServersRequest; import com.rim.ws.enterprise.admin.GetServersResponse; import com.rim.ws.enterprise.admin.GetUsersDetailIndividu alResponse; import com.rim.ws.enterprise.admin.GetUsersDetailRequest; import com.rim.ws.enterprise.admin.GetUsersDetailResponse ; import com.rim.ws.enterprise.admin.GetUsersRequest; import com.rim.ws.enterprise.admin.GetUsersResponse; import com.rim.ws.enterprise.admin.GetUsersSearchCriteria ; import com.rim.ws.enterprise.admin.GetUsersSortBy; import com.rim.ws.enterprise.admin.IndividualResponse; import com.rim.ws.enterprise.admin.NewUser; import com.rim.ws.enterprise.admin.RequestMetadata; import com.rim.ws.enterprise.admin.Role; import com.rim.ws.enterprise.admin.Server; import com.rim.ws.enterprise.admin.User; import com.rim.ws.enterprise.admin.UserAttributes; import com.rim.ws.enterprise.admin.UserDetail; import java.util.List; public class BWSCreateUserTest {//based on sample code by gbeukeboom at http://supportforums.blackberry.com/rim/attachment s/rim/bes_dev@tkb/17/5/Java%20BWS%20Sample.zip private BWSService _myBWSService; private BWS _bws; private BWSUtilService _myBWSUtilService; private BWSUtil _bwsUtil; private String _locale = "en_US"; private String _clientVersion = "5.0.3"; //The version of BAS this application was created for private String basURL; private RequestMetadata _meta = new RequestMetadata(); private List<Authenticator> authenticators; private Authenticator adAuthenticator;//active directory authenticator object (Active Directory, uid = 111) private List<Role> roles; private Role defaultRole;//default role without admin privileges private Server server; public String getBasURL(){ return this.basURL; } public static void main(String[] args){ BWSCreateUserTest createUserStub = new BWSCreateUserTest(); createUserStub.setup("HOST-1234.test.priv"); //create the request object CreateUsersRequest createUsersRequest = new CreateUsersRequest(); createUsersRequest.setMetadata(createUserStub._met a); NewUser newUser=new NewUser(); UserAttributes userAttributes=new UserAttributes(); //enable user to logon with BAS authenticator userAttributes.setAuthenticator(createUserStub.adA uthenticator);//Active Directory userAttributes.setLoginName("jtanner"); userAttributes.setLoginPassword("password"); userAttributes.setDisplayName("jtanner"); userAttributes.setRoleUid(createUserStub.defaultRo le.getUid()); userAttributes.setDomain("test.com"); //use this mail account AccountAttributes accountAttributes=new AccountAttributes(); accountAttributes.setEmailAddress("jtanner@test.co m"); newUser.setUserAttributes(userAttributes); newUser.setAccountAttributes(accountAttributes); //randomly select a BlackBerry Enterprise Server to create the user on newUser.setServer(createUserStub.server); createUsersRequest.getNewUsers().add(newUser); CreateUsersResponse createUsersResponse = createUserStub._bws.createUsers(createUsersRequest ); if (createUsersResponse.getReturnStatus().getCode().c ompareTo("SUCCESS")!=0) { System.out.println("Error occured: " + createUsersResponse.getReturnStatus().getCode()); } for (IndividualResponse itr:createUsersResponse.getIndividualResponses()) { System.out.println("Individual responses - Code: " + itr.getReturnStatus().getCode() + " Message: " + itr.getReturnStatus().getMessage()); if (itr.getReturnStatus().getCode().compareTo("SUCCES S")==0) { System.out.println("User created. Uid is: " + itr.getUid()); } } } public boolean setup(String strBASURL) { if(_bws!=null & this.basURL==strBASURL) return true;//connection already setup this.basURL=strBASURL; 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(strBASURL+".username") ; String password=System.getProperty(strBASURL+".password") ; GetAuthenticatorsRequest authReq= new GetAuthenticatorsRequest(); authReq.setMetadata(_meta); GetAuthenticatorsResponse authResponse = _bwsUtil.getAuthenticators(authReq); System.out.println(authResponse.getReturnStatus(). getMessage()); authenticators=authResponse.getAuthenticators(); for (Authenticator auth:authResponse.getAuthenticators()){ if(auth.getName().contains("Active Directory")){ adAuthenticator=auth; } } GetEncodedUsernameRequest request=new GetEncodedUsernameRequest(); request.setMetadata(_meta); request.setUsername(username); request.setDomain(strBASURL); //The BAS expects the username to be encoded, this call returns the encoded value GetEncodedUsernameResponse geurResponse = _bwsUtil.getEncodedUsername(request); if (geurResponse.getReturnStatus().getCode().compareT o("SUCCESS") != 0){ 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.USERNAM E_PROPERTY, myEncodeUsername); bp.getRequestContext().put(BindingProvider.PASSWOR D_PROPERTY, password); GetRolesRequest roleReq = new GetRolesRequest(); roleReq.setMetadata(_meta); roleReq.setName(""); GetRolesResponse roleResponse = _bws.getRoles(roleReq); System.out.println(roleResponse.getReturnStatus(). getMessage()); roles = roleResponse.getRoles(); for (Role role:roles){ if (role.getLocaleNameAndDescription().get(0).getName ().equals("default")){ defaultRole=role; System.out.println(role.toString()); } } GetServersRequest servReq = new GetServersRequest(); servReq.setMetadata(_meta); String[] hostNameWithDomain = strBASURL.split("\\."); String hostName=hostNameWithDomain[0]; servReq.setHostName(hostName);//get server, extract the host name GetServersResponse servResponse = _bws.getServers(servReq); System.out.println(servResponse.getReturnStatus(). getMessage()); for (Server server:servResponse.getServers()){ if (server.getHostName().equals(hostName))//get server this.server=server; } return true; } }
01-26-2012 01:24 PM
Hi Sean,
I tested your code here and it works properly, I successfully created a user. You may want to debug and check that all values are set as expected before the call to actually create the user.
Also, out of curiosity, are you able to create any other users? Can you create a strictly BAS user (not specifying a UserAttributes object)?
01-26-2012 03:11 PM
Hi Garett- thanks for the reply. I checked all values in the debugger and it looked right. I had a question on the userAttributes.setDomain method. Is it the email domain?
Also, I thought that the userAttributes.setLoginPassword() might not be needed since the user's authentication is done via Active Directory. But if I don't use it I get this:
Error occured: ONE_OR_MORE_FAILURES
Individual responses - Code: INVALID_PARAMETER Message: Login password is required.
If I comment out the the newUser.setAccountAttributes(accountAttributes) the results are:
Individual responses - Code: USER_CREATION_FAILED Message: Failed to create user: Internal error
Thanks,
Sean
01-26-2012 03:54 PM - edited 01-26-2012 03:56 PM
Garett- I think I found the problem was that the domain should have been set differently in Active Directory as test.priv not test.com. So I created a user in Active Directory called ttanner with the test.priv domain, updated the code to userAttributes.setDomain("test.priv"), and now get the following:
Error occured: ONE_OR_MORE_FAILURES
Individual responses - Code: USER_CREATION_FAILED Message: Failed to create user: Cannot find AD user