Beispiel #1
0
        public UserService()
        {
            // create a test user
            User user = new User();

            user.userName    = "******";
            user.externalId  = "mcrooke";
            user.displayName = "Mr Matt Crooke";

            // set the user names
            user.name            = new Name();
            user.name.givenName  = "Matt";
            user.name.familyName = "Crooke";
            user.name.formatted  = "Mr Matt Crooke";

            // set the user emails
            PluralAttribute email = new PluralAttribute();

            email.primary = true;
            email.value   = "*****@*****.**";
            PluralAttribute[] emails = new PluralAttribute[] { email };
            user.emails = emails;

            // retrieve the users cache manager
            if (usersCacheManager == null)
            {
                usersCacheManager = CacheFactory.GetCacheManager(USERS_CACHE);
            }

            // populate the id with the local id
            user.id = "uid=" + user.externalId + ",dc=hackerypokery,dc=com";

            // store the user in the cache
            usersCacheManager.Add(user.id, user);
        }
 private static IPluralFacet Create(PluralAttribute attribute, IFacetHolder holder) {
     return attribute == null ? null : new PluralFacetAnnotation(attribute.Value, holder);
 }
 private static IPluralFacet Create(PluralAttribute attribute, ISpecification holder)
 {
     return(attribute == null ? null : new PluralFacetAnnotation(attribute.Value, holder));
 }
Beispiel #4
0
        public static String createUserTest(Client client)
        {
            // create a test user
            User user = new User();

            user.userName    = "******";
            user.externalId  = "mcrooke";
            user.displayName = "Mr Matt Crooke";

            // set the user names
            user.name            = new Name();
            user.name.givenName  = "Matt";
            user.name.familyName = "Crooke";
            user.name.formatted  = "Mr Matt Crooke";

            // set the user emails
            PluralAttribute email = new PluralAttribute();

            email.primary = true;
            email.value   = "*****@*****.**";
            PluralAttribute[] emails = new PluralAttribute[] { email };
            user.emails = emails;

            // send the request to create the user
            HttpWebResponse response = client.createUser(user);

            // verify the response code indicates success
            //int status =  response.getStatusCode();
            //assert(status == 201);

            // retrieve the location of the user
            //String location = response.getHeaders().getFirst("Location");

            // build a nide reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // get the user object from the response
                user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("created user - " + user.externalId + " as " + user.id);
                return(user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be created, error returned - " + error.code + " " + error.description);
                return(null);
            }

            /*
             * // get the response stream to read the user
             * Stream stream = response.GetResponseStream();
             *
             * // create a user deserializer
             * XmlSerializer deserializer = new XmlSerializer(typeof(User));
             *
             * // retrieve the returned user entry
             * user = (User)deserializer.Deserialize(stream);
             *
             * // retrieve the id of the user
             * String id = user.id;
             *
             * Console.WriteLine("created user - " + user.externalId + " as " + user.id);
             *
             * return id;
             */
        }
Beispiel #5
0
        public static void updateUserTest(Client client, String uid)
        {
            // send the request to retrieve the user
            HttpWebResponse response = client.retrieveUser(uid);

            // build a node reader from the response
            XmlNodeReader xmlNodeReader = client.buildReaderFromResponse(response);

            try
            {
                // verify the response code indicates success
                //int status =  response.getStatusCode();
                //assert(status == 200);

                /*
                 * // get the response stream to read the user
                 * Stream stream = response.GetResponseStream();
                 *
                 * // create a user deserializer
                 * XmlSerializer deserializer = new XmlSerializer(typeof(User));
                 *
                 * // retrieve the returned user entry
                 * User user = (User)deserializer.Deserialize(stream);
                 */

                // get the user object from the response
                User user = client.getUserFromResponse(xmlNodeReader);

                // update the users name
                user.name.givenName  = "Matthew";
                user.name.familyName = "Crooke";
                user.nickName        = "Matt";
                user.name.formatted  = "Mr Matthew Crooke";

                // update the users groups
                PluralAttribute group = new PluralAttribute();
                group.value = "gid=nerds,ou=groups,dc=hackerypokery,dc=com";
                PluralAttribute[] memberOfs = new PluralAttribute[] { group };
                user.memberOf = memberOfs;

                // send the request to update the user
                response = client.updateUser(user);

                // verify the response code indicates success
                //status =  response.getStatusCode();
                //assert(status == 200);

                /*
                 * // get the response stream to update user
                 * stream = response.GetResponseStream();
                 *
                 * // retrieve the returned user entry
                 * user = (User)deserializer.Deserialize(stream);
                 */

                // build a node reader from the response
                xmlNodeReader = client.buildReaderFromResponse(response);

                // get the user object from the response
                user = client.getUserFromResponse(xmlNodeReader);

                Console.WriteLine("updated user - " + user.id);
            }
            catch (InvalidOperationException ioException)
            {
                // InvalidOperationException is throw when a user cannot be deserialized

                // get the error object from the response
                Error error = client.getErrorFromResponse(xmlNodeReader);

                Console.WriteLine("user cannot be updated, error returned - " + error.code + " " + error.description);
            }
        }
 private static IPluralFacet Create(PluralAttribute attribute, ISpecification holder) => attribute is null ? null : new PluralFacetAnnotation(attribute.Value, holder);