Exemplo n.º 1
0
        public void UpdateUser(IntraUser oldUser)
        {
            DialogWindow w = new DialogWindow(oldUser);

            w.ShowDialog();

            if (w.DialogResult == true)
            {
                Debug.WriteLine(fieldResults.SelectedValue.ToString());
                //try
                //{
                var user = w.Answer;
                if (ProducerV2.send(XMLParser.ObjectToXML(user), Severity.AD.ToString()))
                {
                    Console.WriteLine(XMLParser.ObjectToXML(user));

                    /*
                     * <?xml version="1.0" encoding="utf-16"?>
                     * <user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                     *  <header>
                     *      <method>UPDATE</method>
                     *      <origin>AD</origin>
                     *      <version>1</version>
                     *      <timestamp>2021-05-26T15:42:39+02:00</timestamp>
                     *  </header>
                     *  <body>
                     *      <firstname>test</firstname>
                     *      <lastname>up</lastname>
                     *      <email>[email protected]</email>
                     *      <role>docent</role>
                     *  </body>
                     * </user>
                     */
                    MessageBox.Show("Updated user succesfully send!");
                    btnCreateUser.IsEnabled = btnDeleteUser.IsEnabled = btnUpdateUser.IsEnabled = false;
                }
                //}
                //catch (Exception ex)
                //{
                //    MessageBox.Show(ex.Message);
                //}
            }
        }
Exemplo n.º 2
0
 public void DeleteUser(IntraUser user)
 {
     if (ProducerV2.send(XMLParser.ObjectToXML(user), Severity.AD.ToString()))
     {
         /*
          * <user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          * <header>
          *  <method>DELETE</method>
          *  <origin>AD</origin>
          *  <version>0</version>
          *  <timestamp>2021-05-26T15:44:41+02:00</timestamp>
          * </header>
          * <body>
          *  <firstname>test</firstname>
          *  <lastname>d</lastname>
          *  <email>[email protected]</email>
          *  <role>docent</role>
          * </body>
          * </user>
          */
     }
 }
Exemplo n.º 3
0
        /**
         *  Methode: Update the UUID based of the method within the user object
         */
        public static void Update(IntraUser outUser)
        {
            //Replace the necessairy properties with the right Values to send over the queue
            outUser.MetaData.Origin    = "AD";
            outUser.MetaData.TimeStamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss%K");

            /**
             * When some properties of the user are empty, the xml tags alsow dissapear.
             * Even tho, the UUID checks for these empty tags, thus giving an error.
             * So the xml message is HARDCODED with dynamic user data.
             */
            string message = "<user><header>" +
                             "<UUID></UUID>" +
                             "<method>" + outUser.MetaData.Methode + "</method>" +
                             "<origin>" + outUser.MetaData.Origin + "</origin>" +
                             "<version></version>" +
                             "<sourceEntityId>" + outUser.MetaData.GUID + "</sourceEntityId>" +
                             "<timestamp>" + outUser.MetaData.TimeStamp + "</timestamp>" +
                             "</header>" +
                             "<body>" +
                             "<firstname>" + outUser.UserData.FirstName + "</firstname>" +
                             "<lastname>" + outUser.UserData.LastName + "</lastname>" +
                             "<email>" + outUser.UserData.Email + "</email>" +
                             "<birthday>" + outUser.UserData.BirthDay + "</birthday>" +
                             "<role>" + outUser.UserData.Role + "</role>" +
                             "<study>" + outUser.UserData.Study + "</study>" +
                             "</body></user>";

            //Produce a message on the UUID queue
            if (!ProducerV2.Send(message, Severity.UUID.ToString()))
            {
                Console.WriteLine("##################################################");
                Console.WriteLine($"# Producing Message on the UUID Queue has FAILED #");
                Console.WriteLine("##################################################");
            }
        }
Exemplo n.º 4
0
        /**
         *  Main Methode: Reads the operation and assigns the right CRUD operation on the incoming user
         *      @param1 => The method/operation of the CRUD to be executed
         *      @param2 => The incoming user object that is used for the CRUD
         *      @param3 => The CRUD instance with all the CRUD functionality inside
         */
        public static void OperationToCRUD(this string operation, IntraUser user, CRUD crudInstance)
        {
            //Makes an AD/C# user object for ease of use
            var adUser = user.IntraUserObjectToADObject();

            //Check for operation with switch case
            switch (operation.ToUpperInvariant())
            {
            //Creates a new user in the Active Directory DB
            case "CREATE":
                if (crudInstance.CreateUser(user.IntraUserObjectToADObject()))
                {
                    //Check if new user made it into the DB
                    if (crudInstance.IsUserInAD(adUser.CN))
                    {
                        //Get the newly generated GUID from the Attributes
                        user.MetaData.GUID = crudInstance.FindADUser(adUser.CN).ObjectGUID;
                        //Update the UUID with the newly created user
                        Uuid.Update(user);
                    }
                    else
                    {
                        //If user is not found, display an error
                        Console.WriteLine("##################################################");
                        Console.WriteLine($"#      Newly created user cannot be found        #");
                        Console.WriteLine("##################################################");
                    }
                }
                else
                {
                    //Show error if Create got interrupted
                    Console.WriteLine("##################################################");
                    Console.WriteLine($"# CREATING user from Active Directory has FAILED #");
                    Console.WriteLine("##################################################");

                    //Make a XML Error string to log error
                    string error = "<error>" +
                                   "<header>" +
                                   "<code>3003</code>" +
                                   "<origin>AD</origin>" +
                                   "<timestamp>" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss%K") + "</timestamp>" +
                                   "</header>" +
                                   "<body>" +
                                   "<objectUUID></objectUUID>" +
                                   "<objectSourceId></objectSourceId>" +
                                   "<objectOrigin>AD</objectOrigin>" +
                                   "<description>The user could not be added to the AD</description>" +
                                   "</body>" +
                                   "</error>";
                    //Send the error on the Logging Queue
                    ProducerGUI.send(error, Severity.logging.ToString());
                }
                break;

            //Deletes an existing user from the Active Directory DB
            case "DELETE":
                if (crudInstance.DeleteUser(adUser.CN))
                {
                    /**
                     *  Because the GUI only has the Container name of all the users
                     *  the DELETE method only comes wrapped around a READ method,
                     *  to first find the user and with that reference => delete the user
                     */
                    user.MetaData.Methode = CRUDMethode.DELETE;
                    //Update the UUID with the deleted user
                    Uuid.Update(user);
                }
                else
                {
                    //Show error if Delete got interrupted
                    Console.WriteLine("##################################################");
                    Console.WriteLine($"# DELETING user from Active Directory has FAILED #");
                    Console.WriteLine("##################################################");
                }
                break;

            //Updates an existing user from the Active Directory DB
            case "UPDATE":
                //Find the old user object based on the same GUID from both users
                var oldUser = crudInstance.FindADUser("objectGUID=" + ConvertGuidToOctetString(user.MetaData.GUID));
                if (crudInstance.UpdateUser(oldUser, user.IntraUserObjectToADObject()))
                {
                    //Update the UUID with the newly updated user
                    Uuid.Update(user);
                }
                else
                {
                    //Show error if Update got interrupted
                    Console.WriteLine("##################################################");
                    Console.WriteLine($"# UPDATING user from Active Directory has FAILED #");
                    Console.WriteLine("##################################################");
                }
                break;

            //Reads all users in Active Directory and wrap it into a List<ADUser>
            case "READ_ALL":
                //Get all users
                ListUsers.List = crudInstance.GetADUsers();
                //Converts List into a XML Array and send it on the Queue of the GUI
                ProducerGUI.send(ObjectToXML(ListUsers.List), Severity.GUI.ToString());     //Make new Producer
                break;

            default:
                Console.WriteLine("##################################################");
                Console.WriteLine($"#       INVALID Operation: {operation} ");
                Console.WriteLine("##################################################");
                break;
            }
        }