public static AuthenticationSettings GetAuthenticationSettings(this CrmWebsite website, bool isLocal = false) { if (website == null) { throw new ArgumentNullException("website"); } return(new AuthenticationSettings { IsDemoMode = isLocal && website.Settings.Get <bool?>("Authentication/Registration/IsDemoMode").GetValueOrDefault(false), RegistrationEnabled = website.Settings.Get <bool?>("Authentication/Registration/Enabled").GetValueOrDefault(true), InvitationEnabled = website.Settings.Get <bool?>("Authentication/Registration/InvitationEnabled").GetValueOrDefault(true), OpenRegistrationEnabled = website.Settings.Get <bool?>("Authentication/Registration/OpenRegistrationEnabled").GetValueOrDefault(true), LocalLoginEnabled = website.Settings.Get <bool?>("Authentication/Registration/LocalLoginEnabled").GetValueOrDefault(false), LocalLoginByEmail = website.Settings.Get <bool?>("Authentication/Registration/LocalLoginByEmail").GetValueOrDefault(false), RequireUniqueEmail = website.Settings.Get <bool?>("Authentication/UserManager/UserValidator/RequireUniqueEmail").GetValueOrDefault(true), ExternalLoginEnabled = website.Settings.Get <bool?>("Authentication/Registration/ExternalLoginEnabled").GetValueOrDefault(true), RememberMeEnabled = website.Settings.Get <bool?>("Authentication/Registration/RememberMeEnabled").GetValueOrDefault(true), RememberBrowserEnabled = website.Settings.Get <bool?>("Authentication/Registration/RememberBrowserEnabled").GetValueOrDefault(true), ResetPasswordEnabled = website.Settings.Get <bool?>("Authentication/Registration/ResetPasswordEnabled").GetValueOrDefault(true), ResetPasswordRequiresConfirmedEmail = website.Settings.Get <bool?>("Authentication/Registration/ResetPasswordRequiresConfirmedEmail").GetValueOrDefault(false), TriggerLockoutOnFailedPassword = website.Settings.Get <bool?>("Authentication/Registration/TriggerLockoutOnFailedPassword").GetValueOrDefault(true), TwoFactorEnabled = website.Settings.Get <bool?>("Authentication/Registration/TwoFactorEnabled").GetValueOrDefault(false), MobilePhoneEnabled = website.Settings.Get <bool?>("Authentication/Registration/MobilePhoneEnabled").GetValueOrDefault(false), EmailConfirmationEnabled = website.Settings.Get <bool?>("Authentication/Registration/EmailConfirmationEnabled").GetValueOrDefault(true), SignOutEverywhereEnabled = website.Settings.Get <bool?>("Authentication/Registration/SignOutEverywhereEnabled").GetValueOrDefault(true), LoginButtonAuthenticationType = website.Settings.Get <string>("Authentication/Registration/LoginButtonAuthenticationType"), LoginTrackingEnabled = website.Settings.Get <bool?>("Authentication/LoginTrackingEnabled").GetValueOrDefault(false), ProfileRedirectEnabled = website.Settings.Get <bool?>("Authentication/Registration/ProfileRedirectEnabled").GetValueOrDefault(true), AzureADLoginEnabled = website.Settings.Get <bool?>("Authentication/Registration/AzureADLoginEnabled").GetValueOrDefault(true), IsCaptchaEnabledForRegistration = website.Settings.Get <bool?>("Authentication/Registration/CaptchaEnabled").GetValueOrDefault(false) }); }
public static CrmIdentityErrorDescriber GetIdentityErrors(this CrmWebsite website, IOwinContext context, bool isLocal = false) { if (website == null) { throw new ArgumentNullException("website"); } return(new CrmIdentityErrorDescriber(context)); }
public ApplicationStartupSettingsManager( CrmWebsite website, Func <UserManager <ApplicationUser, string>, ApplicationUser, Task <ClaimsIdentity> > regenerateIdentityCallback, PathString loginPath, PathString externalLoginCallbackPath, PathString externalAuthenticationFailedPath, PathString externalPasswordResetPath) : base(website, regenerateIdentityCallback, loginPath, externalLoginCallbackPath, externalAuthenticationFailedPath, externalPasswordResetPath) { }
public static UserLoginInfo GetFacebookAuthenticationType(this CrmWebsite website) { if (website == null) { throw new ArgumentNullException("website"); } var authenticationType = website.Settings.Get <string>("Authentication/OpenAuth/Facebook/AuthenticationType") ?? new FacebookAuthenticationOptions().AuthenticationType; return(new UserLoginInfo(authenticationType, null)); }
public SettingDataAdapter(IDataAdapterDependencies dependencies, CrmWebsite website) { if (dependencies == null) { throw new ArgumentNullException("dependencies"); } if (website == null) { throw new ArgumentNullException("website"); } Dependencies = dependencies; _website = website; }
public virtual void Configure <TWebsiteKey>(CrmWebsite <TWebsiteKey> website) { if (website == null) { throw new ArgumentNullException("website"); } var userValidator = UserValidator as UserValidator <TUser, TKey>; if (userValidator != null) { userValidator.AllowOnlyAlphanumericUserNames = website.Settings.Get <bool?>("Authentication/UserManager/UserValidator/AllowOnlyAlphanumericUserNames").GetValueOrDefault(userValidator.AllowOnlyAlphanumericUserNames); userValidator.RequireUniqueEmail = website.Settings.Get <bool?>("Authentication/UserManager/UserValidator/RequireUniqueEmail").GetValueOrDefault(userValidator.RequireUniqueEmail); } var passwordValidator = PasswordValidator as PasswordValidator; if (passwordValidator != null) { passwordValidator.RequiredLength = website.Settings.Get <int?>("Authentication/UserManager/PasswordValidator/RequiredLength").GetValueOrDefault(passwordValidator.RequiredLength); passwordValidator.RequireNonLetterOrDigit = website.Settings.Get <bool?>("Authentication/UserManager/PasswordValidator/RequireNonLetterOrDigit").GetValueOrDefault(passwordValidator.RequireNonLetterOrDigit); passwordValidator.RequireDigit = website.Settings.Get <bool?>("Authentication/UserManager/PasswordValidator/RequireDigit").GetValueOrDefault(passwordValidator.RequireDigit); passwordValidator.RequireLowercase = website.Settings.Get <bool?>("Authentication/UserManager/PasswordValidator/RequireLowercase").GetValueOrDefault(passwordValidator.RequireLowercase); passwordValidator.RequireUppercase = website.Settings.Get <bool?>("Authentication/UserManager/PasswordValidator/RequireUppercase").GetValueOrDefault(passwordValidator.RequireUppercase); } var crmPasswordValidator = PasswordValidator as CrmPasswordValidator; if (crmPasswordValidator != null) { crmPasswordValidator.EnforcePasswordPolicy = website.Settings.Get <bool?>("Authentication/UserManager/PasswordValidator/EnforcePasswordPolicy").GetValueOrDefault(crmPasswordValidator.EnforcePasswordPolicy); } var minimumLengthValidator = PasswordValidator as MinimumLengthValidator; if (minimumLengthValidator != null) { minimumLengthValidator.RequiredLength = website.Settings.Get <int?>("Authentication/UserManager/PasswordValidator/RequiredLength").GetValueOrDefault(minimumLengthValidator.RequiredLength); } UserLockoutEnabledByDefault = website.Settings.Get <bool?>("Authentication/UserManager/UserLockoutEnabledByDefault").GetValueOrDefault(UserLockoutEnabledByDefault); DefaultAccountLockoutTimeSpan = website.Settings.Get <TimeSpan?>("Authentication/UserManager/DefaultAccountLockoutTimeSpan").GetValueOrDefault(DefaultAccountLockoutTimeSpan); MaxFailedAccessAttemptsBeforeLockout = website.Settings.Get <int?>("Authentication/UserManager/MaxFailedAccessAttemptsBeforeLockout").GetValueOrDefault(MaxFailedAccessAttemptsBeforeLockout); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app, CrmWebsite website) { var url = new UrlHelper(HttpContext.Current.Request.RequestContext); var defaultAuthenticationType = website.Settings.Get <string>("Authentication/Registration/LoginButtonAuthenticationType"); var loginPath = string.IsNullOrWhiteSpace(defaultAuthenticationType) ? new PathString(url.Action("Login", "Login", new { area = "Account" })) : new PathString(url.Action("ExternalLogin", "Login", new { area = "Account", provider = defaultAuthenticationType })); var externalLoginCallbackPath = new PathString(url.Action("ExternalLoginCallback", "Login", new { area = "Account" })); var externalAuthenticationFailedPath = new PathString(url.Action("ExternalAuthenticationFailed", "Login", new { area = "Account" })); var externalPasswordResetPath = new PathString(url.Action("ExternalPasswordReset", "Login", new { area = "Account" })); var settingsManager = new ApplicationStartupSettingsManager(website, (manager, user) => user.GenerateUserIdentityAsync(manager), loginPath, externalLoginCallbackPath, externalAuthenticationFailedPath, externalPasswordResetPath); // Configure user manager and role manager to use a single instance per request app.CreatePerOwinContext(() => settingsManager); app.CreatePerOwinContext <ApplicationInvitationManager>(ApplicationInvitationManager.Create); app.CreatePerOwinContext <ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext <ApplicationSignInManager>(ApplicationSignInManager.Create); app.UseSiteMapAuthentication(settingsManager.ApplicationCookie); // Enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // Configure the sign in cookie app.UseKentorOwinCookieSaver(); app.UseCookieAuthentication(settingsManager.ApplicationCookie); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); app.CreatePerOwinContext <CrmUser>(ApplicationUser.Create); // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, settingsManager.TwoFactorCookie.ExpireTimeSpan); // Enables the application to remember the second login verification factor such as phone or email. // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. // This is similar to the RememberMe option when you log in. app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); app.UsePortalsAuthentication(settingsManager); }
public static JObject GetFacebookToken(this CrmWebsite website, string signedRequest) { if (website == null) { throw new ArgumentNullException("website"); } if (signedRequest == null) { throw new ArgumentNullException("signedRequest"); } var secret = website.Settings.Get <string>("Authentication/OpenAuth/Facebook/AppSecret") ?? website.Settings.Get <string>("Authentication/OpenAuth/Facebook/ClientSecret"); if (string.IsNullOrWhiteSpace(secret)) { return(null); } return(DecodeSignedRequest(signedRequest, secret)); }
public static ExternalLoginInfo GetFacebookLoginInfo(this CrmWebsite website, string signedRequest) { if (website == null) { throw new ArgumentNullException("website"); } if (signedRequest == null) { throw new ArgumentNullException("signedRequest"); } var token = GetFacebookToken(website, signedRequest); var userId = token.GetValue("user_id"); if (userId == null) { return(null); } var authenticationType = GetFacebookAuthenticationType(website); var providerKey = userId.Value <string>(); var issuer = authenticationType.LoginProvider; var claims = new List <Claim> { new Claim(ClaimTypes.NameIdentifier, providerKey, null, issuer, issuer) }; if (!string.IsNullOrWhiteSpace(authenticationType.ProviderKey)) { claims.Add(new Claim(IdentityModel.Claims.ClaimTypes.IdentityProvider, authenticationType.ProviderKey, null, issuer, issuer)); } var login = new ExternalLoginInfo { ExternalIdentity = new ClaimsIdentity(claims), DefaultUserName = providerKey, Login = new UserLoginInfo(issuer, providerKey), }; return(login); }
private static ViewDataAdapter SetViewDataAdapter(ViewConfiguration viewConfiguration, string sortExpression, string search, string filter, string metaFilter, int page, bool applyRecordLevelFilters, bool applyRelatedRecordFilter, string filterRelationshipName, string filterEntityName, string filterAttributeName, Guid?filterValue, IDictionary <string, string> customParameters, PortalConfigurationDataAdapterDependencies dataAdapterDependencies, CrmWebsite website) { var viewDataAdapter = applyRelatedRecordFilter && (!string.IsNullOrWhiteSpace(filterRelationshipName) && !string.IsNullOrWhiteSpace(filterEntityName)) ? new ViewDataAdapter(viewConfiguration, dataAdapterDependencies, filterRelationshipName, filterEntityName, filterAttributeName, filterValue ?? Guid.Empty, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters, customParameters: customParameters) : new ViewDataAdapter(viewConfiguration, dataAdapterDependencies, page, search, sortExpression, filter, metaFilter, applyRecordLevelFilters, customParameters: customParameters); var siteSettings = new SettingDataAdapter(dataAdapterDependencies, website); var multiQueryEntities = (siteSettings.GetValue("Grid/DoQueryPerRecordLevelFilter/Entities") ?? string.Empty) .Split(',') .ToLookup(e => e, StringComparer.OrdinalIgnoreCase); viewDataAdapter.DoQueryPerRecordLevelFilter = multiQueryEntities.Contains(viewConfiguration.EntityName); return(viewDataAdapter); }
public CmsSolutionDefinitionProvider(PortalSolutions portalSolutions, CrmWebsite website) : base(portalSolutions) { _website = website; }
private static Entity GetArticle(OrganizationServiceContext serviceContext, string number, CrmWebsite website, string lang, out string languageLocaleCode) { const int published = 3; var portalContext = PortalCrmConfigurationManager.CreatePortalContext(); languageLocaleCode = lang; // If language locale code is NOT provided and multi-language is enabled, then use the context website language. var contextLanguageInfo = System.Web.HttpContext.Current.GetContextLanguageInfo(); if (contextLanguageInfo.IsCrmMultiLanguageEnabled && string.IsNullOrWhiteSpace(languageLocaleCode)) { languageLocaleCode = contextLanguageInfo.ContextLanguage.Code; } // If language locale code is NOT provided and we're not using multi-language, fall back to site setting. else if (string.IsNullOrWhiteSpace(languageLocaleCode)) { languageLocaleCode = portalContext.ServiceContext.GetSiteSettingValueByName(portalContext.Website, "KnowledgeManagement/Article/Language"); } var optionalLanguageCondition = string.IsNullOrWhiteSpace(languageLocaleCode) ? string.Empty : string.Format("<condition entityname='language_locale' attribute='code' operator='eq' value = '{0}' />", languageLocaleCode); var articlesFetchXml = string.Format(ArticlesFetchXmlFormat, published, number, optionalLanguageCondition); var fetchArticles = Fetch.Parse(articlesFetchXml); var settings = website.Settings; var productFilteringOn = settings.Get <bool>(ProductFilteringSiteSettingName); var calFilteringOn = settings.Get <bool>(CalEnabledSiteSettingName); if (calFilteringOn) { // Apply CAL filtering var contentAccessLevelProvider = new ContentAccessLevelProvider(); contentAccessLevelProvider.TryApplyRecordLevelFiltersToFetch(CrmEntityPermissionRight.Read, fetchArticles); } if (productFilteringOn) { // Apply Product filtering var productAccessProvider = new ProductAccessProvider(); productAccessProvider.TryApplyRecordLevelFiltersToFetch(CrmEntityPermissionRight.Read, fetchArticles); } var article = serviceContext.RetrieveSingle(fetchArticles, false, false, RequestFlag.AllowStaleData); return(article); }