private void ProcessRootServices()
        {
            try {
                OslcClient          rootServicesClient = new OslcClient();
                HttpResponseMessage response           = rootServicesClient.GetResource(rootServicesUrl, OSLCConstants.CT_RDF);
                Stream       stream       = response.Content.ReadAsStreamAsync().Result;
                IGraph       rdfGraph     = new Graph();
                IRdfReader   parser       = new RdfXmlParser();
                StreamReader streamReader = new StreamReader(stream);

                using (streamReader)
                {
                    parser.Load(rdfGraph, streamReader);

                    //get the catalog URL
                    catalogUrl = GetRootServicesProperty(rdfGraph, catalogNamespace, catalogProperty);

                    //get the OAuth URLs
                    requestTokenUrl       = GetRootServicesProperty(rdfGraph, JFS_NAMESPACE, JazzRootServicesConstants.OAUTH_REQUEST_TOKEN_URL);
                    authorizationTokenUrl = GetRootServicesProperty(rdfGraph, JFS_NAMESPACE, JazzRootServicesConstants.OAUTH_USER_AUTH_URL);
                    accessTokenUrl        = GetRootServicesProperty(rdfGraph, JFS_NAMESPACE, JazzRootServicesConstants.OAUTH_ACCESS_TOKEN_URL);
                    try {             // Following field is optional, try to get it, if not found ignore exception because it will use the default
                        authorizationRealm = GetRootServicesProperty(rdfGraph, JFS_NAMESPACE, JazzRootServicesConstants.OAUTH_REALM_NAME);
                    } catch (ResourceNotFoundException e) {
                        // Ignore
                    }
                }
            } catch (Exception e) {
                throw new RootServicesException(baseUrl, e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Create an OSLC query that uses OSLC query parameters and the given page size
        /// </summary>
        /// <param name="oslcClient">the authenticated OSLC client</param>
        /// <param name="capabilityUrl">the URL that is the base</param>
        /// <param name="pageSize">the number of results to include on each page (OslcQueryResult)</param>
        /// <param name="oslcQueryParams">an OslcQueryParameters object</param>
        public OslcQuery(OslcClient oslcClient, string capabilityUrl,
                         int pageSize, OslcQueryParameters oslcQueryParams)
        {
            this.oslcClient    = oslcClient;
            this.capabilityUrl = capabilityUrl;
            this.pageSize      = (pageSize < 1) ? 0 : pageSize;

            //make a local copy of any query parameters
            if (oslcQueryParams != null)
            {
                where       = oslcQueryParams.GetWhere();
                select      = oslcQueryParams.GetSelect();
                orderBy     = oslcQueryParams.GetOrderBy();
                searchTerms = oslcQueryParams.GetSearchTerms();
                prefix      = oslcQueryParams.GetPrefix();
            }
            else
            {
                where = select = orderBy = searchTerms = prefix = null;
            }

            uriBuilder = new UriBuilder(capabilityUrl);
            ApplyPagination();
            ApplyOslcQueryParams();
            queryUrl = GetQueryUrl();
        }
Exemple #3
0
        private static void ProcessCurrentPage(OslcQueryResult result, OslcClient client, bool asDotNetObjects)
        {
            foreach (String resultsUrl in result.GetMembersUrls())
            {
                Console.WriteLine(resultsUrl);

                HttpResponseMessage response = null;
                try {
                    //Get a single artifact by its URL
                    response = client.GetResource(resultsUrl, OSLCConstants.CT_RDF);

                    if (response != null)
                    {
                        //De-serialize it as a .NET object
                        if (asDotNetObjects)
                        {
                            //Requirement req = response.getEntity(Requirement.class);
                            //printRequirementInfo(req);   //print a few attributes
                        }
                        else
                        {
                            //Just print the raw RDF/XML (or process the XML as desired)
                            processRawResponse(response);
                        }
                    }
                } catch (Exception e) {
                    logger.Error("Unable to process artfiact at url: " + resultsUrl, e);
                }
            }
        }
Exemple #4
0
 private static void processCurrentPage(OslcQueryResult result, OslcClient client, bool asDotNetObjects)
 {
     foreach (ChangeRequest cr in result.GetMembers <ChangeRequest>())
     {
         Console.WriteLine("id: " + cr.GetIdentifier() + ", title: " + cr.GetTitle() + ", status: " + cr.GetStatus());
     }
 }
Exemple #5
0
        /// <summary>
        /// Create an OSLC query that uses OSLC query parameters and the given page size
        /// </summary>
        /// <param name="oslcClient">the authenticated OSLC client</param>
        /// <param name="capabilityUrl">the URL that is the base</param>
        /// <param name="pageSize">the number of results to include on each page (OslcQueryResult)</param>
        /// <param name="oslcQueryParams">an OslcQueryParameters object</param>
        public OslcQuery(OslcClient oslcClient, string capabilityUrl,
                         int pageSize, OslcQueryParameters oslcQueryParams)
        {
            _oslcClient    = oslcClient;
            _capabilityUrl = capabilityUrl;
            _pageSize      = (pageSize < 1) ? 0 : pageSize;

            //make a local copy of any query parameters
            if (oslcQueryParams != null)
            {
                _where       = oslcQueryParams.GetWhere();
                _select      = oslcQueryParams.GetSelect();
                _orderBy     = oslcQueryParams.GetOrderBy();
                _searchTerms = oslcQueryParams.GetSearchTerms();
                _prefix      = oslcQueryParams.GetPrefix();
            }
            else
            {
                _where = _select = _orderBy = _searchTerms = _prefix = null;
            }

            _uriBuilder = new UriBuilder(capabilityUrl);
            ApplyPagination();
            ApplyOslcQueryParams();
            _queryUrl = GetQueryUrl();
        }
Exemple #6
0
        private static void ProcessPagedQueryResults(OslcQueryResult result, OslcClient client, bool asDotNetObjects)
        {
            int page = 1;

            do
            {
                Console.WriteLine("\nPage " + page + ":\n");
                ProcessCurrentPage(result, client, asDotNetObjects);
                if (result.MoveNext())
                {
                    result = result.Current;
                    page++;
                }
                else
                {
                    break;
                }
            } while(true);
        }
Exemple #7
0
 /// <summary>
 /// Create an OSLC query that uses the given page size
 /// </summary>
 /// <param name="oslcClient">the authenticated OSLC client</param>
 /// <param name="capabilityUrl">the URL that is the base</param>
 /// <param name="pageSize">the number of results to include on each page (OslcQueryResult)</param>
 public OslcQuery(OslcClient oslcClient, string capabilityUrl, int pageSize) :
     this(oslcClient, capabilityUrl, pageSize, null)
 {
 }
Exemple #8
0
 /// <summary>
 /// Create an OSLC query with query parameters that uses the default page size
 /// </summary>
 /// <param name="oslcClient">the authenticated OSLC client</param>
 /// <param name="capabilityUrl">capabilityUrl capabilityUrl the URL that is the base</param>
 /// <param name="oslcQueryParams">an OslcQueryParameters object</param>
 public OslcQuery(OslcClient oslcClient, string capabilityUrl, OslcQueryParameters oslcQueryParams) :
     this(oslcClient, capabilityUrl, 0, oslcQueryParams)
 {
 }
Exemple #9
0
 /// <summary>
 /// Create an OSLC query that uses the remote system's default page size.
 /// </summary>
 /// <param name="oslcClient">the authenticated OSLC client</param>
 /// <param name="capabilityUrl">the URL that is the base </param>
 public OslcQuery(OslcClient oslcClient, string capabilityUrl) :
     this(oslcClient, capabilityUrl, 0)
 {
 }
Exemple #10
0
        private static HttpMessageHandler OAuthHandler(string requestTokenURL,
                                                       string authorizationTokenURL,
                                                       string accessTokenURL,
                                                       string consumerKey,
                                                       string consumerSecret,
                                                       string user,
                                                       string passwd,
                                                       string authUrl)
        {
            ServiceProviderDescription serviceDescription = new ServiceProviderDescription();

            serviceDescription.AccessTokenEndpoint       = new MessageReceivingEndpoint(new Uri(accessTokenURL), HttpDeliveryMethods.PostRequest);
            serviceDescription.ProtocolVersion           = ProtocolVersion.V10a;
            serviceDescription.RequestTokenEndpoint      = new MessageReceivingEndpoint(new Uri(requestTokenURL), HttpDeliveryMethods.PostRequest);
            serviceDescription.TamperProtectionElements  = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() };
            serviceDescription.UserAuthorizationEndpoint = new MessageReceivingEndpoint(new Uri(authorizationTokenURL), HttpDeliveryMethods.PostRequest);

            TokenManager tokenManager = new TokenManager(consumerKey, consumerSecret);
            WebConsumer  consumer     = new WebConsumer(serviceDescription, tokenManager);

            // callback is never called by CLM, but needed to do OAuth based forms login
            // XXX - Dns.GetHostName() alway seems to return simple, uppercased hostname
            string callback = "https://" + Dns.GetHostName() + '.' + IPGlobalProperties.GetIPGlobalProperties().DomainName + ":9443/cb";

            callback = callback.ToLower();

            consumer.PrepareRequestUserAuthorization(new Uri(callback), null, null);
            OslcClient oslcClient = new OslcClient();
            HttpClient client     = oslcClient.GetHttpClient();

            HttpStatusCode      statusCode = HttpStatusCode.Unused;
            string              location   = null;
            HttpResponseMessage resp;

            try
            {
                client.DefaultRequestHeaders.Clear();

                resp = client.GetAsync(authorizationTokenURL + "?oauth_token=" + tokenManager.GetRequestToken() +
                                       "&oauth_callback=" + Uri.EscapeUriString(callback).Replace("#", "%23").Replace("/", "%2F").Replace(":", "%3A")).Result;
                statusCode = resp.StatusCode;

                if (statusCode == HttpStatusCode.Found)
                {
                    location = resp.Headers.Location.AbsoluteUri;
                    resp.ConsumeContent();
                    statusCode = FollowRedirects(client, statusCode, location);
                }

                string        securityCheckUrl = "j_username="******"&j_password="******"application/x-www-form-urlencoded");

                mediaTypeValue.CharSet = "utf-8";

                content.Headers.ContentType = mediaTypeValue;

                resp       = client.PostAsync(authUrl + "/j_security_check", content).Result;
                statusCode = resp.StatusCode;

                string jazzAuthMessage      = null;
                IEnumerable <string> values = new List <string>();

                if (resp.Headers.TryGetValues(JAZZ_AUTH_MESSAGE_HEADER, out values))
                {
                    jazzAuthMessage = values.Last();
                }

                if (jazzAuthMessage != null && string.Compare(jazzAuthMessage, JAZZ_AUTH_FAILED, true) == 0)
                {
                    resp.ConsumeContent();
                    throw new JazzAuthFailedException(user, authUrl);
                }
                else if (statusCode != HttpStatusCode.OK && statusCode != HttpStatusCode.Found)
                {
                    resp.ConsumeContent();
                    throw new JazzAuthErrorException(statusCode, authUrl);
                }
                else         //success
                {
                    Uri callbackUrl = resp.Headers.Location;

                    resp        = client.GetAsync(callbackUrl.AbsoluteUri).Result;
                    callbackUrl = resp.Headers.Location;
                    resp        = client.GetAsync(callbackUrl.AbsoluteUri).Result;
                    callbackUrl = resp.Headers.Location;

                    NameValueCollection qscoll = callbackUrl.ParseQueryString();

                    if (callbackUrl.OriginalString.StartsWith(callback + '?') && qscoll["oauth_verifier"] != null)
                    {
                        DesktopConsumer         desktopConsumer         = new DesktopConsumer(serviceDescription, tokenManager);
                        AuthorizedTokenResponse authorizedTokenResponse = desktopConsumer.ProcessUserAuthorization(tokenManager.GetRequestToken(), qscoll["oauth_verifier"]);

                        return(consumer.CreateAuthorizingHandler(authorizedTokenResponse.AccessToken, CreateSSLHandler()));
                    }

                    throw new JazzAuthErrorException(statusCode, authUrl);
                }
            } catch (JazzAuthFailedException jfe) {
                throw jfe;
            } catch (JazzAuthErrorException jee) {
                throw jee;
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }

            // return consumer.CreateAuthorizingHandler(accessToken);
            return(null);
        }
Exemple #11
0
        public static ResourceShape LookupRequirementsInstanceShapes(string serviceProviderUrl, string oslcDomain, string oslcResourceType, OslcClient client, string requiredInstanceShape)
        {
            HttpResponseMessage       response        = client.GetResource(serviceProviderUrl, OSLCConstants.CT_RDF);
            ISet <MediaTypeFormatter> formatters      = client.GetFormatters();
            ServiceProvider           serviceProvider = response.Content.ReadAsAsync <ServiceProvider>(formatters).Result;

            if (serviceProvider != null)
            {
                foreach (Service service in serviceProvider.GetServices())
                {
                    Uri domain = service.GetDomain();
                    if (domain != null && domain.ToString().Equals(oslcDomain))
                    {
                        CreationFactory [] creationFactories = service.GetCreationFactories();
                        if (creationFactories != null && creationFactories.Length > 0)
                        {
                            foreach (CreationFactory creationFactory in creationFactories)
                            {
                                foreach (Uri resourceType in creationFactory.GetResourceTypes())
                                {
                                    if (resourceType.ToString() != null && resourceType.ToString().Equals(oslcResourceType))
                                    {
                                        Uri[] instanceShapes = creationFactory.GetResourceShapes();
                                        if (instanceShapes != null)
                                        {
                                            foreach (Uri typeURI in instanceShapes)
                                            {
                                                response = client.GetResource(typeURI.ToString(), OSLCConstants.CT_RDF);
                                                ResourceShape resourceShape = response.Content.ReadAsAsync <ResourceShape>(formatters).Result;
                                                string        typeTitle     = resourceShape.GetTitle();
                                                if ((typeTitle != null) && (string.Compare(typeTitle, requiredInstanceShape, true) == 0))
                                                {
                                                    return(resourceShape);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            throw new ResourceNotFoundException(serviceProviderUrl, "InstanceShapes");
        }