예제 #1
0
        private void GetProjects()
        {
            var getParentIdjsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getprojects&startIndex=0&fetchSize=1&sortBy=sequence&sortOrder=ascend&action=1&solutionId=-1&filterOption=1",
                    _protocol, Params.SBMHostPort);

            var     getParentIdresponse    = WebReq.Make(getParentIdjsonUrl, ssoBase64: _ssoBase64, contentLength: 0);
            JObject getParentIdjObject     = JObject.Parse(getParentIdresponse);
            JToken  getParentIdprojectList = getParentIdjObject["projectList"];
            var     parentId = getParentIdprojectList.First["id"].Value <string>();

            var jsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getprojects&startIndex=0&fetchSize=99999&sortBy=sequence&sortOrder=ascend&searchString=&action=1&solutionId=-1&parentId={2}&projectId=-1",
                    _protocol, Params.SBMHostPort, parentId);

            var response = WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, contentLength: 0);

            JObject jObject     = JObject.Parse(response);
            JToken  projectList = jObject["projectList"];

            _objectExcahnge.Add("SBM.RolesPerProject", new Dictionary <string, SBMRolesPerProject>());
            foreach (var project in projectList)
            {
                var ids = new SBMRolesPerProject {
                    id = project["id"].Value <int>(), solutionId = project["solutionId"].Value <string>()
                };
                ((Dictionary <string, SBMRolesPerProject>)_objectExcahnge["SBM.RolesPerProject"]).Add(project["name"].Value <string>(), ids);
            }
        }
예제 #2
0
        public void SetGroup(string grpName)
        {
            GetAll();

            if (((Dictionary <string, int>)_objectExcahnge["SBM.Groups"]).ContainsKey(grpName))
            {
                Log.Warn("Group: '" + grpName + "' already exists.");
            }
            else
            {
                Log.Info("Creating group: " + grpName);

                var jsonStruct = new SBMSetGroup[1];
                jsonStruct[0] = new SBMSetGroup(grpName);

                var data    = JsonConvert.SerializeObject(jsonStruct);
                var jsonUrl = string.Format("{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=updategroupgeneral&action=1&count=1&checkForConcurrency=0",
                                            _protocol, Params.SBMHostPort);

                WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, data: data);

                _objectExcahnge.Remove("SBM.Groups");
                GetGroups();
            }
        }
예제 #3
0
        private void SetRolesHelper(Dictionary <string, int> inputRoles, byte userOrGroup, int userOrGroupId, SBMRolesPerProject project, string proj)
        {
            var jsonUrl = string.Format("{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=updatesecuritycontrols&timestamp=-1", _protocol, Params.SBMHostPort);

            //get roles ids and grants to lists
            var permissionIds = new List <int>();
            var grantList     = new List <int>();
            //set all roles for group/user
            int firstRoleGranted;

            if (inputRoles.Count == 1 && inputRoles.TryGetValue("*", out firstRoleGranted))
            {
                foreach (var role in project.Roles)
                {
                    UpdatePermissionsGrantLists(role.Value, firstRoleGranted, role.Key, proj, ref permissionIds, ref grantList);
                }
            }
            else
            {
                foreach (var role in inputRoles)
                {
                    int tmpRole;
                    if (project.Roles.TryGetValue(role.Key, out tmpRole))
                    {
                        UpdatePermissionsGrantLists(tmpRole, role.Value, role.Key, proj, ref permissionIds, ref grantList);
                    }
                    else
                    {
                        Log.Warn(string.Format("Role '{0}' not found for project '{1}'", role.Key, proj));
                    }
                }
            }
            //prepare json struct
            int count = permissionIds.Count;

            if (count > 0)
            {
                var jsonStruct = new SBMSetRole[count];
                for (int i = 0; i < count; i++)
                {
                    jsonStruct[i] = new SBMSetRole(project.id, userOrGroupId, userOrGroup)
                    {
                        permissionId = permissionIds[i], granted = grantList[i]
                    }
                }
                ;

                var data = JsonConvert.SerializeObject(jsonStruct);
                WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, data: data);
            }
            else
            {
                Log.Warn(string.Format("No following roles found for '" + proj + "': "));
                foreach (var inputRole in inputRoles)
                {
                    Log.Warn(" - " + inputRole.Key);
                }
            }
        }
예제 #4
0
        private void GetUsers()
        {
            var jsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getusers&showDeleted=0&showExternal=0&showLimited=0&onlyManaged=1&startIndex=0&fetchSize=99999&sortBy=loginId&sortOrder=ascend&searchString=",
                    _protocol, Params.SBMHostPort);

            var response = WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, contentLength: 0);

            JObject jObject  = JObject.Parse(response);
            JToken  userList = jObject["userList"];

            _objectExcahnge.Add("SBM.Users", new Dictionary <string, int>());
            foreach (var user in userList)
            {
                ((Dictionary <string, int>)_objectExcahnge["SBM.Users"]).Add(user["loginId"].Value <string>(), user["id"].Value <int>());
            }
        }
예제 #5
0
        private void GetGroups()
        {
            var jsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getgroups&showDeleted=0&onlyManaged=1&startIndex=0&fetchSize=99999&sortBy=name&sortOrder=ascend&searchString=",
                    _protocol, Params.SBMHostPort);

            var response = WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, contentLength: 0);

            JObject jObject   = JObject.Parse(response);
            JToken  groupList = jObject["groupList"];

            _objectExcahnge.Add("SBM.Groups", new Dictionary <string, int>());
            foreach (var group in groupList)
            {
                ((Dictionary <string, int>)_objectExcahnge["SBM.Groups"]).Add(group["name"].Value <string>(), group["id"].Value <int>());
            }
        }
예제 #6
0
        public void SetMembershipForUser(string inputUserLogin, string[] inputGroups)
        {
            GetAll();
            int userId;

            if (((Dictionary <string, int>)_objectExcahnge["SBM.Users"]).TryGetValue(inputUserLogin, out userId))
            {
                var jsonUrl = string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=updatememberships&timestamp=-1&checkForConcurrency=0&subjectType=1", _protocol, Params.SBMHostPort);
                var groupIDs = new List <int>();
                foreach (var groupName in inputGroups)
                {
                    int tmpGroupId;
                    if (((Dictionary <string, int>)_objectExcahnge["SBM.Groups"]).TryGetValue(groupName, out tmpGroupId))
                    {
                        groupIDs.Add(tmpGroupId);
                        Log.Info(string.Format("Setting '" + groupName + "' membership for " + inputUserLogin));
                    }
                }
                int count = groupIDs.Count;
                if (count > 0)
                {
                    var jsonStruct = new SetMembership[count];
                    for (int i = 0; i < count; i++)
                    {
                        jsonStruct[i] = new SetMembership(groupIDs[i], userId);
                    }

                    var data = JsonConvert.SerializeObject(jsonStruct);
                    WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, data: data);
                }
                else
                {
                    Log.Warn(string.Format("No group membership to be set for '" + inputUserLogin + "'"));
                }
            }
            else
            {
                Log.Warn(string.Format("User '" + inputUserLogin + "' doesn't exist."));
            }
        }
예제 #7
0
        public void SetUser(string inputUserLogin, string inputUserName, string inputUserPwd, string email, string emailCc)
        {
            GetAll();

            int    action;
            string data;
            var    dateFormatted = (String.Format("{0:MM/dd/yyyy}", DateTime.Now)).Replace('.', '/');

            if (((Dictionary <string, int>)_objectExcahnge["SBM.Users"]).ContainsKey(inputUserLogin))
            {
                action = 2; //for at least update
                Log.Info("Modifying user: "******"SBM.Users"])[inputUserLogin]));
            }
            else
            {
                action = 1; //for creation
                Log.Info("Creating user: "******"SBM.Users");
            }

            var jsonUrl =
                string.Format(
                    "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=updateusergeneral&action={2}&timestamp=-1&passWasChanged=1&checkForConcurrency=0", _protocol,
                    Params.SBMHostPort, action);

            WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, data: data);

            if (action == 1)
            {
                GetUsers();
            }
        }
예제 #8
0
        private void GetRoles()
        {
            var projects = (Dictionary <string, SBMRolesPerProject>)_objectExcahnge["SBM.RolesPerProject"];

            foreach (var sbmProject in projects)
            {
                var projectId  = sbmProject.Value.id;
                var solutionId = sbmProject.Value.solutionId;

                var jsonUrl =
                    string.Format(
                        "{0}://{1}/tmtrack/tmtrack.dll?JSONPage&command=getapplicationroles&startIndex=0&fetchSize=99999&sortBy=NAME&sortOrder=ascending&applicationId={2}&projectId={3}",
                        _protocol, Params.SBMHostPort, solutionId, projectId);
                var response = WebReq.Make(jsonUrl, ssoBase64: _ssoBase64, contentLength: 0);

                JObject  jObject = JObject.Parse(response);
                JToken[] roles   = jObject["applicationRoles"]["roles"].ToArray();

                foreach (var role in roles)
                {
                    sbmProject.Value.Roles.Add(role["roleName"].Value <string>(), role["id"].Value <int>());
                }
            }
        }
예제 #9
0
        private void GetToken(string oeHost, string oePort, string username, string password, bool isHttps)
        {
            string requestData;

            using (Stream stream = GetType().Assembly.GetManifestResourceStream("userScript.SSO.ssoTokenRequest.xml"))
            {
                using (var sr = new StreamReader(stream))
                {
                    requestData = sr.ReadToEnd();
                }
            }

            requestData = requestData.Replace("{{Username}}", username).Replace("{{Password}}", password);
            string url = string.Format("http{0}://{1}:{2}/{3}", isHttps ? "s" : string.Empty, oeHost, oePort, Endpoint);

            var response = WebReq.Make(url, contentType: ContentType, data: requestData);

            if (string.IsNullOrEmpty(response))
            {
                throw new Exception("There were no response from SBM at all.");
            }

            //convert value to XML
            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(response);
            }
            catch (Exception)
            {
                throw new Exception("Not proper XML response recieved from SBM: \n" + response);
            }

            //we need to add namespace in order to be able to look for saml: nodes
            var nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            nsmgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:1.0:assertion");
            //get node with required for SSO
            var fault = xmlDoc.SelectSingleNode("//soapenv:Fault", nsmgr);

            if (fault != null)
            {
                var explanation = fault.SelectSingleNode("//Explanation");
                if (explanation == null)
                {
                    throw new Exception("Failed to obtain SSO Token, no explanation has been provided in response.");
                }
                throw new Exception(explanation.InnerText);
            }

            var tokenShort = xmlDoc.SelectSingleNode("//saml:Assertion", nsmgr);

            _ssoTokenXMLNode = xmlDoc.SelectSingleNode("//soapenv:Envelope", nsmgr);
            if (tokenShort == null || _ssoTokenXMLNode == null)
            {
                throw new Exception("SSO: Failed to find nodes in response '//saml:Assertion' or '//soapenv:Envelope'");
            }

            _ssoTokenXmlString = _ssoTokenXMLNode.OuterXml;
            _ssoTokenDecoded   = tokenShort.OuterXml;
            var bytes = Encoding.UTF8.GetBytes(_ssoTokenDecoded);

            _ssoTokenBase64 = Convert.ToBase64String(bytes);
        }