【问题标题】:Silveright - extending AuthenticationService to provide custom authenticationSilveright - 扩展 AuthenticationService 以提供自定义身份验证
【发布时间】:2010-07-07 09:23:30
【问题描述】:

我正在尝试添加到 Silverlight 4 业务模板中提供的身份验证系统,因为我的模型不完全符合模板中提供的模型。我有一个现有的 Web 服务,它执行我的身份验证并提供角色以及每个角色的允许操作。这是 AzMan/Authentication Manager 提供的模型。

但是,除了获得单个角色之外,在身份验证之后,我会为用户提供可用角色列表,并允许用户选择其中一个角色,然后获得该选定角色的操作/操作列表。

我遇到的问题是我不知道如何向身份验证服务添加新方法以允许我获取当前用户和当前选择的角色的操作以完成登录过程,例如

    public SessionInfo GetOperations(string username, string selectedRole)
    {
        SessionInfo sessionInfo;

        using (AzManServiceClient azClient = new AzManServiceClient("AnonymousAuthentication"))
        {
            sessionInfo = azClient.LoginUserByUsername("msldap://CN=LiveApps,CN=Program Data,DC=HLSUK,DC=local", "AIRS", selectedRole, null, username);
        }

        return sessionInfo;
    }

使用 WebContextBase.Current.Authentication 从 LoginForm.xaml.cs 无法访问上述方法...只有诸如 Login 之类的方法是可见的,这更加令人困惑,因为我在 authenticationbase 中看不到这些方法。我完全糊涂了。如何向身份验证服务添加新方法,或者我应该创建一个新的域服务,还是应该访问 azman 服务以直接从 silverlight 客户端获取操作。

【问题讨论】:

    标签: silverlight authentication azman domainservices


    【解决方案1】:

    您是否尝试过覆盖 AuthenticationBase 中的方法?

    然后,您可以使用任何您想要的逻辑来扩展您的身份验证服务。

     <EnableClientAccess()>
            Public Class AuthenticationRiaService
                Inherits AuthenticationBase(Of UserAccount)
    
                Protected Overrides Function ValidateUser(ByVal userName As String, ByVal password As String) As Boolean
                End Function
        End Class
    

    也设置

    WebContext.Current.Authentication 到命名空间 System.ServiceModel.DomainServices.Client.ApplicationServices 中的身份验证服务

    对不起,愚蠢的 VB 代码。 :D

    【讨论】:

    • 是的,我正在扩展身份验证基础,并且 GetOperations 方法是扩展类的一部分 - 为什么我看不到它?
    • 您是否将 WebContext.Current.Authentication 设置为您的身份验证服务?如果使用 Unitycontainer:Container.RegisterInstance(Of AuthenticationService)(WebContext.Current.Authentication)
    • 我们通过 new AuthenticationService().Login() 访问 Login 方法,因此您应该能够以这种方式访问​​您的方法。不是通过 WebContext.Current.
    • 我确实将 WebContext.Current.Authentication 设置为我的身份验证服务。我可以看到登录方法,只是看不到任何“新”方法。即使我这样做 var x = new AuthenticationContext(); x.GetOperations(y,z);它声称 GetOperations 不存在!
    • 当,你说得对。只有登录可用。但是当您在覆盖 ValidateUser 的同时调用 login 时,您最终会到达那里。你能从那里做你的逻辑吗?否则,您似乎必须创建另一个域服务来处理与身份验证不同的事情。也许身份验证库仅用于处理登录/注销/isloggedin 等。然后你必须有一个 useraccountservice 或处理角色等的东西。:)
    猜你喜欢
    • 2012-04-05
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2013-11-15
    • 2020-07-23
    • 2017-11-21
    • 2011-02-09
    • 2021-09-11
    相关资源
    最近更新 更多