public virtual UrlProviderResult ValidateToken(String token)
        {
            UrlProviderResult result = UrlProviderResult.NotEvaluatedToken;

            try
            {
                dtoUrlUserDateToken dto = DecryptToken(token);
                if (dto != null)
                {
                    if (DateTime.Now - dto.Data <= DeltaTime)
                    {
                        result = UrlProviderResult.ValidToken;
                    }
                    else
                    {
                        result = UrlProviderResult.ExpiredToken;
                    }
                }
                else
                {
                    result = UrlProviderResult.InvalidToken;
                }
            }
            catch (Exception ex)
            {
                result = UrlProviderResult.InvalidToken;
            }
            return(result);
        }
        public virtual UrlProviderResult ValidateToken(String token, DateTime dateTimeToVerify)
        {
            UrlProviderResult result = UrlProviderResult.NotEvaluatedToken;

            try
            {
                dtoUrlUserDateToken dto = DecryptToken(token);
                if (dto != null)
                {
                    TimeSpan dateDifference = dateTimeToVerify.Subtract(dto.Data);
                    if (dateDifference <= DeltaTime)
                    {
                        result = UrlProviderResult.ValidToken;
                    }
                    else
                    {
                        result = UrlProviderResult.ExpiredToken;
                    }
                }
                else
                {
                    result = UrlProviderResult.InvalidToken;
                }
            }
            catch (Exception ex)
            {
                result = UrlProviderResult.InvalidToken;
            }
            return(result);
        }
        public void InitView(DateTime dateTimeToVerify)
        {
            String moduleCode           = View.PreLoadedModuleCode;
            String modulePage           = View.PreloadedModulePage;
            String externalProviderCode = View.PreLoadedExternalSource;
            String encodedToken         = "";

            Authentication.AuthenticationProvider provider = Service.GetActiveProvider(externalProviderCode);

            if (provider == null)
            {
                View.UnknowAuthenticationProvider();
            }
            else if (provider.ProviderType == Authentication.AuthenticationProviderType.Url)
            {
                UrlAuthenticationProvider urlProvider = (UrlAuthenticationProvider)provider;
                encodedToken = View.GetEncodedIdUser(urlProvider.UrlIdentifier);
                UrlProviderResult response = UrlProviderResult.NotEvaluatedToken;
                if (encodedToken == "")
                {
                    response = UrlProviderResult.UnknowToken;
                }
                else
                {
                    response = urlProvider.ValidateToken(encodedToken, View.PreloadedPreviousUrl, dateTimeToVerify);
                }
                switch (response)
                {
                case UrlProviderResult.ValidToken:
                    string decodedToken = urlProvider.GetTokenIdentifier(encodedToken);
                    LoadUser(decodedToken, urlProvider);
                    break;

                //case UrlProviderResult.UnknowToken:
                //    View.showLogonInfo(UrlProviderResult.
                //    break;
                default:
                    View.showLogonInfo(response, urlProvider.RemoteLoginUrl);
                    break;
                }
            }
        }
Пример #4
0
        public void InitView(int idPerson, long idProvider, UrlProviderResult message)
        {
            Person person = CurrentManager.GetPerson(idPerson);

            InitializeLanguage(person);

            UrlAuthenticationProvider provider = CurrentManager.Get <UrlAuthenticationProvider>(idProvider);

            if (person != null)
            {
                View.DisplayMessage(person.SurnameAndName, message);
            }
            else
            {
                View.DisplayMessage(message);
            }

            String defaultUrl = (provider != null) ? provider.RemoteLoginUrl : "";

            if (message != UrlProviderResult.ValidToken)
            {
                View.SetAutoLogonUrl(defaultUrl);
            }
        }
Пример #5
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();
            }
        }