I'm trying to create a new user using the CoSign SPML WS.
The code I'm using (C#.NET) is below. Can someone please let me know if the PSOIdentifierType.ID is correct (i.e. "The ID of the User") and what should the Target ID be, I think it should be blank as the user does not exist yet.
private const readonly string addTargetDB = "CoSignDB";
public void CreateBasicUser(string userName, string userLoginName, string userPassword, string userCN, string userEmail)
{
SPMLSoapClient client = new SPMLSoapClient();
AddRequestType request = new AddRequestType();
PSOIdentifierType psoCreationType = new PSOIdentifierType();
psoCreationType.ID = userName;
psoCreationType.targetID = ""; //The parameter that was returned in the ListTargets operation
UserRecord newUserRecord = new UserRecord();
newUserRecord.UserLoginName = userLoginName;
newUserRecord.Password = userPassword;
newUserRecord.UserCN = userCN;
newUserRecord.EmailAddress = userEmail;
newUserRecord.RightsMask = (uint)1; // 1 - User
newUserRecord.UserKind = UserKindEnum.User;
request.returnData = ReturnDataType.everything;
request.targetID = addTargetDB;
request.psoID = psoCreationType;
request.UserRecord = newUserRecord;
AddResponseType clientAddResponse = client.add(request);
if(clientAddResponse.status == StatusCodeType.success)
{
// OK
}
else if(clientAddResponse.status == StatusCodeType.failure)
{
// Fail
}
}
The id of the user is correct (it should be the username) and the TargetID should be "CoSignDB"
Related
My requirement is to create a customer location part of downloading order from 3rd party shopping cart.
I have tried this below code and It is not saving any location and also not raising any error.
private static void CreateCustomerLocation(Customer cust, string locationcode, OrderDTO ord, OrderDownloadActivityEntry grp)
{
try
{
LocationMaint graph = CustomerLocationMaint.CreateInstance<CustomerLocationMaint>();
SelectedLocation loc = new SelectedLocation();
loc.BAccountID = cust.BAccountID;
loc.LocationCD = locationcode;
loc.Descr = ord.CustomerLocationName;
loc.IsContactSameAsMain = false;
loc.IsAddressSameAsMain = false;
graph.Location.Insert(loc);
Contact contact = new Contact();
contact.Attention = ord.OrderCustomerContactName;
contact.Phone1 = ord.OrderCustomerContactPhone;
contact.DisplayName = ord.CustomerLocationName;
contact.LastName = ord.OrderCustomerContactName;
contact = graph.Contact.Update(contact);
Address address = new Address();
address.AddressLine1 = ord.OrderShippingLocationAddress1;
address.AddressLine2 = ord.OrderShippingLocationAddress2;
address.City = ord.OrderShippingLocationCity;
address.State = ord.OrderShippingLocationState;
address.PostalCode = ord.OrderShippingLocationZip;
address.CountryID = "US";
contact = graph.Contact.Update(contact);
address = graph.Address.Update(address);
loc.DefAddressID = address.AddressID;
loc.DefContactID = contact.ContactID;
graph.Location.Update(loc);
graph.Save.Press();
}
catch(Exception e)
{
grp.AddLogData(SessionID, "Create Location", "Create Location falied", null, null, e.StackTrace);
}
}
I am not able to figure out where i am making mistake. any suggestion for this issue?
Update
I have tried the following code and I am getting the following error
CARAccountLocationID' cannot be empty.
private static void CreateCustomerLocation(Customer cust, string locationcode, OrderDTO ord, OrderDownloadActivityEntry grp)
{
try
{
LocationMaint graph = PXGraph.CreateInstance<CustomerLocationMaint>();
graph.BusinessAccount.Current = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>.Select(graph, cust.BAccountID);
var newLocation = (Location)graph.Location.Cache.CreateInstance();
var locType = LocTypeList.CustomerLoc;
newLocation.LocType = locType;
graph.Location.Insert(newLocation);
var loc = (Location)graph.Location.Cache.CreateCopy(graph.Location.Current);
Contact contact = graph.Contact.Cache.CreateCopy(graph.Contact.Current) as Contact;
contact.Attention = ord.OrderCustomerContactName;
contact.Phone1 = ord.OrderCustomerContactPhone;
contact.DisplayName = ord.CustomerLocationName;
contact.LastName = ord.OrderCustomerContactName;
contact = graph.Contact.Update(contact);
Address address = graph.Address.Cache.CreateCopy(graph.Address.Current) as Address;
address.AddressLine1 = ord.OrderShippingLocationAddress1;
address.AddressLine2 = ord.OrderShippingLocationAddress2;
address.City = ord.OrderShippingLocationCity;
address.State = ord.OrderShippingLocationState;
address.PostalCode = ord.OrderShippingLocationZip;
address.CountryID = "US";
contact = graph.Contact.Update(contact);
address = graph.Address.Update(address);
contact.DefAddressID = address.AddressID;
loc.IsAddressSameAsMain = false;
loc.IsContactSameAsMain = false;
loc.IsAPAccountSameAsMain = true;
loc.IsAPPaymentInfoSameAsMain = true;
loc.IsARAccountSameAsMain = true;
loc.LocationCD = locationcode;
loc.Descr = ord.CustomerLocationName;
loc = graph.Location.Update(loc);
loc.BAccountID = cust.BAccountID;
graph.Location.Cache.RaiseFieldUpdated<Location.isARAccountSameAsMain>(loc, null);
if (loc.CARAccountLocationID == null)
loc.CARAccountLocationID = cust.DefLocationID;
graph.Location.Update(loc);
graph.Save.Press();
}
catch(Exception e)
{
grp.AddLogData(SessionID, "Create Location", "Create Location falied", null, null, e.StackTrace);
}
}
CARAccountLocationID is the LocationID of the MAIN location for a given BAccount/Customer. It is used by the business logic when setting GLAccounts.SameAsDefaultLocationS on screen AR303020.
I've seen the "'CARAccountLocationID' cannot be empty." error when creating a location without first setting the Customer.
The resolution was to first set the customer, then set SameAsDefaultLocationS, then set the rest of the fields.
In the screen API order of operations matters.
In your case you might need to directly set loc.CARAccountLocationID to the LocationID of the customer's MAIN location.
I have a free DocuSign Signature Appliance Developer Sandbox account.I want to use "https://prime.cosigntrial.com:8080/SAPIWS/dss.asmx" and wan to use DssSign service method to create and attach signature to pdf.But it reutrn "urn:oasis:names:tc:dss:1.0:resultmajor:ResponderError".Please help how can I get username and password to create a new signature programmatically and assign to a pdf using DocuSign API
I already download the code samples found Git "docusign-signature-appliance-api-recipes-master" but can not sucess.
//Sign PDF file
public bool SignPDFFile(
string FileToSign,
string UserName,
string Password,
int X,
int Y,
int Width,
int Height,
int Page,
bool isVisible)
{
//Create Request object contains signature parameters
RequestBaseType Req = new RequestBaseType();
Req.OptionalInputs = new RequestBaseTypeOptionalInputs();
//Here Operation Type is set: Verify/Create Signature Field/Sign/etc
Req.OptionalInputs.SignatureType = SignatureTypeFieldCreateSign;
//Configure Create and Sign operation parameters:
Req.OptionalInputs.ClaimedIdentity = new ClaimedIdentity();
Req.OptionalInputs.ClaimedIdentity.Name = new NameIdentifierType();
Req.OptionalInputs.ClaimedIdentity.Name.Value = UserName; //User Name
Req.OptionalInputs.ClaimedIdentity.Name.NameQualifier = " "; //Domain (relevant for Active Directory environment only)
Req.OptionalInputs.ClaimedIdentity.SupportingInfo = new CoSignAuthDataType();
Req.OptionalInputs.ClaimedIdentity.SupportingInfo.LogonPassword = Password; //User Password
Req.OptionalInputs.SAPISigFieldSettings = new SAPISigFieldSettingsType();
Req.OptionalInputs.SAPISigFieldSettings.X = X; //Signature Field X coordinate
Req.OptionalInputs.SAPISigFieldSettings.XSpecified = true;
Req.OptionalInputs.SAPISigFieldSettings.Y = Y; //Signature Field Y coordinate
Req.OptionalInputs.SAPISigFieldSettings.YSpecified = true;
Req.OptionalInputs.SAPISigFieldSettings.Page = Page; //Page number the signature field will appear on
Req.OptionalInputs.SAPISigFieldSettings.PageSpecified = true;
Req.OptionalInputs.SAPISigFieldSettings.Width = Width; //Signature Field width
Req.OptionalInputs.SAPISigFieldSettings.WidthSpecified = true;
Req.OptionalInputs.SAPISigFieldSettings.Height = Height; //Signature Field Height
Req.OptionalInputs.SAPISigFieldSettings.HeightSpecified = true;
Req.OptionalInputs.SAPISigFieldSettings.Invisible = !isVisible; //Specifies whether the signature will be visible or not
Req.OptionalInputs.SAPISigFieldSettings.InvisibleSpecified = true;
// Set configuration parameters /////////////////////////////////////////////////////////
int numConfigurationParams = 6;
Req.OptionalInputs.ConfigurationValues = new ConfValueType[numConfigurationParams];
for (int i = 0; i < numConfigurationParams; i++)
{
Req.OptionalInputs.ConfigurationValues[i] = new ConfValueType();
}
// Add reason
Req.OptionalInputs.ConfigurationValues[0].ConfValueID = ConfIDEnum.Reason;
Req.OptionalInputs.ConfigurationValues[0].Item = "I am the author of this document";
// Add TSA:
/*
Req.OptionalInputs.ConfigurationValues[1].ConfValueID = ConfIDEnum.UseTimestamp;
Req.OptionalInputs.ConfigurationValues[1].Item = 1;
Req.OptionalInputs.ConfigurationValues[2].ConfValueID = ConfIDEnum.TimestampURL;
Req.OptionalInputs.ConfigurationValues[2].Item = "http://www.ca-soft.com/request.aspx";
Req.OptionalInputs.ConfigurationValues[3].ConfValueID = ConfIDEnum.TimestampAdditionalBytes;
Req.OptionalInputs.ConfigurationValues[3].Item = 4000;
Req.OptionalInputs.ConfigurationValues[4].ConfValueID = ConfIDEnum.TimestampUser;
Req.OptionalInputs.ConfigurationValues[4].Item = "";
Req.OptionalInputs.ConfigurationValues[5].ConfValueID = ConfIDEnum.TimestampPWD;
Req.OptionalInputs.ConfigurationValues[5].Item = "";
// OCSP (NOTE: Server must contain comodo CA in order to use the following OCSP URL)
Req.OptionalInputs.ConfigurationValues[4].ConfValueID = ConfIDEnum.UseOCSP;
Req.OptionalInputs.ConfigurationValues[4].Item = 1;
Req.OptionalInputs.ConfigurationValues[5].ConfValueID = ConfIDEnum.OCSPURL;
Req.OptionalInputs.ConfigurationValues[5].Item = "ocsp.comodoca.com";
*/
// End setting configuration parameters ////////////////////////////////////////////////
//Set Session ID
Req.RequestID = Guid.NewGuid().ToString();
//Prepare the Data to be signed
DocumentType doc1 = new DocumentType();
DocumentTypeBase64Data b64data = new DocumentTypeBase64Data();
Req.InputDocuments = new RequestBaseTypeInputDocuments();
Req.InputDocuments.Items = new object[1];
b64data.MimeType = "application/pdf"; //Can also be: application/msword, image/tiff, pplication/octet-string (ocsp/tsa are supported in PDF only)
Req.OptionalInputs.ReturnPDFTailOnlySpecified = true;
Req.OptionalInputs.ReturnPDFTailOnly = true;
b64data.Value = ReadFile(FileToSign, true); //Read the file to the Bytes Array
doc1.Item = b64data;
Req.InputDocuments.Items[0] = doc1;
//Call sign service
ResponseBaseType Resp = null;
try
{
// Create the Web Service client object
DSS service = new DSS();
service.Url = "https://prime.cosigntrial.com:8080/SAPIWS/dss.asmx"; //This url is constant and shouldn't be changed
// service.Url = "https://prime-dsa-devctr.docusign.net:8080/sapiws/dss.asmx"; //This url is constant and shouldn't be changed
SignRequest sreq = new SignRequest();
sreq.InputDocuments = Req.InputDocuments;
sreq.OptionalInputs = Req.OptionalInputs;
//Perform Signature operation
Resp = service.DssSign(sreq);
if (Resp.Result.ResultMajor != Success )
{
MessageBox.Show("Error: " + Resp.Result.ResultMajor + " " +
Resp.Result.ResultMinor + " " +
Resp.Result.ResultMessage.Value, "Error");
return false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
if (ex is WebException)
{
WebException we = ex as WebException;
WebResponse webResponse = we.Response;
if (webResponse != null)
MessageBox.Show(we.Response.ToString(), "Web Response");
}
return false;
}
//Handle Reply
DssSignResult sResp = (DssSignResult) Resp;
//object sig = sResp.SignatureObject.Item;
//SignatureObjectTypeBase64Signature sig = (SignatureObjectTypeBase64Signature) sResp.SignatureObject.Item;
DssSignResultSignatureObjectBase64Signature sig = (DssSignResultSignatureObjectBase64Signature)sResp.SignatureObject.Item;
byte[] signature = sig.Value;
return PDFAttachSignature(FileToSign, signature, true); //Attach Signature to the PDF file
}
display error urn:oasis:names:tc:dss:1.0:resultmajor:ResponderError
I am currently using an Umbraco library to extend the Authentication possibilities and enable back office authentication with Active Directory.
https://github.com/umbraco/UmbracoIdentityExtensions
After installing the library and following the blog post below, I was able to display an external login button, authenticate with Active Directory and add a user and external login to the Umbraco database.
https://www.jdibble.co.uk/blog/securing-umbraco-backoffice-with-azure-active-directory/
This then sends you back to the /umbraco login page in a continuous loop. As described by this blog post https://our.umbraco.org/forum/developers/extending-umbraco/75256-login-uisng-azure-ad-redirects-allways-to-login-page
Has anyone faced this issue and solved it? Or have any useful suggestions?
The code being used...
public static void ConfigureBackOfficeAzureActiveDirectoryAuth(this IAppBuilder app,
string tenant, string clientId, string postLoginRedirectUri, Guid issuerId,
string caption = "Active Directory", string style = "btn-microsoft", string icon = "fa-windows")
{
var authority = string.Format(
CultureInfo.InvariantCulture,
"https://login.microsoftonline.com/{0}",
tenant);
var adOptions = new OpenIdConnectAuthenticationOptions
{
SignInAsAuthenticationType = Constants.Security.BackOfficeExternalAuthenticationType,
ClientId = clientId,
Authority = authority,
RedirectUri = postLoginRedirectUri,
AuthenticationMode = AuthenticationMode.Passive,
Notifications = new OpenIdConnectAuthenticationNotifications
{
AuthorizationCodeReceived = async context =>
{
if (System.Diagnostics.Debugger.IsAttached)
System.Diagnostics.Debugger.Break();
var userService = ApplicationContext.Current.Services.UserService;
var stuff = (List<Claim>)context.JwtSecurityToken.Claims;
var email = stuff.FirstOrDefault(x => x.Type == "unique_name").Value;
var issuer = stuff.FirstOrDefault(x => x.Type == "iss").Value;
var providerKey = stuff.FirstOrDefault(x => x.Type == "sub").Value;
var name = stuff.FirstOrDefault(x => x.Type == "name").Value;
var userManager = context.OwinContext.GetUserManager<BackOfficeUserManager>();
var user = userService.GetByEmail(email);
if (user == null)
{
var writerUserType = userService.GetUserTypeByName("writer");
user = userService.CreateUserWithIdentity(email, email, writerUserType);
}
var identity = await userManager.FindByEmailAsync(email);
if (identity.Logins.All(x => x.ProviderKey != providerKey))
{
identity.Logins.Add(new IdentityUserLogin(issuer, providerKey, user.Id));
identity.Name = name;
var result = userManager.Update(identity);
}
},
}
};
adOptions.ForUmbracoBackOffice(style, icon);
adOptions.Caption = caption;
//Need to set the auth type as the issuer path
adOptions.AuthenticationType = string.Format(
CultureInfo.InvariantCulture,
"https://sts.windows.net/{0}/",
issuerId);
adOptions.SetExternalSignInAutoLinkOptions(new ExternalSignInAutoLinkOptions(autoLinkExternalAccount: true));
app.UseOpenIdConnectAuthentication(adOptions);
}
I have been breaking my head over this. Please take a look at this code. This code is in the customer controller.
[HttpPost]
[Themed]
public ActionResult Register(string email, string password, string confirmPassword, Gender gender, string givenName, string familyName, string insertion, DateTime birthDate) {
ViewData["PasswordLength"] = MinPasswordLength;
var shape = _orchardServices.New.Register();
//1. Initialize new content of customer contenttype
var customer = _orchardServices.ContentManager.New("Customer");
if (customer != null) {
//2. Define the parts that need to be filled
var userPart = customer.As<UserPart>();
var customerPart = customer.As<CustomerPart>();
//3. Let's validate first if the user can be created
if (userPart!=null) {
//shape.Customer = _orchardServices.ContentManager.UpdateEditor(customer, this);
if (!ModelState.IsValid)
{
_orchardServices.TransactionManager.Cancel();
return new ShapeResult(this, shape);
}
//4. Now validate the user credentials.
if (ValidateRegistration(email, password, confirmPassword)) {
//Now create the actual customer.
userPart.UserName = email;
userPart.Email = email;
userPart.NormalizedUserName = email.ToLowerInvariant();
userPart.Record.HashAlgorithm = "SHA1";
userPart.Record.RegistrationStatus = UserStatus.Approved;
userPart.Record.EmailStatus = UserStatus.Approved;
customerPart.CreatedAt = DateTime.UtcNow;
customerPart.LastLogonAt = DateTime.UtcNow;
_membershipService.SetPassword(userPart, password);
var user = customerPart.User;
_authenticationService.SignIn(user, false /* createPersistentCookie */);
return Redirect("~/");
}
}
}
When this code is run, I end up with two entries for UserPart in my database. One with a related CustomerPart and one not.
I like to calculate the passowrd expiration date for the user in active directory
I am able to get the MaxPWdAge and LastPwdSet attributes.
But the problem is whenever i am changing the password of one of a user for testing purposes, lastPwdSet is not updating and it is still showing the old date?
Can anybody tell me why is this happen ?
public bool CheckPassWordExpiryDate(string LdapPath, string Username, string Password)
{
DomainConfiguration domainConfig = new DomainConfiguration();
// Configuration(web.config) changes
DirectoryEntry de = new DirectoryEntry("LDAP://" + LdapPath, domainConfig.UserName, domainConfig.Password);
DirectoryEntry entry = new DirectoryEntry();
entry.Username = Username;
entry.Password = Password;
//Function to get maximum password age from the active directory
int maxPwdAge = GetMaxPasswordAge();
// Function to get last password set date for the use.
DateTime pwdLastSet = GetPwdLastSet("pwdLastSet", Username);
//Add maximum password age days to Last password set days , if it is less than today's date means that password has been expired else it is not expired
if (pwdLastSet.AddDays(maxPwdAge) < DateTime.Now)
{
return true;
}
else
{
return false;
}
}
public static int GetMaxPasswordAge()
{
DomainConfiguration domainConfig = new DomainConfiguration();
using (new SPMonitoredScope("AD Properties"))
{
using (DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainConfig.DomainName, domainConfig.UserName, domainConfig.Password))
{
DirectorySearcher ds = new DirectorySearcher(
domain,
"(objectClass=*)",
null,
SearchScope.Base
);
SearchResult sr = ds.FindOne();
TimeSpan maxPwdAge = TimeSpan.MinValue;
if (sr.Properties.Contains("maxPwdAge"))
maxPwdAge = TimeSpan.FromTicks((long)sr.Properties["maxPwdAge"][0]);
return maxPwdAge.Duration().Days;
}
}
}
public DateTime GetPwdLastSet(string attr, string UserName)
{
DomainConfiguration domainConfig = new DomainConfiguration();
using (new SPMonitoredScope("AD Properties"))
{
using (DirectoryEntry domain = new DirectoryEntry("LDAP://" + domainConfig.DomainName, domainConfig.UserName, domainConfig.Password))
{
//DirectorySearcher searcher = new DirectorySearcher(domain, "(|(objectClass=organizationalUnit)(objectClass=container)(objectClass=builtinDomain)(objectClass=domainDNS))");
DirectorySearcher searcher = new DirectorySearcher(domain);
searcher.PageSize = 1000;
searcher.Filter = "(SAMAccountName='" + UserName + "')";
searcher.Filter = "(|(objectCategory=group)(objectCategory=person))";
var user = searcher.FindOne();
DateTime pwdLastSet = DateTime.FromFileTime((Int64)user.Properties["PwdLastSet"][0]);
return pwdLastSet;
}
}
}
} }