Ejemplo n.º 1
0
        public Dictionary <ProfileAttributeType, string> GetUserAttributesForAgency(MacUrlAuthenticationProvider provider, List <dtoMacUrlUserAttribute> attributes)
        {
            List <UserProfileAttribute> pAttributes = provider.Attributes.Where(p => p.Deleted == BaseStatusDeleted.None && p.GetType() == typeof(UserProfileAttribute)).Select(p => (UserProfileAttribute)p).ToList();

            Dictionary <ProfileAttributeType, string> items = new Dictionary <ProfileAttributeType, string>();

            items.Add(ProfileAttributeType.agencyExternalCode, provider.GetAttributeValue(ProfileAttributeType.agencyExternalCode, pAttributes, attributes));
            items.Add(ProfileAttributeType.agencyTaxCode, provider.GetAttributeValue(ProfileAttributeType.agencyTaxCode, pAttributes, attributes));
            items.Add(ProfileAttributeType.agencyNationalCode, provider.GetAttributeValue(ProfileAttributeType.agencyNationalCode, pAttributes, attributes));
            items.Add(ProfileAttributeType.agencyInternalCode, provider.GetAttributeValue(ProfileAttributeType.agencyInternalCode, pAttributes, attributes));

            return(items.Where(i => !String.IsNullOrEmpty(i.Value)).ToDictionary(k => k.Key, k => k.Value));
        }
Ejemplo n.º 2
0
        public dtoBaseProfile GetProfileData(dtoBaseProfile previous, MacUrlAuthenticationProvider provider, List <UserProfileAttribute> pAttributes, List <dtoMacUrlUserAttribute> attributes, Int32 idOrganization, Int32 idProfileType)
        {
            dtoBaseProfile result = GetProfileData(provider, pAttributes, attributes, idOrganization, idProfileType);

            if (previous != null)
            {
                result.Id      = previous.Id;
                result.Name    = previous.Name;
                result.Surname = previous.Surname;
                if (String.IsNullOrEmpty(provider.GetAttributeValue(ProfileAttributeType.taxCode, pAttributes, attributes)))
                {
                    result.TaxCode = previous.TaxCode;
                }

                if (result.Mail == result.Login + "@invalid.invalid.it" && !previous.Mail.Contains("@invalid.invalid.it"))
                {
                    result.Mail = previous.Mail;
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        public dtoBaseProfile GetProfileData(MacUrlAuthenticationProvider provider, List <UserProfileAttribute> pAttributes, List <dtoMacUrlUserAttribute> attributes, Int32 idOrganization, Int32 idProfileType)
        {
            dtoBaseProfile profile  = new dtoBaseProfile();
            String         pwd      = lm.Comol.Core.DomainModel.Helpers.RandomKeyGenerator.GenerateRandomKey(6, 10, true, true, false);
            Language       language = GetUserLanguage(provider.GetAttributeValue(ProfileAttributeType.language, pAttributes, attributes));

            switch (idProfileType)
            {
            case (int)UserTypeStandard.ExternalUser:
                profile = new dtoExternal();
                break;

            case (int)UserTypeStandard.Company:
                profile = new dtoCompany();
                break;

            case (int)UserTypeStandard.Employee:
                profile = new dtoEmployee();
                break;

            default:
                profile = new dtoBaseProfile();
                break;
            }
            profile.Login = provider.GetAttributeValue(ProfileAttributeType.login, pAttributes, attributes);
            if (String.IsNullOrEmpty(profile.Login))
            {
                profile.Login = provider.GetAttributeValue(ProfileAttributeType.externalId, attributes);
            }

            profile.Name    = provider.GetAttributeValue(ProfileAttributeType.name, pAttributes, attributes);
            profile.Surname = provider.GetAttributeValue(ProfileAttributeType.surname, pAttributes, attributes);
            profile.TaxCode = provider.GetAttributeValue(ProfileAttributeType.taxCode, pAttributes, attributes);
            if (String.IsNullOrEmpty(profile.TaxCode))
            {
                profile.TaxCode = UrlService.GenerateRandomTaxCode();
            }
            profile.Mail = provider.GetAttributeValue(ProfileAttributeType.mail, pAttributes, attributes);
            if (String.IsNullOrEmpty(profile.Mail))
            {
                profile.Mail = profile.Login + "@invalid.invalid.it";
            }
            //if (!String.IsNullOrEmpty(profile.Mail))
            //    profile.Mail = profile.Mail.ToLower();
            profile.Password = pwd;
            profile.ShowMail = false;
            if (!String.IsNullOrEmpty(profile.Surname))
            {
                profile.FirstLetter = profile.Surname[0].ToString().ToLower();
            }
            profile.IdProfileType          = idProfileType;
            profile.AuthenticationProvider = provider.ProviderType;
            profile.IdLanguage             = language.Id;
            profile.LanguageName           = language.Name;


            switch (idProfileType)
            {
            case (int)UserTypeStandard.Company:
                dtoCompany dCompany = (dtoCompany)profile;
                dCompany.Info.Address               = provider.GetAttributeValue(ProfileAttributeType.companyAddress, pAttributes, attributes);
                dCompany.Info.City                  = provider.GetAttributeValue(ProfileAttributeType.companyCity, pAttributes, attributes);
                dCompany.Info.Name                  = provider.GetAttributeValue(ProfileAttributeType.companyName, pAttributes, attributes);
                dCompany.Info.Region                = provider.GetAttributeValue(ProfileAttributeType.companyRegion, pAttributes, attributes);
                dCompany.Info.TaxCode               = provider.GetAttributeValue(ProfileAttributeType.companyTaxCode, pAttributes, attributes);
                dCompany.Info.ReaNumber             = provider.GetAttributeValue(ProfileAttributeType.companyReaNumber, pAttributes, attributes);
                dCompany.Info.AssociationCategories = provider.GetAttributeValue(ProfileAttributeType.companyAssociations, pAttributes, attributes);
                return(dCompany);

            case (int)UserTypeStandard.Employee:
                dtoEmployee dEmployee = (dtoEmployee)profile;
                Person      anonymous = ProfileService.GetAnonymousUser();
                Agency      agency    = null;
                if (anonymous == null)
                {
                    Dictionary <ProfileAttributeType, string> agencyAttributes = GetUserAttributesForAgency(provider, attributes);
                    agency = ProfileService.GetAgency(agencyAttributes);
                    if (agency == null)
                    {
                        agency = ProfileService.GetDefaultAgency(idOrganization);
                    }
                }
                else
                {
                    agency = GetAgencyByAttributes(anonymous.Id, idOrganization, provider, attributes);
                }

                if (agency != null)
                {
                    dEmployee.CurrentAgency = new KeyValuePair <long, string>(agency.Id, agency.Name);
                }
                else
                {
                    dEmployee.CurrentAgency = ProfileService.GetEmptyAgency(idOrganization);
                }

                return(dEmployee);


            case (int)UserTypeStandard.ExternalUser:
                dtoExternal dExternal = (dtoExternal)profile;
                dExternal.ExternalUserInfo = provider.GetAttributeValue(ProfileAttributeType.externalUserInfo, pAttributes, attributes);
                return(dExternal);

            default:
                return(profile);
            }
        }