<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Accessing Principal from VM</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : Community Forum : Accessing Principal from VM</description>
  <pubDate>Fri, 10 Apr 2026 20:04:34 -700</pubDate>
  <lastBuildDate>Sat, 06 Jul 2013 06:21:12 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=4209</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Accessing Principal from VM : Great, thanks Marcel. </title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16546#16546</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=579" rel="nofollow">gregweb</a><br /><strong>Subject:</strong> 4209<br /><strong>Posted:</strong> 06-Jul-2013 at 6:21am<br /><br />Great, thanks Marcel.]]>
   </description>
   <pubDate>Sat, 06 Jul 2013 06:21:12 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16546#16546</guid>
  </item> 
  <item>
   <title>Accessing Principal from VM : Yes, that is the correct way....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16545#16545</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1005" rel="nofollow">mgood</a><br /><strong>Subject:</strong> 4209<br /><strong>Posted:</strong> 05-Jul-2013 at 9:05pm<br /><br />Yes, that is the correct way. The principal should always be retrieved from the AuthenticationService. Instead of injecting the AuthenticationService, though, a cleaner approach is to create a UserService from which you can obtain the principal and other authorization stuff. The UserService uses the AuthenticationService to get the principal and for example cast it to the proper type if you use a custom principal. You can see it in TempHire, although TempHire doesn't actually use the UserService anywhere yet, but it shows the idea. The idea of this approach is to cleanly separate authentication from authorization.<div><div><br></div><div>The interface looks like this:<div><br></div><div><div>&nbsp; &nbsp; public interface IUserService</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; bool IsLoggedIn { get; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; UserPrincipal CurrentUser { get; }</div><div>&nbsp; &nbsp; }</div></div></div></div><div><br></div><div>And the implementation like this. The custom AuthenticationService acts in both capacities, but from the consumption perspective, the two concerns are separated.&nbsp;</div><div><br></div><div><div>&nbsp; &nbsp; &#091;Export(typeof(IAuthenticationService))&#093;</div><div>&nbsp; &nbsp; &#091;Export(typeof(IUserService))&#093;</div><div>&nbsp; &nbsp; &#091;PartCreationPolicy(CreationPolicy.Shared)&#093;</div><div>&nbsp; &nbsp; public class TempHireAuthenticationService : AuthenticationService, IUserService</div><div>&nbsp; &nbsp; {</div><div>#if FAKESTORE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; public TempHireAuthenticationService()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Configure(config =&gt; config.WithConnectionOptions(ConnectionOptions.Fake.Name));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>#endif</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; #region IUserService Members</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; public UserPrincipal CurrentUser</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get { return Principal as UserPrincipal; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; #endregion</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; protected override void OnLoggedIn()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; base.OnLoggedIn();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventFns.Publish(new LoggedInMessage(CurrentUser));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; protected override void OnLoggedOut()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; base.OnLoggedOut();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventFns.Publish(new LoggedOutMessage());</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div></div><div><br></div>]]>
   </description>
   <pubDate>Fri, 05 Jul 2013 21:05:57 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16545#16545</guid>
  </item> 
  <item>
   <title>Accessing Principal from VM : I am populating Principal.Roles...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16531#16531</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=579" rel="nofollow">gregweb</a><br /><strong>Subject:</strong> 4209<br /><strong>Posted:</strong> 04-Jul-2013 at 2:39pm<br /><br />I am populating Principal.Roles on the server.<br /><br />However, it is not clear how to access the Principal on the client. Since Cocktail doesn't allow direct access to the EntityManager, I can't use EntityManager.Principal directly.<br /><br />The only way I have found so far is to import the AuthenticationService into the viewModel, and then check AuthenticationService.Principal.<br /><br />Am I doing this correctly?<br /><br />Greg]]>
   </description>
   <pubDate>Thu, 04 Jul 2013 14:39:48 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4209&amp;PID=16531#16531</guid>
  </item> 
 </channel>
</rss>