Hi Abraham,

Are you trying to only check if a username exists in your domain or
you actually want to make sure no such username before creating a new
user?

Please let me know your use case so I can better help you.

Thanks,

--Tony

On Oct 3, 10:00 am, "Abraham Segura" <[EMAIL PROTECTED]> wrote:
> Hi Group, did anyone could help me with and example to check if a username
> is already in google apps.
>
> And I have writting this code could anyone say me it is fine or if I need
> more souce.
>
> package com.kionetworks.gapps.ejb;
> import com.google.gdata.data.appsforyourdomain.provisioning.UserEntry;
> import com.google.gdata.client.appsforyourdomain.UserService;
> import com.google.gdata.client.appsforyourdomain.AppsForYourDomainService;
> import com.google.gdata.util.AuthenticationException;
> import sample.appsforyourdomain.AppsForYourDomainClient;
>
> import javax.ejb.Stateless;
>
> @Stateless
> public class AppServiceBean implements AppServiceLocal
> {
>     public static String account="[EMAIL PROTECTED]";
>     public static String password="mypass";
>     public static String domain="domain.com.mx";
>
>     public AppServiceBean()
>     {
>     }
>
>     private String getToken() throws AuthenticationException
>     {
>         String token="";
>         UserService userService = new UserService("apps");
>         token =
> userService.getAuthToken(AppServiceBean.account,AppServiceBean.password,
> null, null,
>         AppsForYourDomainService.APPS_SERVICE, "apps");
>         return token;
>     }
>
>     public void createUser(String username, String givenName, String
> familyName, String password)
>     {
>         try
>         {
>             AppsForYourDomainClient apps = new
> AppsForYourDomainClient(AppServiceBean.account,
>                     AppServiceBean.password, AppServiceBean.domain);
>             apps.createUser(username, givenName, familyName,
>                     PasswordGenerator.getPassword(
>         PasswordGenerator.MINUSCULAS+
>         PasswordGenerator.MAYUSCULAS,10));
>             UserEntry user = apps.retrieveUser(username);
>         }
>         catch(Exception ex)
>         {
>         }
>     }
>
> }
>
> class PasswordGenerator
> {
>     public static String NUMEROS = "0123456789";
>     public static String MAYUSCULAS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
>     public static String MINUSCULAS = "abcdefghijklmnopqrstuvwxyz";
>     public static String ESPECIALES = "√±√ë";
>
>     public static String getPinNumber()
>         {
>         return getPassword(NUMEROS, 4);
>     }
>
>     public static String getPassword()
>         {
>         return getPassword(8);
>     }
>
>     public static String getPassword(int length)
>         {
>         return getPassword(NUMEROS + MAYUSCULAS + MINUSCULAS, length);
>     }
>
>     public static String getPassword(String key, int length)
>         {
>         String pswd = "";
>         for (int i = 0; i < length; i++)
>                 {
>             pswd+=(key.charAt((int)(Math.random() * key.length())));
>         }
>         return pswd;
>     }
>
> }
>
> Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Apps APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/google-apps-apis?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to