예제 #1
0
        /// <summary>
        /// Create a new workspace having the credentials specified and insert
        /// it in the workspace manager, with the current task Stop.
        /// </summary>
        public static Workspace CreateWorkspace(KwsCredentials creds)
        {
            try
            {
                // Clear the public flag if we already have a public workspace.
                if (Cd.PublicKwsID != 0)
                {
                    creds.PublicFlag = false;
                }

                // Get a new internal ID.
                UInt64 internalID = Cd.NextKwsInternalID++;

                // Register the worskpace in the workspace manager.
                KwsCoreData kwsCd = new KwsCoreData();
                kwsCd.Credentials = creds;
                Workspace kws = new Workspace();
                kws.Relink(internalID, kwsCd);
                AdjustPublicKwsID();

                // Insert the workspace in the workpace list in the database.
                LocalDbBroker.AddKwsToKwsList(kws.InternalID, kws.Cd.Credentials.KwsName);

                // The WM state has changed.
                Wm.OnStateChange(WmStateChange.Permanent);

                return(kws);
            }

            catch (Exception ex)
            {
                KBase.HandleException(ex, true);
                return(null);
            }
        }
예제 #2
0
파일: KwsCoreData.cs 프로젝트: tmbx/kwm-ng
        /// <summary>
        /// Return the user having the ID specified, if any. Virtual users
        /// may be returned.
        /// </summary>
        public KwsUser GetUserByID(UInt32 ID)
        {
            if (ID == 0)
            {
                return(RootUser);
            }
            if (UserTree.ContainsKey(ID))
            {
                return(UserTree[ID]);
            }

            KwsCredentials creds = m_cd.Credentials;

            if (ID == creds.UserID)
            {
                KwsUser user = new KwsUser();
                user.UserID       = creds.UserID;
                user.AdminName    = creds.UserName;
                user.UserName     = creds.UserName;
                user.EmailAddress = creds.UserEmailAddress;
                user.VirtualFlag  = true;
                return(user);
            }

            return(null);
        }
예제 #3
0
        private KwsAnpEventStatus HandleKwsCreatedEvent(AnpMsg msg)
        {
            KwsCredentials creds = m_kws.Cd.Credentials;

            // Add the creator to the user list.
            KwsUser user = new KwsUser();

            user.UserID         = msg.Elements[2].UInt32;
            user.InvitationDate = msg.Elements[1].UInt64;
            user.AdminName      = msg.Elements[3].String;
            user.EmailAddress   = msg.Elements[4].String;
            user.OrgName        = msg.Elements[msg.Minor <= 2 ? 7 : 5].String;
            user.AdminFlag      = true;
            user.ManagerFlag    = true;
            user.RegisterFlag   = true;
            m_kws.Cd.UserInfo.UserTree[user.UserID] = user;

            // Update the workspace data.
            if (msg.Minor <= 2)
            {
                creds.SecureFlag = true;
            }

            if (msg.Minor >= 3)
            {
                creds.KwsName     = msg.Elements[6].String;
                creds.Flags       = msg.Elements[7].UInt32;
                creds.KwmoAddress = msg.Elements[8].String;
            }

            m_kws.OnStateChange(WmStateChange.Permanent);
            return(KwsAnpEventStatus.Processed);
        }
예제 #4
0
        /// <summary>
        /// Called by the workspace state machine to log in the workspace.
        /// </summary>
        public void PerformLogin()
        {
            Debug.Assert(m_currentStep == KwsLoginStep.None);

            // We perform the cached step if explicitly required, if the
            // workspace is open, if we have a ticket and a password, or if we
            // cannot login on the KPS. The latter condition is necessary since
            // we have to try to login once to determine whether a password is
            // available on the KCD. Otherwise, we perform the ticket step
            // directly.
            KwsCredentials creds      = m_kws.Cd.Credentials;
            bool           cachedFlag = (m_loginType == KwsLoginType.Cached ||
                                         !creds.SecureFlag ||
                                         creds.Ticket != null ||
                                         creds.Pwd != "" ||
                                         !KwmCfg.Cur.CanLoginOnKps());

            if (cachedFlag)
            {
                HandleCachedLoginStep();
            }
            else
            {
                HandleTicketLoginStep();
            }
        }
예제 #5
0
파일: KwsSpawnHandler.cs 프로젝트: tmbx/kwm
 public BaseImportKwsOp(WorkspaceManager wm, KwsCredentials creds, String folderPath, bool joinFlag)
     : base(wm)
 {
     m_folderPath = folderPath;
     m_joinFlag = joinFlag;
     m_sh = new KwsSpawnOpHelper(this, creds);
 }
예제 #6
0
        /// <summary>
        /// "Import" a workspace that already exists in the KWM.
        /// </summary>
        private static void ImportExistingKws(Workspace kws, KwsCredentials creds)
        {
            KwsTask task = kws.Cd.CurrentTask;

            KLogging.Log("Import of existing workspace " + kws.InternalID + " with task " + task + " requested.");

            // We can only import workspaces that are stopped or working
            // offline.
            if (task != KwsTask.Stop && task != KwsTask.WorkOffline)
            {
                KLogging.Log("Skipping import due to incompatible task.");
                return;
            }

            // Update the credentials unless they were already accepted.
            if (kws.Cd.KcdState.LoginResult != KwsLoginResult.Accepted)
            {
                KLogging.Log("Updating workspace credentials.");
                creds.PublicFlag   = kws.Cd.Credentials.PublicFlag;
                kws.Cd.Credentials = creds;
            }

            // Make the workspace work online.
            kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline);

            // The workspace state has changed.
            kws.OnStateChange(WmStateChange.Permanent);
        }
예제 #7
0
        /// <summary>
        /// Extract the workspace credentials from the XML element specified.
        /// </summary>
        private static KwsCredentials XmlToKwsCredentials(XmlElement el)
        {
            KwsCredentials c = new KwsCredentials();

            int version = Int32.Parse(el.GetAttribute("version"));

            if (version > KwsCredentials.ExportVersion)
            {
                throw new Exception("unsupported kws version ('" + version + "')");
            }

            c.KcdAddress          = KwmXml.GetXmlChildValue(el, "KcdAddress", "");
            c.KwmoAddress         = KwmXml.GetXmlChildValue(el, "KwmoAddress", "");
            c.ExternalID          = UInt64.Parse(KwmXml.GetXmlChildValue(el, "ExternalID", "0"));
            c.EmailID             = KwmXml.GetXmlChildValue(el, "EmailID", "");
            c.KwsName             = KwmXml.GetXmlChildValue(el, "KwsName", "");
            c.UserName            = KwmXml.GetXmlChildValue(el, "UserName", "");
            c.UserEmailAddress    = KwmXml.GetXmlChildValue(el, "UserEmailAddress", "");
            c.InviterName         = KwmXml.GetXmlChildValue(el, "InviterName", "");
            c.InviterEmailAddress = KwmXml.GetXmlChildValue(el, "InviterEmailAddress", "");
            c.UserID     = UInt32.Parse(KwmXml.GetXmlChildValue(el, "UserID", "0"));
            c.Ticket     = Convert.FromBase64String(KwmXml.GetXmlChildValue(el, "Ticket", ""));
            c.Pwd        = KwmXml.GetXmlChildValue(el, "Pwd", "");
            c.Flags      = UInt32.Parse(KwmXml.GetXmlChildValue(el, "Flags", "0"));
            c.FolderPath = KwmXml.GetXmlChildValue(el, "FolderPath", "");
            c.EtBlob     = Convert.FromBase64String(KwmXml.GetXmlChildValue(el, "EtBlob", ""));

            if (version < 4)
            {
                XmlElement kasIDElem = KwmXml.GetXmlChildElement(el, "KasID");
                if (kasIDElem == null)
                {
                    throw new Exception("KasID element not present");
                }
                c.KcdAddress = KwmXml.GetXmlChildValue(kasIDElem, "Host", "");
                c.PublicFlag = bool.Parse(KwmXml.GetXmlChildValue(el, "PublicFlag", "False"));
                c.SecureFlag = bool.Parse(KwmXml.GetXmlChildValue(el, "SecureFlag", "False"));
            }

            // Normalize the data.
            if (c.Ticket != null && c.Ticket.Length == 0)
            {
                c.Ticket = null;
            }
            if (c.EtBlob != null && c.EtBlob.Length == 0)
            {
                c.EtBlob = null;
            }

            // Validate.
            if (c.KcdAddress == "" || c.ExternalID == 0)
            {
                throw new Exception("invalid kws credentials");
            }

            return(c);
        }
예제 #8
0
        private KwsAnpEventStatus HandleKwsPropChange(AnpMsg msg)
        {
            KwsCredentials creds    = m_kws.Cd.Credentials;
            KwsUserInfo    userInfo = m_kws.Cd.UserInfo;

            int    i        = 3;
            UInt32 nbChange = msg.Elements[i++].UInt32;

            for (UInt32 j = 0; j < nbChange; j++)
            {
                UInt32 type = msg.Elements[i++].UInt32;

                if (type == KAnp.KANP_PROP_KWS_NAME)
                {
                    creds.KwsName = msg.Elements[i++].String;
                }

                else if (type == KAnp.KANP_PROP_KWS_FLAGS)
                {
                    creds.Flags = msg.Elements[i++].UInt32;
                }

                else
                {
                    KwsUser user = userInfo.GetNonVirtualUserByID(msg.Elements[i++].UInt32);
                    if (user == null)
                    {
                        throw new Exception("no such user");
                    }

                    if (type == KAnp.KANP_PROP_USER_NAME_ADMIN)
                    {
                        user.AdminName = msg.Elements[i++].String;
                    }

                    else if (type == KAnp.KANP_PROP_USER_NAME_USER)
                    {
                        user.UserName = msg.Elements[i++].String;
                    }

                    else if (type == KAnp.KANP_PROP_USER_FLAGS)
                    {
                        user.Flags = msg.Elements[i++].UInt32;
                    }

                    else
                    {
                        throw new Exception("invalid user property type");
                    }
                }
            }

            m_kws.OnStateChange(WmStateChange.Permanent);
            return(KwsAnpEventStatus.Processed);
        }
예제 #9
0
        /// <summary>
        /// Import the workspace specified.
        /// </summary>
        public static void ImportKws(KwsCredentials creds)
        {
            Workspace kws = Wm.GetKwsByExternalID(creds.KcdID, creds.ExternalID);

            if (kws != null)
            {
                ImportExistingKws(kws, creds);
            }
            else
            {
                ImportNewKws(creds);
            }
        }
예제 #10
0
        /// <summary>
        /// Import or join a workspace that does not exist in the KWM.
        /// </summary>
        private static void ImportNewKws(KwsCredentials creds)
        {
            KLogging.Log("Importing new workspace " + creds.KwsName + ".");

            // Create the workspace.
            Workspace kws = Wm.CreateWorkspace(creds);

            // Set its main status.
            kws.Cd.MainStatus = KwsMainStatus.Good;

            // Make the workspace work online.
            kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline);
        }
예제 #11
0
파일: KwsCoreData.cs 프로젝트: tmbx/kwm-ng
        /// <summary>
        /// Clone this object.
        /// </summary>
        public KwsCredentials Clone()
        {
            KwsCredentials c = (KwsCredentials)MemberwiseClone();

            if (c.Ticket != null)
            {
                c.Ticket = (byte[])c.Ticket.Clone();
            }
            if (c.EtBlob != null)
            {
                c.EtBlob = (byte[])c.EtBlob.Clone();
            }
            return(c);
        }
예제 #12
0
파일: KwsSpawnHandler.cs 프로젝트: tmbx/kwm
 /// <summary>
 // Clone and update the current credentials.
 /// </summary>
 private void CloneCreds()
 {
     Creds = new KwsCredentials(Creds);
     m_sh.Creds = Creds;
     m_ih.Creds = Creds;
 }
예제 #13
0
        /// <summary>
        /// Create a new workspace having the credentials specified and insert
        /// it in the workspace manager, with the current task Stop.
        /// </summary>
        public static Workspace CreateWorkspace(KwsCredentials creds)
        {
            try
            {
                // Clear the public flag if we already have a public workspace.
                if (Cd.PublicKwsID != 0) creds.PublicFlag = false;

                // Get a new internal ID.
                UInt64 internalID = Cd.NextKwsInternalID++;

                // Register the worskpace in the workspace manager.
                KwsCoreData kwsCd = new KwsCoreData();
                kwsCd.Credentials = creds;
                Workspace kws = new Workspace();
                kws.Relink(internalID, kwsCd);
                AdjustPublicKwsID();

                // Insert the workspace in the workpace list in the database.
                LocalDbBroker.AddKwsToKwsList(kws.InternalID, kws.Cd.Credentials.KwsName);

                // The WM state has changed.
                Wm.OnStateChange(WmStateChange.Permanent);

                return kws;
            }

            catch (Exception ex)
            {
                KBase.HandleException(ex, true);
                return null;
            }
        }
예제 #14
0
        /// <summary>
        /// Create a new workspace object having the credentials specified and 
        /// insert it in the workspace manager, with the current task Stop and
        /// under the folder specified. Set selectFlag to true if you want the
        /// workspace to be selected once created.
        /// </summary>
        public Workspace CreateWorkspaceObject(KwsCredentials creds, KwsBrowserFolderNode folder, bool firstFlag)
        {
            try
            {
                // Clear the public flag if we already have a public workspace.
                if (PublicKwsID != 0) creds.PublicFlag = false;

                // Get the KAS object.
                WmKas kas = GetOrCreateKas(creds.KasID);

                // Create the workspace object, if possible.
                Workspace kws = new Workspace(this, kas, NextKwsInternalId++, creds);

                // Register the workspace in the WM and the KAS.
                KwsTree[kws.InternalID] = kws;
                kas.KwsTree[kws.InternalID] = kws;
                AdjustPublicKwsID();

                // Insert the workspace in the folder specified.
                UiBroker.Browser.AddKws(kws, folder, firstFlag);
                UiBroker.RequestBrowserUiUpdate(true);

                // Insert the workspace in the database.
                AddKwsToDb(kws);
                SetDirty();

                return kws;
            }

            catch (Exception ex)
            {
                Base.HandleException(ex, true);
                return null;
            }
        }
예제 #15
0
파일: KwsSpawnHandler.cs 프로젝트: tmbx/kwm
 public KwmImportKwsOp(WorkspaceManager wm, KwsCredentials creds, String folderPath, bool joinFlag)
     : base(wm, creds, folderPath, joinFlag)
 {
 }
예제 #16
0
 public KwsInviteOpHelper(KwsCoreOp op, KwsCredentials creds)
 {
     Op = op;
     Creds = creds;
 }
예제 #17
0
 public OutlookLookupRecAddrOp(WorkspaceManager wm, WmOutlookRequest request)
     : base(wm)
 {
     KwsCredentials creds = new KwsCredentials();
     creds.SecureFlag = true;
     m_ih = new KwsInviteOpHelper(this, creds);
     m_ih.FillInviteParamsFromOutlookLookupRecCmd(request.Cmd);
     RegisterOutlookRequest(request);
 }
예제 #18
0
파일: Workspace.cs 프로젝트: tmbx/kwm
 public ExportedKws(KwsCredentials creds, String folderPath)
 {
     Creds = creds;
     FolderPath = folderPath;
 }
예제 #19
0
파일: Workspace.cs 프로젝트: tmbx/kwm
 /// <summary>
 /// Non-deserializing constructor. This constructor can throw.
 /// </summary>
 public Workspace(WorkspaceManager wm, WmKas kas, UInt64 internalID, KwsCredentials creds)
 {
     Kas = kas;
     InternalID = internalID;
     CoreData.Credentials = creds;
     if (creds != null) Debug.Assert(Kas.KasID.CompareTo(creds.KasID) == 0);
     Initialize(wm);
     SetDirty();
 }
예제 #20
0
        /// <summary>
        /// "Import" a workspace that already exists in the KWM.
        /// </summary>
        public void ImportExistingKws(Workspace kws, KwsCredentials creds, bool singleFlag)
        {
            KwsTask task = kws.Sm.GetCurrentTask();
            Logging.Log("Import of existing workspace " + kws.InternalID + " with task " + task + " requested.");

            // Do not do anything if the workspace is being spawned, removed or
            // is already working online.
            if (task == KwsTask.Spawn || task == KwsTask.Remove || task == KwsTask.WorkOnline)
            {
                Logging.Log("Skipping import.");
                return;
            }

            // Update the credentials unless they were already accepted.
            if (kws.KasLoginHandler.LoginResult != KwsLoginResult.Accepted)
            {
                Logging.Log("Updating workspace credentials.");
                creds.PublicFlag = kws.CoreData.Credentials.PublicFlag;
                kws.CoreData.Credentials = creds;
            }

            // Make the workspace work online.
            if (task == KwsTask.WorkOffline || task == KwsTask.Stop)
            {
                KwsLoginType loginType = singleFlag ? KwsLoginType.All : KwsLoginType.NoPwdPrompt;
                Logging.Log("Switching to WorkOnline task with login type " + loginType + ".");
                kws.Sm.SetLoginType(loginType);
                kws.Sm.RequestTaskSwitch(KwsTask.WorkOnline);
            }
        }
예제 #21
0
        /// <summary>
        /// Store the workspace credentials in the element specified. Nothing
        /// is exported if the credentials are invalid.
        /// </summary>
        private static void KwsCredentialsToXml(KwsCredentials c, XmlDocument doc, XmlElement parent)
        {
            if (c.KcdAddress == "" || c.ExternalID == 0)
            {
                return;
            }

            XmlElement el = doc.CreateElement("Kws");

            parent.AppendChild(el);

            el.SetAttribute("version", KwsCredentials.ExportVersion.ToString());
            KwmXml.CreateXmlElement(doc, el, "KcdAddress", c.KcdAddress);
            if (c.KwmoAddress != "")
            {
                KwmXml.CreateXmlElement(doc, el, "KwmoAddress", c.KwmoAddress);
            }
            KwmXml.CreateXmlElement(doc, el, "ExternalID", c.ExternalID.ToString());
            KwmXml.CreateXmlElement(doc, el, "EmailID", c.EmailID);
            if (c.KwsName != "")
            {
                KwmXml.CreateXmlElement(doc, el, "KwsName", c.KwsName);
            }
            if (c.UserName != "")
            {
                KwmXml.CreateXmlElement(doc, el, "UserName", c.UserName);
            }
            if (c.UserEmailAddress != "")
            {
                KwmXml.CreateXmlElement(doc, el, "UserEmailAddress", c.UserEmailAddress);
            }
            if (c.InviterName != "")
            {
                KwmXml.CreateXmlElement(doc, el, "InviterName", c.InviterName);
            }
            if (c.InviterEmailAddress != "")
            {
                KwmXml.CreateXmlElement(doc, el, "InviterEmailAddress", c.InviterEmailAddress);
            }
            if (c.UserID != 0)
            {
                KwmXml.CreateXmlElement(doc, el, "UserID", c.UserID.ToString());
            }
            if (c.Ticket != null)
            {
                KwmXml.CreateXmlElement(doc, el, "Ticket", Convert.ToBase64String(c.Ticket));
            }
            if (c.Pwd != "")
            {
                KwmXml.CreateXmlElement(doc, el, "Pwd", c.Pwd);
            }
            if (c.Flags != 0)
            {
                KwmXml.CreateXmlElement(doc, el, "Flags", c.Flags.ToString());
            }
            if (c.FolderPath != "")
            {
                KwmXml.CreateXmlElement(doc, el, "FolderPath", c.FolderPath);
            }
            if (c.EtBlob != null)
            {
                KwmXml.CreateXmlElement(doc, el, "EtBlob", Convert.ToBase64String(c.EtBlob));
            }
        }
예제 #22
0
        /// <summary>
        /// Import or join a workspace that does not exist in the KWM.
        /// </summary>
        private void ImportNewKws(KwsCredentials creds, String folderPath, bool singleFlag)
        {
            Logging.Log("Importing new workspace " + creds.KwsName + ".");

            // Validate the destination folder.
            KwsBrowserFolderNode folder = UiBroker.Browser.CreateFolderFromPath(folderPath);
            if (folder.IsRoot()) folderPath = UiBroker.Browser.PrimaryFolder.FullPath;

            // Dispatch to the import operation.
            KwmImportKwsOp op = new KwmImportKwsOp(this, creds, folderPath, singleFlag);
            op.StartOp();
        }