Skip to content

Commit 6dbaa83

Browse files
committed
Add Security trimming Menu example
1 parent c5d893d commit 6dbaa83

File tree

80 files changed

+83631
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+83631
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KendoMenu_SecurityTrimming", "KendoMenu_SecurityTrimming\KendoMenu_SecurityTrimming.csproj", "{A3D62467-E12D-481C-84A6-8520C5A83ADB}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{A3D62467-E12D-481C-84A6-8520C5A83ADB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{A3D62467-E12D-481C-84A6-8520C5A83ADB}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{A3D62467-E12D-481C-84A6-8520C5A83ADB}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{A3D62467-E12D-481C-84A6-8520C5A83ADB}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Web;
2+
using System.Web.Optimization;
3+
4+
namespace KendoMenu_SecurityTrimming
5+
{
6+
public class BundleConfig
7+
{
8+
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
9+
public static void RegisterBundles(BundleCollection bundles)
10+
{
11+
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
12+
"~/Scripts/jquery.validate*"));
13+
14+
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
15+
"~/Scripts/bootstrap.js",
16+
"~/Scripts/respond.js"));
17+
18+
bundles.Add(new StyleBundle("~/Content/css").Include(
19+
"~/Content/bootstrap.css",
20+
"~/Content/site.css"));
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Web;
2+
using System.Web.Mvc;
3+
4+
namespace KendoMenu_SecurityTrimming
5+
{
6+
public class FilterConfig
7+
{
8+
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
9+
{
10+
filters.Add(new HandleErrorAttribute());
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data.Entity;
4+
using System.Linq;
5+
using System.Security.Claims;
6+
using System.Threading.Tasks;
7+
using System.Web;
8+
using Microsoft.AspNet.Identity;
9+
using Microsoft.AspNet.Identity.EntityFramework;
10+
using Microsoft.AspNet.Identity.Owin;
11+
using Microsoft.Owin;
12+
using Microsoft.Owin.Security;
13+
using KendoMenu_SecurityTrimming.Models;
14+
15+
namespace KendoMenu_SecurityTrimming
16+
{
17+
public class EmailService : IIdentityMessageService
18+
{
19+
public Task SendAsync(IdentityMessage message)
20+
{
21+
// Plug in your email service here to send an email.
22+
return Task.FromResult(0);
23+
}
24+
}
25+
26+
public class SmsService : IIdentityMessageService
27+
{
28+
public Task SendAsync(IdentityMessage message)
29+
{
30+
// Plug in your SMS service here to send a text message.
31+
return Task.FromResult(0);
32+
}
33+
}
34+
35+
// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
36+
public class ApplicationUserManager : UserManager<ApplicationUser>
37+
{
38+
public ApplicationUserManager(IUserStore<ApplicationUser> store)
39+
: base(store)
40+
{
41+
}
42+
43+
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
44+
{
45+
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
46+
// Configure validation logic for usernames
47+
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
48+
{
49+
AllowOnlyAlphanumericUserNames = false,
50+
RequireUniqueEmail = true
51+
};
52+
53+
// Configure validation logic for passwords
54+
manager.PasswordValidator = new PasswordValidator
55+
{
56+
RequiredLength = 6,
57+
RequireNonLetterOrDigit = false,
58+
RequireDigit = false,
59+
RequireLowercase = false,
60+
RequireUppercase = false,
61+
};
62+
63+
// Configure user lockout defaults
64+
manager.UserLockoutEnabledByDefault = true;
65+
manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
66+
manager.MaxFailedAccessAttemptsBeforeLockout = 5;
67+
68+
// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
69+
// You can write your own provider and plug it in here.
70+
manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser>
71+
{
72+
MessageFormat = "Your security code is {0}"
73+
});
74+
manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
75+
{
76+
Subject = "Security Code",
77+
BodyFormat = "Your security code is {0}"
78+
});
79+
manager.EmailService = new EmailService();
80+
manager.SmsService = new SmsService();
81+
var dataProtectionProvider = options.DataProtectionProvider;
82+
if (dataProtectionProvider != null)
83+
{
84+
manager.UserTokenProvider =
85+
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
86+
}
87+
return manager;
88+
}
89+
}
90+
91+
// Configure the application sign-in manager which is used in this application.
92+
public class ApplicationSignInManager : SignInManager<ApplicationUser, string>
93+
{
94+
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)
95+
: base(userManager, authenticationManager)
96+
{
97+
}
98+
99+
public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user)
100+
{
101+
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);
102+
}
103+
104+
public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context)
105+
{
106+
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication);
107+
}
108+
}
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.Mvc;
6+
using System.Web.Routing;
7+
8+
namespace KendoMenu_SecurityTrimming
9+
{
10+
public class RouteConfig
11+
{
12+
public static void RegisterRoutes(RouteCollection routes)
13+
{
14+
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
15+
16+
routes.MapRoute(
17+
name: "Default",
18+
url: "{controller}/{action}/{id}",
19+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
20+
);
21+
}
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using Microsoft.AspNet.Identity;
3+
using Microsoft.AspNet.Identity.Owin;
4+
using Microsoft.Owin;
5+
using Microsoft.Owin.Security.Cookies;
6+
using Microsoft.Owin.Security.Google;
7+
using Owin;
8+
using KendoMenu_SecurityTrimming.Models;
9+
10+
namespace KendoMenu_SecurityTrimming
11+
{
12+
public partial class Startup
13+
{
14+
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
15+
public void ConfigureAuth(IAppBuilder app)
16+
{
17+
// Configure the db context, user manager and signin manager to use a single instance per request
18+
app.CreatePerOwinContext(ApplicationDbContext.Create);
19+
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
20+
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
21+
22+
// Enable the application to use a cookie to store information for the signed in user
23+
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
24+
// Configure the sign in cookie
25+
app.UseCookieAuthentication(new CookieAuthenticationOptions
26+
{
27+
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
28+
LoginPath = new PathString("/Account/Login"),
29+
Provider = new CookieAuthenticationProvider
30+
{
31+
// Enables the application to validate the security stamp when the user logs in.
32+
// This is a security feature which is used when you change a password or add an external login to your account.
33+
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
34+
validateInterval: TimeSpan.FromMinutes(30),
35+
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
36+
}
37+
});
38+
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
39+
40+
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
41+
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
42+
43+
// Enables the application to remember the second login verification factor such as phone or email.
44+
// 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.
45+
// This is similar to the RememberMe option when you log in.
46+
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
47+
48+
// Uncomment the following lines to enable logging in with third party login providers
49+
//app.UseMicrosoftAccountAuthentication(
50+
// clientId: "",
51+
// clientSecret: "");
52+
53+
//app.UseTwitterAuthentication(
54+
// consumerKey: "",
55+
// consumerSecret: "");
56+
57+
//app.UseFacebookAuthentication(
58+
// appId: "",
59+
// appSecret: "");
60+
61+
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
62+
//{
63+
// ClientId = "",
64+
// ClientSecret = ""
65+
//});
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
3+
<TelemetryModules>
4+
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector"/>
5+
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
6+
<!--
7+
Use the following syntax here to collect additional performance counters:
8+
9+
<Counters>
10+
<Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
11+
...
12+
</Counters>
13+
14+
PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
15+
16+
Counter names may only contain letters, round brackets, forward slashes, hyphens, underscores, spaces and dots.
17+
You may provide an optional ReportAs attribute which will be used as the metric name when reporting counter data.
18+
For the purposes of reporting, metric names will be sanitized by removing all invalid characters from the resulting metric name.
19+
20+
NOTE: performance counters configuration will be lost upon NuGet upgrade.
21+
22+
The following placeholders are supported as InstanceName:
23+
??APP_WIN32_PROC?? - instance name of the application process for Win32 counters.
24+
??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
25+
??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
26+
-->
27+
</Add>
28+
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector"/>
29+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/>
30+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
31+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
32+
<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
33+
<Handlers>
34+
<!--
35+
Add entries here to filter out additional handlers:
36+
37+
NOTE: handler configuration will be lost upon NuGet upgrade.
38+
-->
39+
<Add>System.Web.Handlers.TransferRequestHandler</Add>
40+
<Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
41+
<Add>System.Web.StaticFileHandler</Add>
42+
<Add>System.Web.Handlers.AssemblyResourceLoader</Add>
43+
<Add>System.Web.Optimization.BundleHandler</Add>
44+
<Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
45+
<Add>System.Web.Handlers.TraceHandler</Add>
46+
<Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
47+
<Add>System.Web.HttpDebugHandler</Add>
48+
</Handlers>
49+
</Add>
50+
<Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/>
51+
</TelemetryModules>
52+
<TelemetryProcessors>
53+
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector"/>
54+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
55+
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
56+
</Add>
57+
</TelemetryProcessors>
58+
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/>
59+
<!--
60+
Learn more about Application Insights configuration with ApplicationInsights.config here:
61+
http://go.microsoft.com/fwlink/?LinkID=513840
62+
63+
Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
64+
-->
65+
<TelemetryInitializers>
66+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
67+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DomainNameRoleInstanceTelemetryInitializer, Microsoft.AI.WindowsServer"/>
68+
<Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/>
69+
<Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web"/>
70+
<Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
71+
<Filters>
72+
<Add Pattern="(YottaaMonitor|BrowserMob|HttpMonitor|YandexBot|BingPreview|PagePeeker|ThumbShotsBot|WebThumb|URL2PNG|ZooShot|GomezA|Catchpoint bot|Willow Internet Crawler|Google SketchUp|Read%20Later|KTXN|Pingdom|AlwaysOn)"/>
73+
<Add Pattern="Slurp" SourceName="Yahoo Bot"/>
74+
<Add Pattern="(bot|zao|borg|Bot|oegp|silk|Xenu|zeal|^NING|crawl|Crawl|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|^Java/|^JNLP/|Daumoa|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|spider|Spider|vortex|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|^voyager|archiver|Icarus6j|mogimogi|Netvibes|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|wsr\-agent|Squrl Java|A6\-Indexer|netresearch|searchsight|http%20client|Python-urllib|dataparksearch|Screaming Frog|AppEngine-Google|YahooCacheSystem|semanticdiscovery|facebookexternalhit|Google.*/\+/web/snippet|Google-HTTP-Java-Client)"
75+
SourceName="Spider"/>
76+
</Filters>
77+
</Add>
78+
<Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/>
79+
<Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/>
80+
<Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
81+
<Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/>
82+
<Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web"/>
83+
<Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web"/>
84+
<Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/>
85+
</TelemetryInitializers>
86+
</ApplicationInsights>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
body {
2+
padding-top: 50px;
3+
padding-bottom: 20px;
4+
}
5+
6+
/* Set padding to keep content from hitting the edges */
7+
.body-content {
8+
padding-left: 15px;
9+
padding-right: 15px;
10+
}
11+
12+
/* Override the default bootstrap behavior where horizontal description lists
13+
will truncate terms that are too long to fit in the left column
14+
*/
15+
.dl-horizontal dt {
16+
white-space: normal;
17+
}
18+
19+
/* Set width on the form input elements since they're 100% wide by default */
20+
input,
21+
select,
22+
textarea {
23+
max-width: 280px;
24+
}

0 commit comments

Comments
 (0)