diff options
| author | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
|---|---|---|
| committer | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
| commit | 1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch) | |
| tree | 4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/app/Marina/Web/Http/HttpGateway.cs | |
| parent | 42d66bcab8262c7b8b2452615df535e694a3ec1c (diff) | |
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/app/Marina/Web/Http/HttpGateway.cs')
| -rw-r--r-- | slips/src/app/Marina/Web/Http/HttpGateway.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/slips/src/app/Marina/Web/Http/HttpGateway.cs b/slips/src/app/Marina/Web/Http/HttpGateway.cs new file mode 100644 index 0000000..4b91315 --- /dev/null +++ b/slips/src/app/Marina/Web/Http/HttpGateway.cs @@ -0,0 +1,71 @@ +using System;
+using System.Collections.Specialized;
+using System.Security.Principal;
+using System.Web;
+using System.Web.Security;
+using Marina.Infrastructure.Logging.Interfaces;
+using Marina.Presentation;
+using Marina.Web.Views;
+
+namespace Marina.Web.Http {
+ public class HttpGateway : IHttpGateway {
+ public HttpGateway( IHttpContext context ) {
+ _context = context;
+ }
+
+ public string Destination() {
+ return _context.Request.RawUrl;
+ }
+
+ public void RedirectTo( IView view ) {
+ try {
+ _context.Server.Transfer( view.Name( ) );
+ }
+ catch ( Exception ex ) {
+ Log.For( this ).CriticalError( ex.StackTrace );
+ }
+ }
+
+ public void AddAuthenticationCookieFor( string username, long customerId ) {
+ AddCookieToResponse( username, customerId );
+ BindPrincipalToCurrentThread( username );
+ }
+
+ public T ParsePayloadFor< T >( PayloadKey< T > key ) {
+ return key.ParseFrom( Payload( ) );
+ }
+
+ public bool ContainsPayload< T >( PayloadKey< T > key ) {
+ try {
+ ParsePayloadFor( key );
+ return true;
+ }
+ catch ( PayloadKeyNotFoundException ) {
+ return false;
+ }
+ }
+
+ private NameValueCollection Payload() {
+ return new NameValueCollection( _context.Request.Params );
+ }
+
+ private void BindPrincipalToCurrentThread( string username ) {
+ _context.User = new GenericPrincipal( new GenericIdentity( username ), new string[] {"Customer"} );
+ }
+
+ private void AddCookieToResponse( string username, long customerId ) {
+ FormsAuthenticationTicket ticket =
+ new FormsAuthenticationTicket( 1, username, DateTime.Now, DateTime.Now.AddMinutes( 20 ), false,
+ customerId.ToString( ) );
+
+ _context.Response.Cookies.Add( CreateCookieFrom( ticket ) );
+ _context.Response.Cookies.Add( new HttpCookie( PayloadKeys.CustomerId, customerId.ToString( ) ) );
+ }
+
+ private HttpCookie CreateCookieFrom( FormsAuthenticationTicket ticket ) {
+ return new HttpCookie( FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt( ticket ) );
+ }
+
+ private IHttpContext _context;
+ }
+}
\ No newline at end of file |
