static ResourceMapManager() { entryComparer = new ResourceEntryComparer(); mappingCache = new Dictionary<int, ResourceMapping>(); mapKeyCache = new Dictionary<ResourceMappingEntry, List<int>>(); BrokerDB db = new BrokerDB(); List<ResourceMapping> list = db.RetrieveResourceMapping(); if (list != null && list.Count > 0) { Add(list); } needsRefresh = false; }
/// <summary> /// performs whatever actions including GUI interaction to identify and authenticate the user who has initiated the current session /// </summary> /// <param name="userName">the local of user</param> /// <param name="authGuid">an optional authority guid, if empty use local pasword</param> /// <param name="password">the user's password</param> /// <returns>true if the user has been authenticated; false otherwise</returns> public static bool Authenticate(string userName, string authGuid, string password) { BrokerDB brokerDB = new BrokerDB(); Authority auth = null; bool status = false; int userID = -1; if (authGuid != null && authGuid.Length > 0) { auth = brokerDB.AuthorityRetrieve(authGuid); } else{ auth = brokerDB.AuthorityRetrieve(0); } if(auth != null){ userID = InternalAdminDB.SelectUserID(userName,auth.authorityID); if (auth.authorityID == 0 && auth.authTypeID == 1) //Test for local authentication { string hashedDBPassword = InternalAuthenticationDB.ReturnNativePassword(userID); if (hashedDBPassword != null && hashedDBPassword.Length > 0) { string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1"); if (hashedPassword == hashedDBPassword) { status = true; } } } else { // For now accept third party authentication if(userID > 0) status = true; } } return status; }
public static Ticket GetAuthenticateAgentTicket(string authGuid, string passkey) { Ticket authTicket = null; BrokerDB brokerDB = new BrokerDB(); Coupon[] authCoupons = brokerDB.GetIssuedCoupons(passkey); if (authCoupons != null && authCoupons.Length > 0) { authTicket = brokerDB.RetrieveTicket(authCoupons[0], TicketTypes.AUTHENTICATE_AGENT); if (authTicket == null || authTicket.sponsorGuid.CompareTo(authGuid) != 0) { //TODO: Parse Ticket throw new AccessDeniedException("AccessDenied!"); } } return authTicket; }
protected void On_BlobSelected(object sender, GridViewCommandEventArgs e) { lblResponse.Visible = false; if (Session["EssGuid"] != null) { long blobId = Convert.ToInt64(e.CommandArgument); BrokerDB brokerDB = new BrokerDB(); ProcessAgentInfo ess = brokerDB.GetProcessAgentInfo(Session["EssGuid"].ToString()); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = brokerDB.GetEssOpCoupon(Convert.ToInt64(txtExperimentID.Text), TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; string url = essProxy.RequestBlobAccess(blobId, "http", 30); if (url != null) { string jScript = "<script language='javascript'>" + "window.open('" + url + "')" + "</script>"; //Page.RegisterStartupScript("Open New Window", jScript); ClientScript.RegisterClientScriptBlock(this.GetType(), "Open New Window", jScript); //Response.Redirect(url); } else{ lblResponse.Text = Utilities.FormatWarningMessage("Could not access BLOB. "); lblResponse.Visible = true; } } } else { lblResponse.Text = Utilities.FormatWarningMessage("No ESS is specified, so no records. "); lblResponse.Visible = true; } }
protected void displayRecords(long experimentId, string essGuid) { BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; ExperimentRecord[] records = essProxy.GetRecords(experimentId,null); if (records != null) { StringBuilder buf = null; if (cbxContents.Checked) { buf = new StringBuilder(); foreach (ExperimentRecord rec in records) { buf.AppendLine(rec.contents); } txtExperimentRecords.Text = buf.ToString(); txtExperimentRecords.Visible = true; grvExperimentRecords.Visible = false; } else { dtRecords = new DataTable(); dtRecords.Columns.Add("Seq_Num", typeof(System.Int32)); dtRecords.Columns.Add("Record Type", typeof(System.String)); dtRecords.Columns.Add("Contents", typeof(System.String)); foreach (ExperimentRecord rec in records) { DataRow recTmp = dtRecords.NewRow(); recTmp["Seq_Num"] = rec.sequenceNum; recTmp["Record Type"] = rec.type; recTmp["Contents"] = rec.contents; dtRecords.Rows.InsertAt(recTmp, dtRecords.Rows.Count); } grvExperimentRecords.DataSource = dtRecords; grvExperimentRecords.DataBind(); grvExperimentRecords.Visible = true; txtExperimentRecords.Visible = false; } divRecords.Visible = true; } Blob[] blobs = essProxy.GetBlobs(experimentId); if (blobs != null) { dtBlobs = new DataTable(); dtBlobs.Columns.Add("Blob_ID", typeof(System.Int64)); dtBlobs.Columns.Add("Seq_Num", typeof(System.Int32)); dtBlobs.Columns.Add("MimeType", typeof(System.String)); dtBlobs.Columns.Add("Description", typeof(System.String)); foreach (Blob b in blobs) { DataRow blobTmp = dtBlobs.NewRow(); blobTmp["Blob_ID"] = b.blobId; blobTmp["Seq_Num"] = b.recordNumber; blobTmp["MimeType"] = b.mimeType; blobTmp["Description"] = b.description; dtBlobs.Rows.InsertAt(blobTmp, dtBlobs.Rows.Count); } grvBlobs.DataSource = dtBlobs; grvBlobs.DataBind(); divBlobs.Visible = true; } } }
public static int Refresh() { int count = 0; mappingCache.Clear(); mapKeyCache.Clear(); BrokerDB db = new BrokerDB(); List<ResourceMapping> list = db.RetrieveResourceMapping(); if (list != null && list.Count > 0) { Add(list); count = list.Count; } needsRefresh = false; return count; }
private void reenterLabClient() { if (Session["UserID"] == null) { Response.Redirect("login.aspx"); } BrokerDB brokerDB = new BrokerDB(); StringBuilder message = new StringBuilder("Message: clientID = "); int[] labIds = new int[1]; message.Append(btnReenter.CommandArgument + " "); long expid = Convert.ToInt64(btnReenter.CommandArgument); LabClient client = AdministrativeAPI.GetLabClient(Convert.ToInt32(Session["ClientID"])); if (client.clientID > 0) { if (client.clientType == LabClient.INTERACTIVE_HTML_REDIRECT) { long[] coupIDs = InternalDataDB.RetrieveExperimentCouponIDs(expid); Coupon coupon = brokerDB.GetIssuedCoupon(coupIDs[0]); // construct the redirect query StringBuilder url = new StringBuilder(client.loaderScript.Trim()); if (url.ToString().IndexOf("?") == -1) url.Append('?'); else url.Append('&'); url.Append("coupon_id=" + coupon.couponId + "&passkey=" + coupon.passkey + "&issuer_guid=" + brokerDB.GetIssuerGuid()); // Add the return url to the redirect url.Append("&sb_url="); url.Append(Utilities.ExportUrlPath(Request.Url)); // Now open the lab within the current Window/frame Response.Redirect(url.ToString(), true); } } }
protected void lbxSelectExperiment_SelectedIndexChanged(object sender, System.EventArgs e) { clearExperimentDisplay(); long experimentID = Int64.Parse(lbxSelectExperiment.Items[lbxSelectExperiment.SelectedIndex].Value); try { ExperimentSummary[] expInfo = wrapper.GetExperimentSummaryWrapper(new long[] { experimentID }); if (expInfo[0] != null) { txtExperimentID.Text = expInfo[0].experimentId.ToString(); txtUsername.Text = expInfo[0].userName; txtGroupName.Text = expInfo[0].groupName; txtLabServerName.Text = expInfo[0].labServerName; txtClientName.Text = expInfo[0].clientName; //Check if update needed from the ESS if one is used if (expInfo[0].essGuid != null) { int expStatus = expInfo[0].status; if ((expStatus == StorageStatus.UNKNOWN || expStatus == StorageStatus.INITIALIZED || expStatus == StorageStatus.OPEN || expStatus == StorageStatus.REOPENED || expStatus == StorageStatus.RUNNING || expStatus == StorageStatus.BATCH_QUEUED || expStatus == StorageStatus.BATCH_RUNNING || expStatus == StorageStatus.BATCH_TERMINATED || expStatus == StorageStatus.BATCH_TERMINATED_ERROR)) { // This operation should happen within the Wrapper BrokerDB ticketIssuer = new BrokerDB(); ProcessAgentInfo ess = ticketIssuer.GetProcessAgentInfo(expInfo[0].essGuid); if (ess == null || ess.retired) { throw new Exception("The ESS is not registered or is retired"); } Coupon opCoupon = ticketIssuer.GetEssOpCoupon(expInfo[0].experimentId, TicketTypes.RETRIEVE_RECORDS, 60, ess.agentGuid); if (opCoupon != null) { ExperimentStorageProxy essProxy = new ExperimentStorageProxy(); OperationAuthHeader header = new OperationAuthHeader(); header.coupon = opCoupon; essProxy.Url = ess.webServiceUrl; essProxy.OperationAuthHeaderValue = header; StorageStatus curStatus = essProxy.GetExperimentStatus(expInfo[0].experimentId); if (expInfo[0].status != curStatus.status || expInfo[0].recordCount != curStatus.recordCount || expInfo[0].closeTime != curStatus.closeTime) { DataStorageAPI.UpdateExperimentStatus(curStatus); expInfo[0].status = curStatus.status; expInfo[0].recordCount = curStatus.recordCount; expInfo[0].closeTime = curStatus.closeTime; } } } } txtStatus.Text = DataStorageAPI.getStatusString(expInfo[0].status); txtSubmissionTime.Text = DateUtil.ToUserTime(expInfo[0].creationTime, culture, userTZ); if ((expInfo[0].closeTime != null) && (expInfo[0].closeTime != DateTime.MinValue)) { txtCompletionTime.Text = DateUtil.ToUserTime(expInfo[0].closeTime, culture, userTZ); } else { txtCompletionTime.Text = "Experiment Not Closed!"; } txtRecordCount.Text = expInfo[0].recordCount.ToString(" 0"); txtAnnotation.Text = expInfo[0].annotation; //trSaveAnnotation.Visible = true; //trDeleteExperiment.Visible = true; //trShowExperiment.Visible = (expInfo[0].recordCount > 0); } } catch (Exception ex) { lblResponse.Text = Utilities.FormatErrorMessage("Error retrieving experiment information. " + ex.Message); lblResponse.Visible = true; } }
public ClientSubmissionReport Submit(string labServerID, string experimentSpecification, int priorityHint, bool emailNotification) { // Default to 24 hours duration long duration = TimeSpan.TicksPerDay / TimeSpan.TicksPerSecond; int seqNo = 0; ClientSubmissionReport clientSReport = null; try { // Checking if user has permission to use the lab server. The method will set headers for lab server calls //if authorization is successful. CheckAndSetLSAuthorization(labServerID); //Retrieve variables from session int userID = Convert.ToInt32(Session["UserID"]); int effectiveGroupID = Convert.ToInt32(Session["GroupID"]); int clientID = 0; if (Session["ClientID"] != null) clientID = Convert.ToInt32(Session["ClientID"]); string effectiveGroup = Session["GroupName"].ToString(); ProcessAgentInfo infoLS = dbTicketing.GetProcessAgentInfo(labServerID); if (infoLS.retired) { throw new Exception("The Batch Lab Server is retired"); } // get qualifier ID of labServer int qualifierID = AuthorizationAPI.GetQualifierID(infoLS.agentId, Qualifier.labServerQualifierTypeID); /* End collecting information */ // Checking if user has permission to use the lab server if (!AuthorizationAPI.CheckAuthorization(userID, Function.useLabServerFunctionType, qualifierID)) { // check fails throw new AccessDeniedException("Access denied using labServer '" + infoLS.agentName + "'."); } else { int[] groupIDs = new int[1]; groupIDs[0] = effectiveGroupID; SubmissionReport sReport = new SubmissionReport(); clientSReport = new ClientSubmissionReport(); clientSReport.vReport = new ValidationReport(); clientSReport.wait = new WaitEstimate(); BrokerDB brokerDB = new BrokerDB(); // 1. Create Coupon for ExperimentCollection Coupon coupon = brokerDB.CreateCoupon(); int essID = brokerDB.FindProcessAgentIdForClient(clientID, ProcessAgentType.EXPERIMENT_STORAGE_SERVER); // // 2. create ServiceBroker experiment record and get corresponding experiment id // This checks authorization. long experimentID = wrapper.CreateExperimentWrapper(StorageStatus.INITIALIZED, userID, effectiveGroupID, infoLS.agentId, clientID, essID, DateTime.UtcNow, duration); // Store a record of the Experiment Collection Coupon DataStorageAPI.InsertExperimentCoupon(experimentID, coupon.couponId); //3.A create ESS administer experiment ticket, Add 10 minutes to duration // This must be created before the ESS experiment records may be created ProcessAgentInfo essAgent = brokerDB.GetProcessAgentInfo(essID); if (essAgent.retired) { throw new Exception("The Batch Lab Server is retired"); } TicketLoadFactory factory = TicketLoadFactory.Instance(); brokerDB.AddTicket(coupon, TicketTypes.ADMINISTER_EXPERIMENT, essAgent.AgentGuid, ProcessAgentDB.ServiceGuid, duration, factory.createAdministerExperimentPayload(experimentID, essAgent.webServiceUrl)); //3.B create store record ticket, in the MergedSB the records are all saved via the serviceBroker brokerDB.AddTicket(coupon, TicketTypes.STORE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, duration, factory.StoreRecordsPayload(true, experimentID, essAgent.webServiceUrl)); //3.C create retrieve experiment ticket, retrieve Experiment Records never expires, unless experiment deleted // This should be changed to a long but finite period once eadExisting Expermint is in place. brokerDB.AddTicket(coupon, TicketTypes.RETRIEVE_RECORDS, essAgent.agentGuid, ProcessAgentDB.ServiceGuid, -1, factory.RetrieveRecordsPayload(experimentID, essAgent.webServiceUrl)); // 3.D Create the ESS Experiment Records ExperimentStorageProxy ess = new ExperimentStorageProxy(); ess.AgentAuthHeaderValue = new AgentAuthHeader(); ess.AgentAuthHeaderValue.coupon = essAgent.identOut; ess.AgentAuthHeaderValue.agentGuid = ProcessAgentDB.ServiceGuid; ess.OperationAuthHeaderValue = new OperationAuthHeader(); ess.OperationAuthHeaderValue.coupon = coupon; ess.Url = essAgent.webServiceUrl; // Call the ESS to create the ESS Records and open the experiment StorageStatus status = ess.OpenExperiment(experimentID, duration); if (status != null) DataStorageAPI.UpdateExperimentStatus(status); seqNo = ess.AddRecord(experimentID, ProcessAgentDB.ServiceGuid, BatchRecordType.SPECIFICATION, true, experimentSpecification, null); // save lab configuration string labConfiguration = batchLS_Proxy.GetLabConfiguration(effectiveGroup); seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.LAB_CONFIGURATION, true, labConfiguration, null); // call labServer submit sReport = batchLS_Proxy.Submit(Convert.ToInt32(experimentID), experimentSpecification, effectiveGroup, priorityHint); // save submission report //wrapper.SaveSubmissionReportWrapper(experimentID, sReport); if (sReport.vReport != null) if ((sReport.vReport.errorMessage != null) && (sReport.vReport.errorMessage.CompareTo("") != 0)) { seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_ERROR, false, sReport.vReport.errorMessage, null); } if (sReport.vReport.warningMessages != null) foreach (string s in sReport.vReport.warningMessages) { if ((s != null) && (s.CompareTo("") != 0)) seqNo = ess.AddRecord(experimentID, labServerID, BatchRecordType.VALIDATION_WARNING, false, s, null); } // return clientSubmissionReport if (sReport.vReport != null) { clientSReport.vReport.accepted = sReport.vReport.accepted; clientSReport.vReport.errorMessage = sReport.vReport.errorMessage; // if error exists then change status to "an experiment with a problem" if ((sReport.vReport.errorMessage != null) && (!sReport.vReport.errorMessage.Equals(""))) { StorageStatus sStatus = new StorageStatus(); sStatus.experimentId = experimentID; //sStatus.estRuntime=sReport.vReport.estRuntime; sStatus.status = StorageStatus.BATCH_TERMINATED_ERROR; DataStorageAPI.UpdateExperimentStatus(sStatus); } clientSReport.vReport.estRuntime = sReport.vReport.estRuntime; clientSReport.vReport.warningMessages = sReport.vReport.warningMessages; } clientSReport.experimentID = Convert.ToInt32(experimentID); clientSReport.minTimeToLive = sReport.minTimetoLive; if (sReport.wait != null) { clientSReport.wait.effectiveQueueLength = sReport.wait.effectiveQueueLength; clientSReport.wait.estWait = sReport.wait.estWait; } } return clientSReport; } catch { throw; } }