SlideShare a Scribd company logo
Integrating Security Roles into Microsoft Silverlight Applications
Integrating Security Roles into Microsoft Silverlight ApplicationsDEV356Dan WahlinWahlin Consulting
AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
Silverlight Security OptionsSilverlight Authentication:WindowsFormsCustomSilverlight Authorization:Active Directory GroupsForms RolesCustom Roles
Windows Authentication OptionsOption 1: Secure page hosting Silverlight controlEasiestUser promptedSilverlight app securedOption 2: Secure backend servicesSilverlight application is anonymousCalls to service require credentialsClient HTTP stack can be used
Using the Client HTTP Stack//Set once in App.xaml.csHttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);....WebClientwc = new WebClient();wc.UseDefaultCredentials = false;wc.Credentials = new NetworkCredential("username",  "password", "domain");
AgendaSecuring Silverlight ApplicationsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
Accessing a User's CredentialsSilverlight does not support accessing the User object directlyUser.Identity.NameOptions for accessing the user name:initParams (be careful!)Use a serviceWCF RIA Services
Passing the User Name with initParamsUser Name can be passed dynamically into Silverlight using initParamsBe Careful!
Using initParams<param name="initParams" value="UserName=<%=User.Identity.Name%>" />…private void Application_Startup(object sender, StartupEventArgs e) {ProcessInitParams(e.InitParams);this.RootVisual = new MainPage();}void ProcessInitParams(IDictionary<string, string> initParams) {    if (initParams != null)  {foreach (var item in initParams)  {this.Resources.Add(item.Key, item.Value);        }    }}
Creating a User Credentials ServiceCreate a User Credentials WCF/ASMX service:Service handles returning authenticated user's informationNo risk of a spoofed User Name as with initParamsService can return additional information such as rolesWCF RIA Services does this out-of-the-box
Returning a User Name from a Service[OperationContract]public string GetLoggedInUserName() {   return new SecurityRepository()           .GetUserName(OperationContext.Current);}public class SecurityRepository {    public string GetUserName(OperationContextopContext) {        return (opContext.ServiceSecurityContext != null && opContext.ServiceSecurityContext.WindowsIdentity != null) ? opContext.ServiceSecurityContext.WindowsIdentity.Name : null;    }}
demoAccessing an Authenticated User's User Name
AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
Accessing User RolesOptions:Pass user roles into application using initParamsCreate a security service operation that returns rolesBe Careful!
Returning Roles from a Service[OperationContract]public List<Role> GetRoles(){    return new SecurityRepository().GetRoles(OperationContext.Current);}public class SecurityRepository {    public List<Role> GetRoles(OperationContextopContext)    {varuserName = GetUserName(opContext);        //Get roles from Active Directory, Database, or elsewhere    }}
demoAccessing User Roles
AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
How do you access and manage user names and roles in a Silverlight application?
Creating a SecurityManager ClassSecurityManager class can act as client-side gateway to user credentials:Accesses user credentials asynchronouslyDetermine user role(s)Determine access to viewMVVM compliantAdd to ViewModel base class through aggregation
The SecurityManager Class[Export(typeof(ISecurityManager))][PartCreationPolicy(CreationPolicy.Shared)]public class SecurityManager : ISecurityManager {public event EventHandlerUserSecurityLoaded; public boolIsUserSecurityLoadComplete { get; set; }       public ObservableCollection<Role> UserRoles { get; set; }    public string UserName { get; set; }    public boolIsAdmin { get; }    public boolIsInUserRole { get; }    public boolIsValidUser { get; }    private void GetUserSecurityDetails() {}    public boolCheckUserAccessToUri(Uri uri) {}    public boolUserIsInRole(string role) {}    public boolUserIsInAnyRole(params string[] roles) {}}
Using the SecurityManager Classpublic class ViewModelBase: INotifyPropertyChanged { [Import]public ISecurityManagerSecurityManager { get; set; }}public class MainPageViewModel : ViewModelBase {    public MainPageViewModel() {if (!IsDesignTime) SecurityManager.UserSecurityLoaded +=  SecurityManagerUserSecurityLoaded;    }    void SecurityManagerUserSecurityLoaded(object sender, EventArgs e) {IsAdmin = SecurityManager.IsAdmin;   //Set INPC propertyUserName = SecurityManager.UserName; //Set INPC property    }}
demoCreating and using a SecurityManager Class
SummarySilverlight doesn’t provide direct access to user credentialsDifferent techniques can be used to access a user name and roles:Pass into initParams (be careful!)Access data through a security serviceUse WCF RIA Service's WebContext classThe SecurityManager class can simplify the process of working with user credentialsHandles async calls to security service Stores user credentials and provides security logicIntegrates well with MVVM
Contact InfoBloghttp://weblogs.asp.net/dwahlinTwitter@DanWahlinBloghttp://weblogs.asp.net/dwahlinTwitter@DanWahlin
Related ContentRequired SlideSpeakers, please list the Breakout Sessions, Interactive Discussions, Labs, Demo Stations and Certification Exam that relate to your session. Also indicate when they can find you staffing in the TLC.DEV209: From Zero to Silverlight in 75 MinutesDEV210: Microsoft Silverlight, WCF RIA Services and Your Business ObjectsDEV331: A Lap around Microsoft Silverlight 5DEV386HOL: Microsoft Silverlight Data BindingDEV388HOL: Web Services and Microsoft SilverlightDEV390HOL: Using the MVVM Pattern in Microsoft Silverlight Applications
Track ResourcesRequired Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Resource 1Resource 2Resource 3Resource 4
ResourcesConnect. Share. Discuss.http://northamerica.msteched.comLearningSessions On-Demand & CommunityMicrosoft Certification & Training Resourceswww.microsoft.com/techedwww.microsoft.com/learningResources for IT ProfessionalsResources for Developershttp://microsoft.com/technethttp://microsoft.com/msdn
Required SlideComplete an evaluation on CommNet and enter to win!
Required Slide Your MS Tag will be inserted here during the final scrub. MS Tag Placeholder Slide
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related Content

PPTX
CloudBrew: Windows Azure Mobile Services - Next stage
PPT
Web 20 Security - Vordel
PPTX
Android+ax+app+wcf
DOCX
Android ax app wcf
PDF
struts
PDF
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
PDF
softshake 2014 - Java EE
PPTX
Java EE 8 security and JSON binding API
CloudBrew: Windows Azure Mobile Services - Next stage
Web 20 Security - Vordel
Android+ax+app+wcf
Android ax app wcf
struts
Mixing OAuth 2.0, Jersey and Guice to Build an Ecosystem of Apps - JavaOne...
softshake 2014 - Java EE
Java EE 8 security and JSON binding API

What's hot (20)

PDF
iOS Masque Attack
PPT
Java Security And Authentacation
PPTX
Application Instrumentation with WMI
PDF
Wicket 6
PPTX
Community call: Develop multi tenant apps with the Microsoft identity platform
PDF
Spring Framework - Data Access
PPTX
Mockito junit
PPTX
Using the Tooling API to Generate Apex SOAP Web Service Clients
PDF
Paul Lammertsma: Account manager & sync
PDF
Jetpack, with new features in 2021 GDG Georgetown IO Extended
PPTX
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
DOCX
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
PDF
Distributing information on iOS
PPTX
Learn Apache Shiro
PDF
Mvc interview questions – deep dive jinal desai
PPTX
Building secure applications with keycloak
PDF
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
PPTX
Microsoft identity platform community call-May 2020
PPTX
Microservice Protection With WSO2 Identity Server
PDF
Lecture 3: Servlets - Session Management
iOS Masque Attack
Java Security And Authentacation
Application Instrumentation with WMI
Wicket 6
Community call: Develop multi tenant apps with the Microsoft identity platform
Spring Framework - Data Access
Mockito junit
Using the Tooling API to Generate Apex SOAP Web Service Clients
Paul Lammertsma: Account manager & sync
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Distributing information on iOS
Learn Apache Shiro
Mvc interview questions – deep dive jinal desai
Building secure applications with keycloak
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Microsoft identity platform community call-May 2020
Microservice Protection With WSO2 Identity Server
Lecture 3: Servlets - Session Management
Ad

Viewers also liked (18)

PPTX
Development Trends - What's New in the World of Web Development
PPTX
Building an End-to-End AngularJS Application
PPTX
Building AngularJS Custom Directives
PPTX
Getting Started with ASP.NET MVC 3 and Razor
PPT
Top 13 Web Development Trends And Predictions For 2015
PDF
Lastest Trends in Web Development
PPTX
AngularJS in 60ish Minutes
PPTX
JavaScript Patterns to Cleanup your Code
PPT
Using jQuery Templates
PPTX
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
PPTX
Basics of angular directive (Part - 1)
PDF
Custom AngularJS Directives
PDF
AngularJS Custom Directives
PPTX
AngularJS custom directive
PDF
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
PPTX
Enterprise mobility management a comprehensive guide
PPTX
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
PPTX
Web Development Trends 2016
Development Trends - What's New in the World of Web Development
Building an End-to-End AngularJS Application
Building AngularJS Custom Directives
Getting Started with ASP.NET MVC 3 and Razor
Top 13 Web Development Trends And Predictions For 2015
Lastest Trends in Web Development
AngularJS in 60ish Minutes
JavaScript Patterns to Cleanup your Code
Using jQuery Templates
Building the an End-to-End ASP.NET MVC 4, Entity Framework, HTML5, jQuery app...
Basics of angular directive (Part - 1)
Custom AngularJS Directives
AngularJS Custom Directives
AngularJS custom directive
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Enterprise mobility management a comprehensive guide
Getting Started Building Windows 8 HTML/JavaScript Metro Apps
Web Development Trends 2016
Ad

Similar to Integrating Security Roles into Microsoft Silverlight Applications (20)

PDF
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
PPTX
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
PPTX
Developing your first application using FI-WARE
KEY
CDI e as ideias pro futuro do VRaptor
PPTX
Html bridge
PDF
vCloud SDK for PHP - Introduction
KEY
Multi Client Development with Spring
PDF
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
PPTX
Windows Store app using XAML and C#: Enterprise Product Development
PPTX
Hacking 101 3
PPTX
Developing your first application using FIWARE
PPTX
MongoDB.local Atlanta: Introduction to Serverless MongoDB
PDF
WinAppDriver - Windows Store Apps Test Automation
PPT
Implementing application security using the .net framework
PPTX
State management
PDF
Serverless Angular, Material, Firebase and Google Cloud applications
PPTX
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
PPTX
Lunch Learn - WCF Security
PDF
DataFX 8 (JavaOne 2014)
PPTX
2008 - TechDays PT: Building Software + Services with Volta
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
Developing your first application using FI-WARE
CDI e as ideias pro futuro do VRaptor
Html bridge
vCloud SDK for PHP - Introduction
Multi Client Development with Spring
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Windows Store app using XAML and C#: Enterprise Product Development
Hacking 101 3
Developing your first application using FIWARE
MongoDB.local Atlanta: Introduction to Serverless MongoDB
WinAppDriver - Windows Store Apps Test Automation
Implementing application security using the .net framework
State management
Serverless Angular, Material, Firebase and Google Cloud applications
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
Lunch Learn - WCF Security
DataFX 8 (JavaOne 2014)
2008 - TechDays PT: Building Software + Services with Volta

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
KodekX | Application Modernization Development
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KodekX | Application Modernization Development
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf

Integrating Security Roles into Microsoft Silverlight Applications

  • 2. Integrating Security Roles into Microsoft Silverlight ApplicationsDEV356Dan WahlinWahlin Consulting
  • 3. AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
  • 4. Silverlight Security OptionsSilverlight Authentication:WindowsFormsCustomSilverlight Authorization:Active Directory GroupsForms RolesCustom Roles
  • 5. Windows Authentication OptionsOption 1: Secure page hosting Silverlight controlEasiestUser promptedSilverlight app securedOption 2: Secure backend servicesSilverlight application is anonymousCalls to service require credentialsClient HTTP stack can be used
  • 6. Using the Client HTTP Stack//Set once in App.xaml.csHttpWebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp);....WebClientwc = new WebClient();wc.UseDefaultCredentials = false;wc.Credentials = new NetworkCredential("username", "password", "domain");
  • 7. AgendaSecuring Silverlight ApplicationsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
  • 8. Accessing a User's CredentialsSilverlight does not support accessing the User object directlyUser.Identity.NameOptions for accessing the user name:initParams (be careful!)Use a serviceWCF RIA Services
  • 9. Passing the User Name with initParamsUser Name can be passed dynamically into Silverlight using initParamsBe Careful!
  • 10. Using initParams<param name="initParams" value="UserName=<%=User.Identity.Name%>" />…private void Application_Startup(object sender, StartupEventArgs e) {ProcessInitParams(e.InitParams);this.RootVisual = new MainPage();}void ProcessInitParams(IDictionary<string, string> initParams) { if (initParams != null) {foreach (var item in initParams) {this.Resources.Add(item.Key, item.Value); } }}
  • 11. Creating a User Credentials ServiceCreate a User Credentials WCF/ASMX service:Service handles returning authenticated user's informationNo risk of a spoofed User Name as with initParamsService can return additional information such as rolesWCF RIA Services does this out-of-the-box
  • 12. Returning a User Name from a Service[OperationContract]public string GetLoggedInUserName() { return new SecurityRepository() .GetUserName(OperationContext.Current);}public class SecurityRepository { public string GetUserName(OperationContextopContext) { return (opContext.ServiceSecurityContext != null && opContext.ServiceSecurityContext.WindowsIdentity != null) ? opContext.ServiceSecurityContext.WindowsIdentity.Name : null; }}
  • 14. AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
  • 15. Accessing User RolesOptions:Pass user roles into application using initParamsCreate a security service operation that returns rolesBe Careful!
  • 16. Returning Roles from a Service[OperationContract]public List<Role> GetRoles(){ return new SecurityRepository().GetRoles(OperationContext.Current);}public class SecurityRepository { public List<Role> GetRoles(OperationContextopContext) {varuserName = GetUserName(opContext); //Get roles from Active Directory, Database, or elsewhere }}
  • 18. AgendaSilverlight Security OptionsAccessing User Identity InformationAccessing User RolesCreating a SecurityManager class
  • 19. How do you access and manage user names and roles in a Silverlight application?
  • 20. Creating a SecurityManager ClassSecurityManager class can act as client-side gateway to user credentials:Accesses user credentials asynchronouslyDetermine user role(s)Determine access to viewMVVM compliantAdd to ViewModel base class through aggregation
  • 21. The SecurityManager Class[Export(typeof(ISecurityManager))][PartCreationPolicy(CreationPolicy.Shared)]public class SecurityManager : ISecurityManager {public event EventHandlerUserSecurityLoaded; public boolIsUserSecurityLoadComplete { get; set; } public ObservableCollection<Role> UserRoles { get; set; } public string UserName { get; set; } public boolIsAdmin { get; } public boolIsInUserRole { get; } public boolIsValidUser { get; } private void GetUserSecurityDetails() {} public boolCheckUserAccessToUri(Uri uri) {} public boolUserIsInRole(string role) {} public boolUserIsInAnyRole(params string[] roles) {}}
  • 22. Using the SecurityManager Classpublic class ViewModelBase: INotifyPropertyChanged { [Import]public ISecurityManagerSecurityManager { get; set; }}public class MainPageViewModel : ViewModelBase { public MainPageViewModel() {if (!IsDesignTime) SecurityManager.UserSecurityLoaded += SecurityManagerUserSecurityLoaded; } void SecurityManagerUserSecurityLoaded(object sender, EventArgs e) {IsAdmin = SecurityManager.IsAdmin; //Set INPC propertyUserName = SecurityManager.UserName; //Set INPC property }}
  • 23. demoCreating and using a SecurityManager Class
  • 24. SummarySilverlight doesn’t provide direct access to user credentialsDifferent techniques can be used to access a user name and roles:Pass into initParams (be careful!)Access data through a security serviceUse WCF RIA Service's WebContext classThe SecurityManager class can simplify the process of working with user credentialsHandles async calls to security service Stores user credentials and provides security logicIntegrates well with MVVM
  • 26. Related ContentRequired SlideSpeakers, please list the Breakout Sessions, Interactive Discussions, Labs, Demo Stations and Certification Exam that relate to your session. Also indicate when they can find you staffing in the TLC.DEV209: From Zero to Silverlight in 75 MinutesDEV210: Microsoft Silverlight, WCF RIA Services and Your Business ObjectsDEV331: A Lap around Microsoft Silverlight 5DEV386HOL: Microsoft Silverlight Data BindingDEV388HOL: Web Services and Microsoft SilverlightDEV390HOL: Using the MVVM Pattern in Microsoft Silverlight Applications
  • 27. Track ResourcesRequired Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Resource 1Resource 2Resource 3Resource 4
  • 28. ResourcesConnect. Share. Discuss.http://northamerica.msteched.comLearningSessions On-Demand & CommunityMicrosoft Certification & Training Resourceswww.microsoft.com/techedwww.microsoft.com/learningResources for IT ProfessionalsResources for Developershttp://microsoft.com/technethttp://microsoft.com/msdn
  • 29. Required SlideComplete an evaluation on CommNet and enter to win!
  • 30. Required Slide Your MS Tag will be inserted here during the final scrub. MS Tag Placeholder Slide
  • 31. © 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Editor's Notes

  • #6: Option 1: Secure page hosting Silverlight control:Easiest approachSilverlight application isn&apos;t accessed until user authenticatesUser prompted for credentials or credentials are passed throughOption 2: Secure backend servicesAnonymous application accessCalls to services prompt for authentication credentialsUse Client HTTP Stack to set network credentials programmatically (example shown next)
  • #9: Use WCF RIA Service&apos;s WebContext class:WebContext.Current.Authentication.User
  • #10: Be Careful!Hacker could change value passed into initParamsIf application simply displays the User Name then no problemIf application relies on User Name to lookup roles and more from services this can be a bad solution
  • #16: Be Careful!Embedding roles in initParams opens the application to spoofingReturning roles from a service call is the best option
  • #31: New for TechEd 2011, we will be working with Microsoft Tag (http://tag.microsoft.com/overview.aspx) to create unique Tags for every session at the event. Your session Tag will appear on both the room signage and at the end of your presentation. With your session Tag, attendees will be able to scan as they enter the room to retrieve session details, view speaker bios, and engage in discussions; or scan at the end of the presentation to evaluate your session and download materials. We’re excited to integrate Microsoft Tag across the My TechEd mobile experience this year.