alexanderzeitler.com - WCF Web API: Role based access control with basic authentication









Search Preview

WCF Web API: Role based access control with basic authentication | Alexander Zeitler

alexanderzeitler.com

.com > alexanderzeitler.com

SEO audit: Content analysis

Language Error! No language localisation is found.
Title WCF Web API: Role based access control with basic authentication | Alexander Zeitler
Text / HTML ratio 56 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud = roles public resource var request class contacts => attribute access users return _roles RolesAttribute basic based roleRepository _roleRepository Alexander
Keywords consistency
Keyword Content Title Description Headings
= 10
roles 9
public 8
resource 7
var 6
request 6
Headings
H1 H2 H3 H4 H5 H6
1 0 0 0 0 0
Images We found 1 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
= 10 0.50 %
roles 9 0.45 %
public 8 0.40 %
resource 7 0.35 %
var 6 0.30 %
request 6 0.30 %
class 6 0.30 %
contacts 4 0.20 %
=> 4 0.20 %
attribute 4 0.20 %
access 4 0.20 %
users 4 0.20 %
return 4 0.20 %
_roles 3 0.15 %
RolesAttribute 3 0.15 %
basic 3 0.15 %
based 3 0.15 %
roleRepository 2 0.10 %
_roleRepository 2 0.10 %
Alexander 2 0.10 %

SEO Keywords (Two Word)

Keyword Occurrence Density
contacts resource 4 0.20 %
the roles 3 0.15 %
resource class 3 0.15 %
in the 3 0.15 %
public class 3 0.15 %
access to 2 0.10 %
we need 2 0.10 %
from the 2 0.10 %
the authenticated 2 0.10 %
return request 2 0.10 %
the resource 2 0.10 %
want to 2 0.10 %
need to 2 0.10 %
to resources 2 0.10 %
basic authentication 2 0.10 %
WCF Web 2 0.10 %
Web API 2 0.10 %
our contacts 2 0.10 %
based access 2 0.10 %
= attribute 2 0.10 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
we need to 2 0.10 % No
our contacts resource 2 0.10 % No
access to resources 2 0.10 % No
WCF Web API 2 0.10 % No
the resource class 2 0.10 % No
Toggle navigation Home 1 0.05 % No
read from the 1 0.05 % No
is read from 1 0.05 % No
resource is read 1 0.05 % No
requested resource is 1 0.05 % No
the requested resource 1 0.05 % No
of the requested 1 0.05 % No
type of the 1 0.05 % No
Then the type 1 0.05 % No
the type of 1 0.05 % No
to Then the 1 0.05 % No
belongs to Then 1 0.05 % No
user belongs to 1 0.05 % No
auth user belongs 1 0.05 % No
basic auth user 1 0.05 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
Toggle navigation Home Feed 1 0.05 % No
belongs to Then the 1 0.05 % No
resource is read from 1 0.05 % No
requested resource is read 1 0.05 % No
the requested resource is 1 0.05 % No
of the requested resource 1 0.05 % No
type of the requested 1 0.05 % No
the type of the 1 0.05 % No
Then the type of 1 0.05 % No
to Then the type 1 0.05 % No
user belongs to Then 1 0.05 % No
read from the currents 1 0.05 % No
auth user belongs to 1 0.05 % No
basic auth user belongs 1 0.05 % No
through basic auth user 1 0.05 % No
authenticated through basic auth 1 0.05 % No
the authenticated through basic 1 0.05 % No
roles the authenticated through 1 0.05 % No
the roles the authenticated 1 0.05 % No
the the roles the 1 0.05 % No

Internal links in - alexanderzeitler.com

Fixing Chrome 58+ [missing_subjectAltName] with openssl when using self signed certificates
Fixing Chrome 58+ [missing_subjectAltName] with openssl when using self signed certificates | Alexander Zeitler
Accessing an HTTP API running on your MacBook in a Docker container from your iPhone/iPad using dnsmasq
Accessing an HTTP API running on your MacBook in a Docker container from your iPhone/iPad using dnsmasq | Alexander Zeitler
Deploying Ubuntu Mate Desktop as a developer environment in a Azure VM
Deploying Ubuntu Mate Desktop as a developer environment in a Azure VM | Alexander Zeitler
Deploying Ubuntu Mate Desktop as a developer environment in AWS EC2
Deploying Ubuntu Mate Desktop as a developer environment in AWS EC2 | Alexander Zeitler
Debugging mocha tests in a Docker container using Visual Studio Code
Debugging mocha tests in a Docker container using Visual Studio Code | Alexander Zeitler
Debugging mocha tests with Visual Studio Code when Node.js is installed using nvm
Debugging mocha tests with Visual Studio Code when Node.js is installed using nvm | Alexander Zeitler
Debugging a ES6 Node.js application in a Docker container using Visual Studio Code
Debugging a ES6 Node.js application in a Docker container using Visual Studio Code | Alexander Zeitler
Some thoughts on Open Source Software
Some thoughts on Open Source Software | Alexander Zeitler
Resizing a VMware Workstation VM partition using GParted - get the swap partition out of my way!
Resizing a VMware Workstation VM partition using GParted - get the swap partition out of my way! | Alexander Zeitler
Workflows: using Docker Machine and Docker Compose together in development
Workflows: using Docker Machine and Docker Compose together in development | Alexander Zeitler
Chrome crashes on Ubuntu in VMware Workstation
Chrome crashes on Ubuntu in VMware Workstation | Alexander Zeitler
Rename Visual Studio project including files, folders and namespaces
Rename Visual Studio project including files, folders and namespaces | Alexander Zeitler
A lap around AWS and docker-machine
A lap around AWS and docker-machine | Alexander Zeitler
Integration-testing ASP.NET 5 / MVC 6 Controllers on DNX Beta 4
Integration-testing ASP.NET 5 / MVC 6 Controllers on DNX Beta 4 | Alexander Zeitler
Deploying a ASP.NET MVC 6 API as Azure API App in Azure App Services
Deploying a ASP.NET MVC 6 API as Azure API App in Azure App Services | Alexander Zeitler
lowerCamelCase JSON with ASP.NET MVC 6
lowerCamelCase JSON with ASP.NET MVC 6 | Alexander Zeitler
Running ASP.NET 5 Beta 4 in Docker with DNX runtime #aspnet5 #docker
Running ASP.NET 5 Beta 4 in Docker with DNX runtime #aspnet5 #docker | Alexander Zeitler
Stop complaining or improve yourself
Stop complaining or improve yourself | Alexander Zeitler
#NodeJS / #ExpressJS: Adding routes dynamically at runtime
#NodeJS / #ExpressJS: Adding routes dynamically at runtime | Alexander Zeitler
mongoose: Referencing schema in properties or arrays
mongoose: Referencing schema in properties or arrays | Alexander Zeitler
MongoDB development environment journal size management using mongoctl
MongoDB development environment journal size management using mongoctl | Alexander Zeitler
Farewell...
Farewell... | Alexander Zeitler
Inspecting AngularJS $scope using Firebug and Chrome Developer Tools
Inspecting AngularJS $scope using Firebug and Chrome Developer Tools | Alexander Zeitler
Useful @Brackets extensions for Web Developers
Useful @Brackets extensions for Web Developers | Alexander Zeitler
.NET User Group Karlsruhe: StreamInsight: Complex Event Processing by Microsoft
.NET User Group Karlsruhe: StreamInsight: Complex Event Processing by Microsoft | Alexander Zeitler
“Commit all must be called when a managed buffer has focus” in Microsoft SQL Server Data Tools
“Commit all must be called when a managed buffer has focus” in Microsoft SQL Server Data Tools | Alexander Zeitler
.NET User Group Karlsruhe: Git
.NET User Group Karlsruhe: Git | Alexander Zeitler
Open Source Windows 8 App: Sprudelsuche
Open Source Windows 8 App: Sprudelsuche | Alexander Zeitler
Open Source– Scheissegal?
Open Source– Scheissegal? | Alexander Zeitler
Lowercase JSON with ASP.NET Web API
Lowercase JSON with ASP.NET Web API | Alexander Zeitler
.NET Usergroup Karlsruhe: Think Big – Entwicklung skalierbarer Anwendungen mit Windows Azure
.NET Usergroup Karlsruhe: Think Big – Entwicklung skalierbarer Anwendungen mit Windows Azure | Alexander Zeitler
ASP.NET Web API and RavenDb
ASP.NET Web API and RavenDb | Alexander Zeitler
ASP.NET Web API Round-Up Slides
ASP.NET Web API Round-Up Slides | Alexander Zeitler
ASP.NET MVC 4 public beta including ASP.NET Web API
ASP.NET MVC 4 public beta including ASP.NET Web API | Alexander Zeitler
Hash Bang Urls in Single Page Applications mit ASP.NET MVC
Hash Bang Urls in Single Page Applications mit ASP.NET MVC | Alexander Zeitler
.NET User Group Karlsruhe: Know your Tools
.NET User Group Karlsruhe: Know your Tools | Alexander Zeitler
Git flow init liefert: flags: FATAL unable to determine getopt version unter Cygwin
Git flow init liefert: flags: FATAL unable to determine getopt version unter Cygwin | Alexander Zeitler
Using JsonValue and JsonArray in WCF Web API
Using JsonValue and JsonArray in WCF Web API | Alexander Zeitler
.NET User Group Karlsruhe: PowerShell 3.. 2.. 1..
.NET User Group Karlsruhe: PowerShell 3.. 2.. 1.. | Alexander Zeitler
What’s new in WCF Web API Preview 5 – introducing the test client
What’s new in WCF Web API Preview 5 – introducing the test client | Alexander Zeitler
Externe Templates in KnockoutJS laden
Externe Templates in KnockoutJS laden | Alexander Zeitler
WCF Web API: Role based access control with basic authentication
WCF Web API: Role based access control with basic authentication | Alexander Zeitler
.NET User Group Karlsruhe: Produce Cleaner Code with Aspect-Oriented Programming (AOP)
.NET User Group Karlsruhe: Produce Cleaner Code with Aspect-Oriented Programming (AOP) | Alexander Zeitler
REST using the WCF Web API – POST it!
REST using the WCF Web API – POST it! | Alexander Zeitler
REST using the WCF Web API – getting more RESTful responses (Part 5)
REST using the WCF Web API – getting more RESTful responses (Part 5) | Alexander Zeitler
TypeLoadException when mocking COM objects - Could not load type … from assembly. The type is marked…
TypeLoadException when mocking COM objects - Could not load type … from assembly. The type is marked… | Alexander Zeitler
REST using the WCF Web API – getting RESTful the BDD way (Part 4)
REST using the WCF Web API – getting RESTful the BDD way (Part 4) | Alexander Zeitler
REST using the WCF Web API – refactoring to IoC style (Part 3)
REST using the WCF Web API – refactoring to IoC style (Part 3) | Alexander Zeitler
REST using the WCF Web API – Basics (Part2)
REST using the WCF Web API – Basics (Part2) | Alexander Zeitler
Microsoft Web API – the REST is done by WCF (Part 1)
Microsoft Web API – the REST is done by WCF (Part 1) | Alexander Zeitler
Microsoft Web API – den REST macht WCF (Teil 1)
Microsoft Web API – den REST macht WCF (Teil 1) | Alexander Zeitler
.NET User Group Karlsruhe: Flexible Softwarearchitekturen mit Inversion of Control (IoC)
.NET User Group Karlsruhe: Flexible Softwarearchitekturen mit Inversion of Control (IoC) | Alexander Zeitler
machine.fakes ReSharper Templates
machine.fakes ReSharper Templates | Alexander Zeitler
CreateCert.cmd aus dem Windows Azure Platform Training Kit funktioniert nicht
CreateCert.cmd aus dem Windows Azure Platform Training Kit funktioniert nicht | Alexander Zeitler
JSON via jQuery direkt an einen ASP.NET MVC 3 Controller senden
JSON via jQuery direkt an einen ASP.NET MVC 3 Controller senden | Alexander Zeitler
POSTing Json data using the HttpClient from WCF Web API
POSTing Json data using the HttpClient from WCF Web API | Alexander Zeitler
Using the new WCF Web APIs HttpClient with ASP.NET Forms Authentication
Using the new WCF Web APIs HttpClient with ASP.NET Forms Authentication | Alexander Zeitler
Keyboard Jedi unter x64
Keyboard Jedi unter x64 | Alexander Zeitler
Using WCF Web APIs / WCF Http with ASP.NET Forms Authentication
Using WCF Web APIs / WCF Http with ASP.NET Forms Authentication | Alexander Zeitler
WCF Web APIs / WCF Http mit ASP.NET Forms Authentication verwenden
WCF Web APIs / WCF Http mit ASP.NET Forms Authentication verwenden | Alexander Zeitler
ILSpy – Open Source .NET Assembly Browser und Decompiler
ILSpy – Open Source .NET Assembly Browser und Decompiler | Alexander Zeitler

Alexanderzeitler.com Spined HTML


WCF Web API: Role based wangle tenancy with vital hallmark | Alexander Zeitler Toggle navigation Home Feed WCF Web API: Role based wangle tenancy with vital hallmark Written on August 24, 2011 Authenticating users with WCF Web API using vital hallmark is a worldwide use case. Yet this does not unchangingly fit all needs -- sometimes you may want to requite users wangle to resources based on the roles they vest to. We want to proceeds users role based wangle to resources by attributing the resource matriculation with a RolesAttribute: [AttributeUsageAttribute(AttributeTargets.Class)] public matriculation RolesAttribute :Symbol{ readonly string _roles; public RolesAttribute(string roles) { _roles = roles; } public string Roles { get { return _roles; } } } Thus, our contacts resource matriculation could squint like this: [ServiceContract] [Roles("Admins")] public matriculation ContactsResource { [WebGet(UriTemplate = "")] public HttpResponseMessage<List<Contact>> Get(HttpRequestMessage request) { return new HttpResponseMessage<List<Contact>>( new List<Contact>() { new Contact() { Id= Guid.NewGuid(), Name = "Alexander Zeitler" } }); } } Now we need to verify that the authenticated user is in the neccessary roles for our contacts resource. This is washed-up by the use of an HttpOperationHandler. public matriculation RoleRequestHandler : HttpOperationHandler<HttpRequestMessage, HttpRequestMessage> { readonly IRoleRepository _roleRepository; public RoleRequestHandler(IRoleRepository roleRepository) : base("request") { _roleRepository = roleRepository; } public override HttpRequestMessage OnHandle(HttpRequestMessage request) { var userRoles = _roleRepository.GetRolesForUser(Thread.CurrentPrincipal.Identity.Name); var operationContext = OperationContext.Current; var serviceType = operationContext.Host.Description.ServiceType; var symbol = (serviceType.GetCustomAttributes(typeof(RolesAttribute),false)).FirstOrDefault(); if (null != attribute) { var rolesAttribute = symbol as RolesAttribute; var roles = rolesAttribute.Roles.Split(",".ToCharArray()).ToList(); if (roles.Where(r => r.Any(u => userRoles.Contains(r))).Count() > 0) { return request; } else { throw new HttpResponseException( new HttpResponseMessage( HttpStatusCode.Unauthorized, "You're not in the required roles.")); } } return request; } } First, we're retrieving the the roles the authenticated (through vital auth) user belongs to. Then, the type of the requested resource is read from the currents operation context description. After this we try to get the roles symbol from the resource matriculation type and finally trammels if the users matches at least one of these roles specified in the attributed contacts resource. If this is the case, the request is forwarded to the contacts resource. Otherwise we throw an exception containing a 401 unauthorized status lawmaking and a comprehensive reason phrase. To wire things up, we need to assign our request handler to our configuration: configuration .AddRequestHandlers(c => c.Add( new RoleRequestHandler( container.Resolve<IRoleRepository>())), (s, o) => true); Next step should be wangle tenancy at method level - lets see if I can handle this ;-) I'll alimony you up to date... Please enable JavaScript to view the comments powered by Disqus. Copyright © Alexander Zeitler 2003 - 2016 | Impressum