136 CHAPTER 5 PERMUTATIONS PATTERN E B

136 CHAPTER 5 PERMUTATIONS PATTERN E B V is commonplace; a simple example is a shopping cart. A shopping cart is a resource, requires the identification of some user, and uses URL rewriting. Additionally, the shopping cart adds the complexity of performing a URL redirection to an unknown resource. Imagine that I will be buying something at Amazon.com. The Amazon shopping cart will contain what I want to buy. What is unknown is the shopping cart that Amazon uses to reference the items that I want to buy. Shopping carts can be associated with and authorized by only a single person. From a logic perspective, while shopping at Amazon, I do not want somebody to add or remove items from my shopping cart. Additionally, I do not want somebody to be able to create a shopping cart in my name and ship it to another address. So in the end, even though it is not obvious, a shopping cart is a very personal resource. If the user is authenticated, the shopping cart is associated with the authenticated user. If the user is not authenticated, the shopping cart is associated with the client using a cookie. In either case, a cookie could be used to authorize who is allowed to manipulate the shopping cart. The URL for the shopping cart would be /shoppingcart/12324, but the shopping cart can be accessed only by the authenticated user or cookie of the anonymous user. What is never done is the association of the URL /shoppingcart with a specific authenticated user or cookie. Defining the User Identification Interfaces Authenticating a user is the process of creating a user identifier, and there are multiple ways to create a user identifier. This means that when implementing HTTP authentication, some thought should be given to keeping everything neutral so that other user identification implementations could be switched at runtime without affecting how authentication is managed. The solution is to use the Bridge and Factory patterns to define an intention of identifying the user and then define the implementations that technically identify the user. The following source code defines the interfaces for the intention of identifying a user: public interface IUserIdentificationResolver { IUserIdentification Resolve(WebReference reference); } public interface IUserIdentificationFactory { IUserIdentification Create( string identifier); IUserIdentification Create(); } public interface IUserIdentification { string Identifier { get; } bool IsIdentified { get; } } The interface IUserIdentificationResolver<> is defined by using .NET Generics and has a single method, Resolve. .NET Generics are used to define the interface, allowing the interface to be used in multiple user identification implementation contexts. When using Generics, the interface is saying, Given the WebReference type, I will resolve what the user identification mechanism is.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Leave a Reply