Setting Principal for HttpWorkerRequest

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Setting Principal for HttpWorkerRequest

    re: [url]http://www.dotnet247.com/247reference/msgs/31/159270.aspx[/url]
    (neither my news server, nor microsoft's seems to still carry this thread)

    I am trying to add User Authentication to Cassini.

    More specifically I am using Cassini as a web-server back end to a GUI
    application (with a web browser control navigating the cassini web server)
    and I want User.Identity to be set to the same login details as the User
    running the GUI application hosting Cassini.

    At the moment I have added the following lines to the web application's
    global.asax.vb:
    if (!User.Identity.IsAuthenticated) {
    IIdentity id = new GenericIdentity(Environment.UserDomainName + @"\" +
    Environment.UserName);
    IPrincipal ip = new GenericPrincipal(id, new string[0]);
    Context.User = ip;
    }

    This at least simulates the user being logged in.

    I would prefer to add it to Cassini instead, because then I can host
    exisiting web applications with-no-change. (This includes adding an
    HTTPModule in the web.config)

    I tried settings the CurrentThread.Identity in Host.Configure in Cassini,
    but with no effect. Request.Process has the same problem I seem to
    remember.

    How is it possible to set the Context.User from the hosting thread in
    Cassini?

    Norman Rasmussen

    open box software
    T +27 21 701 7884 | M +27 (0) 83 418 9799
    E [email]nrasmussen@openboxsoftware.com[/email] | W [url]www.openboxsoftware.com[/url]


    Norman Rasmussen Guest

  2. Similar Questions and Discussions

    1. Web Service w custom Principal
      We have a class that Implements IPrincipal (System.Security.Principal.IPrincipal). We have a business logic class library assembly that checks the...
    2. Custom Principal
      Hi, I use Custom Principal and it works well on my PC (Localhost). When I deploy it at my hosting service it fails. I print out...
    3. Enum All Roles in a Principal?
      I know how to do ..IsInRole() to test if a user is in a particular role. How do I enumerate all of the roles currently attached to my principal...
    4. Custom Windows Authentication Principal?
      Ok here's the situation, I have several intranet applications at this company that use windows authentication. Now when people open the...
    5. Set Windows Principal
      Hi, My current legacy asp/becoming-asp.net application uses IIS Windows Authentication at present. What I need to do is let a user coming from...
  3. #2

    Default Re: Setting Principal for HttpWorkerRequest

    I have slightly more luck in getting Cassini to act as if the user logged-in
    via a web server. Because I am only intrested in Cassini running as a local
    host for the application, I am happy to assume the user running the GUI
    application (and therefore Cassini) is the user I am authenticating as.

    Bascially I set the PrinciplePolicy to use the current login and its
    associated groups as the user identity & its roles. Then I return the
    required information to the WindowsAuthenticationModule to make it get the
    user token and use it for the current context.

    If you wanted to create a fully fledged authentication module for Cassini
    then you would not change the priciple policy, and you would have to use
    LogonUser to create a new token and then store it instead of using the
    current thread's identity. (as described in the WindowsIdentity.Impersonate
    example code)

    Note: that in the web.config file:
    <!-- Most user accounts are not granted the right to impersonate by the
    Security Policy (either local or domain) -->
    <identity impersonate="false"/>
    <!-- FileAuthorization via FileSecurityDescriptorWrapper uses IIS to check
    if the file can be accessed and therefore can't be used with Cassini-->
    <httpModules><remove name="FileAuthorization"/></httpModules>

    So, added details are as follows:

    Host.cs, Line 72:
    Thread.GetDomain().SetPrincipalPolicy(System.Secur ity.Principal.PrincipalPol
    icy.WindowsPrincipal);

    Request.cs, Line 20:
    using System.Security.Principal;

    Request.cs, Line Line 67:
    private IIdentity _identity;

    Request.cs, Line 127:
    _identity = Thread.CurrentPrincipal.Identity;

    Request.cs, Line 525:
    case "LOGON_USER":
    s = _identity.Name;
    break;
    case "AUTH_TYPE":
    s = _identity.AuthenticationType;
    break;

    Request.cs, Line 730:
    public override System.IntPtr GetUserToken() {
    if (_identity.GetType() == typeof(WindowsIdentity))
    return ((WindowsIdentity)_identity).Token;
    else
    return IntPtr.Zero;
    }

    Norman Rasmussen

    open box software
    T +27 21 701 7884 | M +27 (0) 83 418 9799
    E [email]nrasmussen@openboxsoftware.com[/email] | W [url]www.openboxsoftware.com[/url]


    Norman Rasmussen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139