private void UrlProviderLogon(dtoMacUrlProviderIdentifier identifier, String fromUrl) { MacUrlAuthenticationProvider provider = UrlService.GetProvider(identifier.IdProvider); if (provider != null) { List <dtoMacUrlUserAttribute> attributes = View.GetTokenAttributes(provider.GetUserAttributes()); dtoMacUrlToken vToken = provider.ValidateToken(attributes, fromUrl, UserContext.IpAddress, UserContext.ProxyIpAddress); //if (!String.IsNullOrEmpty(provider.RemoteLoginUrl)) // View.SetExternalWebLogonUrl(provider.RemoteLoginUrl); //else if (!String.IsNullOrEmpty(provider.SenderUrl)) // View.SetExternalWebLogonUrl(provider.SenderUrl); List <ExternalLoginInfo> users = UrlService.FindUserByIdentifier(vToken.UniqueIdentifyer, provider); List <ExternalLoginInfo> userIdentifiers = null; Person logonUser = null; if (View.PreloadForDebug) { View.DisplayDebugInfo(vToken); } else { // NEL CASO IN CUI UN UTENTE ACCEDA CoN DUE IDENTIFICATIVI DISTINTI MA IL SISTEMA NON CONSENTA DUE TAXCODE identici ! if (!String.IsNullOrEmpty(vToken.UniqueIdentifyer) && users.Count == 0 && provider.AllowMultipleInsert && !provider.AllowTaxCodeDuplication) { String taxCode = provider.GetAttributeValue(ProfileAttributeType.taxCode, attributes); List <Person> pItems = ProfileService.GetUserByTaxCode(taxCode); if (pItems != null && pItems.Count == 1) { logonUser = pItems[0]; userIdentifiers = UrlService.GetUserIdentifiers(pItems[0], provider); } } switch (vToken.Evaluation.Result) { case UrlProviderResult.ValidToken: if (users.Count == 1) { ExternalLoginInfo loginInfo = users[0]; if (loginInfo.Person != null) { UpdateProfileByToken(loginInfo.Person, provider, attributes); } ExternalLogonManage(vToken, loginInfo, provider, attributes); } else if (logonUser != null && !logonUser.isDisabled) { UpdateProfileByToken(logonUser, provider, attributes); ExternalLogonManage(vToken, UrlService.AddUserInfo(logonUser, provider, vToken.UniqueIdentifyer), provider, attributes); } else if (!String.IsNullOrEmpty(vToken.UniqueIdentifyer) && users.Count == 0) { if (provider.AutoEnroll) { UrlProviderResult result = UrlProviderResult.ValidToken; Int32 idOrganization = 0; Int32 idProfileType = 0; Int32 idProfile = 0; List <OrganizationAttributeItem> items = provider.GetOrganizationsInfo(attributes); if (items == null || items.Count != 1) { result = UrlProviderResult.InvalidToken; } else { List <UserProfileAttribute> pAttributes = provider.GetProfileAttributes(); idOrganization = items[0].Organization.Id; idProfileType = items[0].IdDefaultProfile; String taxCode = provider.GetAttributeValue(ProfileAttributeType.taxCode, pAttributes, attributes); if (!provider.AllowTaxCodeDuplication && !UrlService.isUniqueTaxCode(taxCode)) { result = UrlProviderResult.InvalidToken; View.DisplayTaxCodeAlreadyPresent(); } else { idProfile = View.CreateUserProfile(Helper.GetProfileData(provider, pAttributes, attributes, idOrganization, idProfileType), idProfileType, idOrganization, provider, UrlService.GetCredentials(provider, attributes)); } } if (result != UrlProviderResult.ValidToken) { View.DisplayInvalidMessage(UrlProviderResult.InvalidToken); } else if (idProfile == 0) { View.DisplayAutoEnrollmentFailed(); } else { if (provider.HasCatalogues()) { UrlService.UpdateCatalogueAssocation(idProfile, provider, attributes); } ExternalLogonManage(vToken, UrlService.GetUserInfo(provider.Id, idProfile, vToken.UniqueIdentifyer), provider, attributes); } } else { View.GoToProfile(vToken, lm.Comol.Core.BaseModules.ProfileManagement.RootObject.MacUrlProfileWizard(provider.Id, attributes)); } } break; default: int idPerson = (users.Count == 1 && users[0].Person != null) ? users[0].Person.Id : 0; if (users.Count == 1 && users[0].Person != null) { View.DisplayInvalidMessage(users[0].Person.SurnameAndName, vToken.Evaluation.Result); } else { View.DisplayInvalidMessage(vToken.Evaluation.Result); } if (!String.IsNullOrEmpty(provider.RemoteLoginUrl)) { View.SetAutoLogonUrl(provider.RemoteLoginUrl); } else if (!String.IsNullOrEmpty(provider.SenderUrl)) { View.SetAutoLogonUrl(provider.SenderUrl); } break; } } } else { View.DisplayUrlAuthenticationUnavailable(); } }