Example #1
0
        public IHttpActionResult RemoveValuesFromResource(string connectionInfo, string objectID, string attributeName, [FromUri] string[] valuesToRemove)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connectionInfo);
                    ResourceOption ro = new ResourceOption(ci);

                    string id = repo.Value.RemoveValuesFromResource(objectID, attributeName, valuesToRemove, ro);

                    if (id.Equals("AuthorizationRequired"))
                    {
                        return(Content(HttpStatusCode.PartialContent, id));
                    }

                    return(Ok(id));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #2
0
        public IHttpActionResult GetResourceByQuery(
            string connectionInfo, string query, [FromUri] string[] attributesToGet = null,
            int pageSize = 0, int index = 0, int cultureKey = 127, bool resolveID = false, bool deepResolve = false,
            [FromUri] string[] attributesToResolve = null, [FromUri] string[] attributesToSort = null)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connectionInfo);
                    ResourceOption ro = new ResourceOption(
                        ci, cultureKey, resolveID, deepResolve, attributesToResolve, attributesToSort);

                    DSResourceSet rss = repo.Value.GetResourceByQuery(
                        query,
                        (attributesToGet == null || attributesToGet.Length == 0) ? new string[] { "DisplayName" } : attributesToGet,
                        pageSize,
                        index,
                        ro);

                    return(Ok(rss));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #3
0
        public IHttpActionResult CreateResource(string connectionInfo, DSResource resource)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connectionInfo);
                    ResourceOption ro = new ResourceOption(ci);

                    string id = repo.Value.CreateResource(resource, ro);

                    return(Ok(id));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #4
0
        public IHttpActionResult UpdateResource(string connectionInfo, DSResource resource, bool isDelta = false)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connectionInfo);
                    ResourceOption ro = new ResourceOption(ci);

                    string id = repo.Value.UpdateResource(resource, isDelta, ro);

                    if (id.Equals("AuthorizationRequired"))
                    {
                        return(Content(HttpStatusCode.PartialContent, id));
                    }

                    return(Ok(id));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #5
0
        public IHttpActionResult GetResourceCount(string connectionInfo, string query)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connectionInfo);
                    ResourceOption ro = new ResourceOption(ci);

                    int count = repo.Value.GetResourceCount(query, ro);

                    return(Ok(count));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #6
0
        public IHttpActionResult GetResourceByID(
            string encryptionKey, string id, [FromUri] string[] attributesToGet = null,
            bool includePermission = false, int cultureKey = 127, bool resolveID = false, bool deepResolve = false,
            [FromUri] string[] attributesToResolve = null)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (!encryptionKey.Equals(this.encryptionKey))
                {
                    return(InternalServerError(new Exception("Invalid Encryption Key")));
                }

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(this.adminConnection);
                    ResourceOption ro = new ResourceOption(ci, cultureKey, resolveID, deepResolve, attributesToResolve);

                    DSResource rs = repo.Value.GetResourceByID(id, (attributesToGet == null || attributesToGet.Length == 0) ? new string[] { "DisplayName" } : attributesToGet, includePermission, ro);

                    return(Ok(rs));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #7
0
        public IHttpActionResult AddValuesToResource(string encryptionKey, string objectID, string attributeName, [FromUri] string[] valuesToAdd)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (!encryptionKey.Equals(this.encryptionKey))
                {
                    return(InternalServerError(new Exception("Invalid Encryption Key")));
                }

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(this.adminConnection);
                    ResourceOption ro = new ResourceOption(ci);

                    string id = repo.Value.AddValuesToResource(objectID, attributeName, valuesToAdd, ro);

                    if (id.Equals("AuthorizationRequired"))
                    {
                        return(Content(HttpStatusCode.PartialContent, id));
                    }

                    return(Ok(id));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #8
0
        public IHttpActionResult CreateResource(string encryptionKey, DSResource resource)
        {
            try
            {
                Lazy <IOCGDSRepository> repo = RepositoryManager.GetRepository(repos, "MIMResource");

                if (!encryptionKey.Equals(this.encryptionKey))
                {
                    return(InternalServerError(new Exception("Invalid Encryption Key")));
                }

                if (repo != null)
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(this.adminConnection);
                    ResourceOption ro = new ResourceOption(ci);

                    string id = repo.Value.CreateResource(resource, ro);

                    return(Ok(id));
                }
                else
                {
                    return(NotFound());
                }
            }
            catch (Exception exp)
            {
                return(InternalServerError(exp));
            }
        }
Example #9
0
        public string Initialize(string token, string connection = "", string encryptionKey = "")
        {
            if (!string.IsNullOrEmpty(token) && this.repoCache.Contains(token))
            {
                return(token);
            }
            else
            {
                if (string.IsNullOrEmpty(connection))
                {
                    ResourceManagementClient client = new ResourceManagementClient();
                    client.RefreshSchema();

                    if (string.IsNullOrEmpty(token))
                    {
                        return(this.repoCache.Set <ResourceManagementClient>(client));
                    }
                    else
                    {
                        this.repoCache.Set <ResourceManagementClient>(token, client);
                        return(token);
                    }
                }
                else
                {
                    ConnectionInfo ci = ConnectionInfo.BuildConnectionInfo(connection);

                    ResourceManagementClient client = null;

                    NetworkCredential cred = null;
                    if (!string.IsNullOrEmpty(ci.Domain) &&
                        !string.IsNullOrEmpty(ci.UserName) && !string.IsNullOrEmpty(ci.Password))
                    {
                        bool valid = false;
                        using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
                        {
                            valid = context.ValidateCredentials(ci.UserName, this.cryptograph.Decrypt(ci.Password, encryptionKey));
                        }
                        if (valid)
                        {
                            cred = new NetworkCredential(ci.UserName,
                                                         this.cryptograph.Decrypt(ci.Password, encryptionKey), ci.Domain);
                        }
                        else
                        {
                            throw new Exception("invalid user");
                        }
                    }
                    else
                    {
                        throw new Exception("invalid user");
                    }

                    if (cred == null)
                    {
                        throw new Exception("invalid user");
                    }

                    client = string.IsNullOrEmpty(ci.BaseAddress) ?
                             new ResourceManagementClient(cred) : new ResourceManagementClient(ci.BaseAddress, cred);
                    client.RefreshSchema();

                    //if (cred == null)
                    //{
                    //    client = string.IsNullOrEmpty(ci.BaseAddress) ?
                    //        new ResourceManagementClient() : new ResourceManagementClient(ci.BaseAddress);
                    //    client.RefreshSchema();
                    //}
                    //else
                    //{
                    //    client = string.IsNullOrEmpty(ci.BaseAddress) ?
                    //        new ResourceManagementClient(cred) : new ResourceManagementClient(ci.BaseAddress, cred);
                    //    client.RefreshSchema();
                    //}

                    if (string.IsNullOrEmpty(token))
                    {
                        return(this.repoCache.Set <ResourceManagementClient>(client));
                    }
                    else
                    {
                        this.repoCache.Set <ResourceManagementClient>(token, client);
                        return(token);
                    }
                }
            }
        }