Set AttributeConsumingService index? - asp.net

I'am doing an connection to IDP with sustainsys SAML2 with the Saml2AuthenticationModule and Sustainsys.Saml2.HttpModule
Since I want metadata returned I need to set
AttributeConsumingService index from 0(default) to 1.
Tried to find ways to change it without success. Anyone knows how?
<AttributeConsumingService index="0" isDefault="true">
<ServiceName xml:lang="en">SP</ServiceName>
<RequestedAttribute isRequired="true" Name=...
...

You can configure the value in Startup.cs
.AddSaml2("IDP", "IDP", opt =>
{
opt.SPOptions = new Sustainsys.Saml2.Configuration.SPOptions
{
EntityId = new EntityId(ipdUrl),
ReturnUrl = new Uri(webSiteUrl),
ModulePath = string.Format("/saml2/{0}", "idp"),
AuthenticateRequestSigningBehavior = SigningBehavior.Always,
MinIncomingSigningAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
};
RequestedAttribute requestedAttributeEmail = new RequestedAttribute("email");
requestedAttributeEmail.FriendlyName = "Email";
requestedAttributeEmail.NameFormat = RequestedAttribute.AttributeNameFormatBasic;
requestedAttributeEmail.IsRequired = false;
AttributeConsumingService attributeConsumingService = new AttributeConsumingService();
attributeConsumingService.RequestedAttributes.Add(requestedAttributeEmail);
attributeConsumingService.ServiceNames.Add(new LocalizedName("Required attributes", "en"));
attributeConsumingService.IsRequired = true;
attributeConsumingService.Index = 1;
attributeConsumingService.IsDefault = true;
opt.SPOptions.AttributeConsumingServices.Add(attributeConsumingService);
});

Related

Npgsql passing an array of parameters

I am new in using Npgsql and I tried to make an helper in my asp.net project so that I can call it conveniently in my controllers method.
npgsqlqueryhelper
public DataSet ExecuteQueryWithParams(string commandText, params NpgsqlParameter[] parameters)
{
using (var connection = npgsqlcon.GetnpgsqlConnection())
using (NpgsqlCommand command = new NpgsqlCommand(commandText, connection))
{
DataSet ds = new DataSet();
command.Parameters.AddRange(parameters);
command.CommandTimeout = 5000;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(command);
da.Fill(ds);
connection.Close();
return ds;
}
}
My Controller Method
List<rollingPAR> rollingparlist = new List<rollingPAR>();
npgsqlhelper = new npgsqlQueryHelper();
NpgsqlParameter[] parameterList = {
new NpgsqlParameter("#lid", r.lid),
new NpgsqlParameter("#posting_date", r.date_end)
};
var table = npgsqlhelper.ExecuteQueryWithParams("SELECT ln.get_payment_status()", parameterList).Tables[0];
rollingparlist = table.AsEnumerable().Select(row => new rollingPAR
{
get_payment_status = row.Field<int>("get_payment_status")
}).ToList();
As I tried to run my program, I always encountered an error saying that function ln.get_payment_status() does not exist but when I tried to supply the parameters directly on the query
(e.g var table = npgsqlhelper.ExecuteQueryWithParams("SELECT ln.get_payment_status(1231,'06-18-2019')", parameterList).Tables[0];)
It gives me the data that I need. I don't know what is my mistake and I'm stuck here since yesterday. Can anyone help me with this? TIA
The parameter place holders are not automatically included in the function call. Try adding them:
var table = npgsqlhelper.ExecuteQueryWithParams("SELECT ln.get_payment_status(#lid,#posting_date)", parameterList).Tables[0];
With the help of Sir #JGH, it turns out that my query is missing the parameter placeholders but after I edit it, I encountered an error regarding the datatype between the asp.net datetime and postgresql date so I added this code to remove the error.
parameterList[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Date;
So here is now the new code:
List<rollingPAR> rollingparlist = new List<rollingPAR>();
npgsqlhelper = new npgsqlQueryHelper();
NpgsqlParameter[] parameterList = {
new NpgsqlParameter("#lid", r.lid),
new NpgsqlParameter("#posting_date", r.date_end)
};
parameterList[1].NpgsqlDbType = NpgsqlTypes.NpgsqlDbType.Date;
var table = npgsqlhelper.ExecuteQueryWithParams("SELECT ln.get_payment_status(#lid,#posting_date)", parameterList).Tables[0];
rollingparlist = table.AsEnumerable().Select(row => new rollingPAR
{
get_payment_status = row.Field<int?>("get_payment_status")
}).ToList();
Thank you sir #JGH

ASP.NET & SQL Server: won't update but will append/insert

I am using a database-first approach with a custom html helper to get a state of a checkbox using ajax (without using form in the view). I have two tables:
Tbl_1 -> Id, state (true or false), name (name of checkbox)
Tbl_2 -> Id, user_guid, timestamp, Tbl_1Id (foreign_key)
When I do insert operations, it does without any problem but when I try to update it (based upon the logged in user as it also gets GUID, the table gets appended/inserted with new data).
My controller:
public ActionResult SetState(checkboxstate cbstate)
{
var UserId = new Guid(System.Security.Claims.ClaimsPrincipal.Current.FindFirst("sub").Value);
var ent = new StartopDatabaseEntities();
var cbs = ent.checkboxstates.Where(w => w.Name == "World").FirstOrDefault();
if (cbs == null) // when there are no records in the database
{
ent.checkboxstates.Add(cbstate);
ent.checkboxstateUpdates.SingleOrDefault(c => c.Id == cbstate.Id);
var cbsOp = new checkboxstateUpdates();
cbsOp.timestamp = DateTime.Now;
cbsOp.user_guid = UserId;
cbstate.checkboxstateUpdates.Add(cbsOp);
ent.SaveChanges();
} // record in database, update (I've only one user now, so has to update only this one)
else
{
var cbsOp = new checkboxstateUpdates(); // declare in global
var chc = new checkboxstate(); // to be declared in global
var newCbs = ent.checkboxstateUpdates.Include(c => c.checkboxstate).ToList();
foreach (var u in newCbs)
{
if(u.user_guid==UserId && u.CheckboxStateId == u.checkboxstate.Id)
{
chc.state = cbstate.state;
chc.name = cbstate.name;
ent.checkboxstates.Add(chc);
cbsOp.Tidspunkt = DateTime.Now;
cbsOp.OpdateretAfBruger = UserId;
ent.checkboxstateUpdates.Add(cbsOp);
ent.SaveChanges();
}
}
}
Can anyone explain please why it's not updating but appending/inserting same data with a new Id (primary key)? I have a simple view where Ajax sends a call to the controller with the state and name of the checkbox. I have also tried
Db.Entry(obj).state = EntityState.Modified
without any help
You have not written the code for the logic which want to achieve..
I am not clear on the logic of if block also but the else part can be fixed as following.
var newCbs = ent.checkboxstateUpdates.Include(c => c.checkboxstate).Where(u.user_guid == UserId).FirstOrDefault();
if(newCbs != null) {
newCbs.checkboxstate.state = cbstate.state;
newCbs.checkboxstate.name = cbstate.name;
newCbs.Tidspunkt = DateTime.Now;
newCbs.OpdateretAfBruger = UserId;
ent.SaveChanges();
}
Solved this with the help from #David & #Chetan:
I did some modify in the code as per David:
u.checkboxstate.state=cbstate.state;
u.checkboxstate.name=cbstate.name;
u.timestamp=DateTime.Now;
ent.saveChanges();
I was using the wrong logic i.e. getting instance of the class rather than the 'ent' object. Thanks guys for the help.

Cancel a complete PNR

I'm writing a service which automtically cancels a PNR left on a certain queue. This sounds pretty straight forward with the OTA_CancelLLSRQ request, however it appears I have to loop through each segment individually, or is there a way I can cancell ALL segments at once?
In the application we defined a PNR class, this class contains all of the information we can obtain with the "" call.
To cancel the PNR I currently use the following code:
MessageHeader msgHeader = new MessageHeader
{
ConversationId = "TestSession",
CPAId = licenseId,
Action = "OTA_CancelLLSRQ",
Service = new Service { Value = "OTA_CancelLLSRQ" },
MessageData = new MessageData
{
MessageId = "xxx",
Timestamp = DateTime.UtcNow.ToString("s") + "Z"
},
From = new From()
{
PartyId = new PartyId[]
{
new PartyId { Value = "WebServiceClient"}
}
},
To = new To()
{
PartyId = new[]
{
new PartyId { Value = "WebServiceSupplier"}
}
}
};
var segmentList = new List<OTA_CancelRQSegment>();
foreach (var segment in pnrObject.Segments)
{
var requestSegment = new OTA_CancelRQSegment
{
Number = segment.SegmentNumber.ToString()
};
segmentList.Add(requestSegment);
}
var request = new OTA_CancelRQ()
{
Version = "2.0.0",
TimeStamp = DateTime.UtcNow,
TimeStampSpecified = true,
Segment = segmentList.ToArray()
};
OTA_CancelRS response = null;
Policy.Handle<SoapException>()
.Or<WebException>()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1)
})
.Execute(() =>
{
using (OTA_CancelService serviceObj = new OTA_CancelService())
{
serviceObj.MessageHeaderValue = msgHeader;
serviceObj.Security = new Security1 { BinarySecurityToken = token };
response = serviceObj.OTA_CancelRQ(request);
}
});
It compiles & builds, but I haven't gotten around testing it just yet. :-)
In the documentation I found the following request:
<OTA_CancelRQ Version="2.0.0">
<Segment Type="entire"/>
</OTA_CancelRQ>
How do I encode this using the object model the webservice expects?
Steps for cancelling PNR is as follows.
STEP1: SessionCreateRQ
STEP2: TravelItineraryReadRQ
STEP3: OTA_CancelRQ
STEP4: EndTransactionRQ
STEP5: SessionCloseRQ
In case of SOAP SERVICES your request XML for STEP3 (i.e OTA_CancelRQ)will be as follows.
<OTA_CancelRQ EchoToken="String" TimeStamp="2001-12-17T09:30:47-05:00" Target="Production" Version="2003A.TsabreXML1.0.1" SequenceNmbr="1" PrimaryLangID="en-us" AltLangID="en-us" xmlns="http://webservices.sabre.com/sabreXML/2003/07" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<POS>
<Source PseudoCityCode="PCC"/>
</POS>
<TPA_Extensions>
<SegmentCancel Type="Entire">
</SegmentCancel>
</TPA_Extensions>
</OTA_CancelRQ>
I hope this will make your knowledge more clear.
You can specify "entire" type like the below to cancel the entire Itinerary of a PNR.
<OTA_CancelRQ Version="2.0.0">
<Segment Type="entire"/>
</OTA_CancelRQ>
here is the request part of my code in c#, hope this help add a refrence to proxy class for OTA_CancelRQ.
OTA_CancelRQ rq = new OTA_CancelRQ();
List<OTA_CancelRQSegment> segmentCancelList = new List<OTA_CancelRQSegment>();
OTA_CancelRQSegment segmentCancel = new OTA_CancelRQSegment();
OTA_CancelRQSegmentType segmentType = new OTA_CancelRQSegmentType();
segmentType = OTA_CancelRQSegmentType.entire;
segmentCancel.Type = segmentType;
segmentCancel.TypeSpecified = true;
segmentCancelList.Add(segmentCancel);
rq.Segment = segmentCancelList.ToArray();
Thanks.
cancelRQ.tPA_ExtensionsField = new CancelRequest.TPA_Extensions
{
segmentCancelField = new CancelRequest.TPA_Extensions.SegmentCancel
{
typeField = "Entire"
}
};
call OTA_CancelLLSRQ Perform a transaction after the original booking was completed (cancel the itinerary that was booked, in this case).

ASP.NET Bind and Query LDAP

So I have been driving myself crazy trying to figure out why I can't get my LDAP search to work.
private String getDNFromLDAP(String strUID)
{
String strDN = "";
//Create an LDAP Entry Object
DirectoryEntry entry = new DirectoryEntry("LDAP://something.blah.com/cn=people,dc=blah,dc=com");
entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer;
entry.Username = "cn=myaccount,cn=special,dc=blah,dc=com";
entry.Password = "supersecret";
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.SearchScope = SearchScope.Subtree;
mySearcher.Filter = "(uid=" + strUID + ")";
SearchResult result = mySearcher.FindOne();
int nIndex = result.Path.LastIndexOf("/");
strDN = result.Path.Substring((nIndex + 1)).ToString().TrimEnd();
//Clean up objects
entry.Close();
entry.Dispose();
mySearcher.Dispose();
//returns the DN
return strDN;
}
I know the object I am searching for exist (confirmed with ldapsearch), but my result keeps coming back empty. I suspect there is an issue with the base dn, but I don't know how to confirm what what DirectorySearch is using as the base dn. Any help at all would be appreciated.
You set the root using the searchroot property. The root is set to entry you pass on the constructor, so this might be why you can't find your entry.

ckfinder wont recognize role?

if somebody could help with this please.
I am trying to incorporate ckeditor and ckfinder to an Asp.Net Mvc 1 project. SO far everything is working fine. The only thing I cann't get to work right is the Access Control for ckfinder.
For what I understand, in the file ckfinder/config.ascx, the variable string RoleSessionVar is used to assign the role to be restricted. The default value is:
RoleSessionVar = "CKFinder_UserRole";
I have tree roles in my project Administrators, Editors and Contributors. So in order to get my current user Role I replace it for:
string currentRole= "";
if(HttpContext.Current.User.IsInRole("Administrators"))
{
currentRole = "Administrators";
}
else
{
if (HttpContext.Current.User.IsInRole("Editors"))
currentRole = "Editors";
else
{
if (HttpContext.Current.User.IsInRole("Contributors"))
{
currentRole = "Contributors";
}
}
}
RoleSessionVar = currentRole;
The variable gets assigned with the correct Role for the current user. The next part in the config.ascx file are the ACL settings. The default one are:
AccessControl acl = AccessControl.Add();
acl.Role = "*";
acl.ResourceType = "*";
acl.Folder = "/";
acl.FolderView = true;
acl.FolderCreate = true;
acl.FolderRename = true;
acl.FolderDelete = true;
acl.FileView = true;
acl.FileUpload = true;
acl.FileRename = true;
acl.FileDelete = true;
With these settings there are not any problems the ckfinder, it lists all the folders and files, but there with full permissions for everyone. I want to restrict deleting permissions to different Roles. Anyway just as a test I tried to give full permissions to Administrators' Role
AccessControl acl = AccessControl.Add();
acl.Role = "Administrators";
acl.ResourceType = "*";
acl.Folder = "/";
acl.FolderView = true;
acl.FolderCreate = true;
acl.FolderRename = true;
acl.FolderDelete = true;
acl.FileView = true;
acl.FileUpload = true;
acl.FileRename = true;
acl.FileDelete = true;
But ckfinder will not show any folder or file even though RoleSessionVar = "Administrators".
I'll be very thankful for any ligh to the solution of this problem.
Byron
You need to do
Session["RoleSessionVar"] = currentRole;
you should try:
Session["CKFinder_UserRole"] = currentRole;

Resources