Silverlight RIA Services - how to perform Windows authentication?

I am building my first Silverlight 3 + RI Services application and need some help.
It will be deployed on a controlled corporate intranet, 100% Windows clients. I started with the Silverlight business application template.
These are my requirements:

  • At startup, the application should recognize the registered user.
  • An application must have access to other user properties in AD, such as email, full name, and group membership.
  • Group membership is used for certain specific functions in the application.
  • A link to "login as another user" should always be available. Some machines are available at all enterprises, logged in as a specific common user (confirmed by the absence of certain groups of participants). In this case, you can enter the credentials and log in (impersonate) as a user other than the user already registered on the computer.
  • This user must be used in service calls.


I changed the following in the default business application template:

  • App.xaml: appsvc: WindowsAuthentication instead of the standard FormsAuthentication form
  • Web.config: authentication mode = "Windows"

№1 ( ). RiaContext.Current.User, AD, . ?

.

+5
3

, , , .

13.3 RIA , .

RIA Services , , .

+4

AuthenticationService, BusinessApplicationTemplate.

 [EnableClientAccess]
    public class AuthenticationService : AuthenticationBase<User> {

    protected override User  GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)
    {
        User user = base.GetAuthenticatedUser(principal);
        Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
        SystemWebSectionGroup grp = (SystemWebSectionGroup)config.GetSectionGroup("system.web");
        AuthenticationSection auth = grp.Authentication;
        if (auth.Mode == AuthenticationMode.Forms)
        {
        }
        else if (auth.Mode == AuthenticationMode.Windows)
        {
            string[] a = user.Name.Split('\\');
            System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
            string Name = ADEntry.Properties["FullName"].Value.ToString();
            user.Name = Name;
        }
        return user;
    }
}
+3

Hi everyone, new article on MSDN, I am working on it now.

http://msdn.microsoft.com/en-us/library/ee707353(VS.91).aspx

+3
source

All Articles