Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Web Services

Reply
New Member
alexisgingras
Posts: 1
Registered: ‎12-08-2011
My Device: 9300
My Carrier: Videotron

Create a blackberry enabled user with Web services for Enterprise Administration

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?

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Create a blackberry enabled user with Web services for Enterprise Administration

[ Edited ]

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/enterprise/admin/5.0.3/

 

Let me know if you experience any difficulties implementing the code from the sample.

 

Regards,

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
scmurdock
Posts: 15
Registered: ‎01-14-2012
My Device: Developer
My Carrier: Developer

Re: Create a blackberry enabled user with Web services for Enterprise Administration

[ Edited ]

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.defaultRole.getUid());
		   userAttributes.setDomain("test.com");

		   //use this mail account
		   AccountAttributes accountAttributes=new AccountAttributes();
		   accountAttributes.setEmailAddress("jtanner@test.com");
		   

		   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().compareTo("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("SUCCESS")==0) {
		           System.out.println("User created. Uid is: " + itr.getUid());
		       } 
		   }

 

Thanks!

Sean

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Create a blackberry enabled user with Web services for Enterprise Administration

Hi Sean,

 

Can you create the user using the same information through the BAS console?

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
scmurdock
Posts: 15
Registered: ‎01-14-2012
My Device: Developer
My Carrier: Developer

Re: Create a blackberry enabled user with Web services for Enterprise Administration

Hello Garett- yes I just did.

 

Thanks,

Sean

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Create a blackberry enabled user with Web services for Enterprise Administration

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.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
scmurdock
Posts: 15
Registered: ‎01-14-2012
My Device: Developer
My Carrier: Developer

Re: Create a blackberry enabled user with Web services for Enterprise Administration

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.GetAuthenticatorsResponse;
import com.rim.ws.enterprise.admin.GetEncodedUsernameRequest;
import com.rim.ws.enterprise.admin.GetEncodedUsernameResponse;
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.GetUsersDetailIndividualResponse;
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/attachments/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._meta);

		   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("password");
		   userAttributes.setDisplayName("jtanner");
		   userAttributes.setRoleUid(createUserStub.defaultRole.getUid());
		   userAttributes.setDomain("test.com");
		   

		   //use this mail account
		   AccountAttributes accountAttributes=new AccountAttributes();
		   accountAttributes.setEmailAddress("jtanner@test.com");
		   

		   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().compareTo("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("SUCCESS")==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().compareTo("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.USERNAME_PROPERTY, myEncodeUsername);
		bp.getRequestContext().put(BindingProvider.PASSWORD_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;
	}
}

 

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: Create a blackberry enabled user with Web services for Enterprise Administration

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)?

 

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
scmurdock
Posts: 15
Registered: ‎01-14-2012
My Device: Developer
My Carrier: Developer

Re: Create a blackberry enabled user with Web services for Enterprise Administration

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

Please use plain text.
Contributor
scmurdock
Posts: 15
Registered: ‎01-14-2012
My Device: Developer
My Carrier: Developer

Re: Create a blackberry enabled user with Web services for Enterprise Administration

[ Edited ]

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

Please use plain text.