17

Silverlight RIAサービスを使用していますが、カスタム認証を作成したいと思います。これは、実質的にドキュメントがない唯一のもののようです(RIAServicesOverview.docx全体を読みました)。

私が顧客認証サービスを作成する方法を知っていますか?デフォルトのASP.NETメンバーシップモデルを使用したくありません。System.Web.Ria.ApplicationServices.IAuthenticationを見つけましたが、実装する必要のあるインターフェイスまたは抽象クラスがわかりません。

IAuthenticationを実装する必要がありますか?もしそうなら、そうする方法について私にアドバイスをいただけますか?これらは次の方法です。

    public User GetUser();

    public User Login(string userName, string password, bool isPersistent, string customData);

    public User Logout();

    public void UpdateUser(User user);

これらのいずれかを実装する方法がわかりません(ログインを除く)-Logout()が機能するために、サービスが現在ログインしているユーザーをどのように知ることができるでしょうか?

これを行う方法を何時間も探してWebを精査してきましたが、「RIAにリンクされた」Silverlightプロジェクトでユーザーを認証するために使用できる単純なDomainServiceを作成する方法を説明するものが見つかりません。

誰かがこれに光を当てることができれば、私は心から感謝します。

ありがとう、
チャールズ


[編集] MSDNコードギャラリーでRIAサービスページ
を見つけました。認証サンプルと呼ばれるセクションがあり、いくつかの優れたコードサンプルにリンクしています。RIAサービス内で認証がどのように機能するかについて詳しく知りたい場合は、チェックしてください。

4

3 に答える 3

20

「Silverlightビジネスアプリケーション」を作成すると、テンプレートがどのように認証を実装するかがわかります。(または、ここに移動して、テンプレートサンプルプロジェクトをダウンロードします。)

簡単にするために、私が使用したプロセスは次のとおりです。

まず、LinqToEntitiesDomainServiceから派生するドメインサービス(FooService)を作成します。ここで、FooContextはエンティティモデルです。その中に、カスタムDBテーブルにアクセスしてユーザープロファイルを返すためのすべてのCRUD操作を追加します。

次に、UserBaseから派生して、サーバー側に具体的なUserクラスを作成します。

using System.Web.Ria;
using System.Web.Ria.ApplicationServices;

public class User : UserBase
{}

最後に、AuthenticationBaseからクラスを派生させ、次の4つのメソッドを実装します。

[EnableClientAccess]
public class AuthenticationService : AuthenticationBase<User>
{
    private FooService _service = new FooService();

    protected override bool ValidateUser(string username, string password)
    {
        // Code here that tests only if the password is valid for the given
        // username using your custom DB calls via the domain service you
        // implemented above
    }

    protected override User GetAuthenticatedUser(IPrincipal pricipal)
    {
        // principal.Identity.Name will be the username for the user
        // you're trying to authenticate. Here's one way to implement
        // this:
        User user = null;
        if (this._service.DoesUserExist(principal.Identity.Name)) // DoesUserExist() is a call
                                                                  // added in my domain service
        {
            // UserProfile is an entity in my DB
            UserProfile profile = this._service.GetUserProfile(principal.Identity.Name);
            user.Name = profile.UserName;
            user.AuthenticationType = principal.Identity.AuthenticationType;
        }
        return user;
    }

    public override void Initialize(DomainServiceContext context)
    {
        this._service.Initialize(context);
        base.Initialize(context);
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
            this._service.Dispose();
        base.Dispose(disposing);
    }
}
于 2009-08-05T14:31:04.850 に答える
1

これはMSからの完全な公式の例です:

http://code.msdn.microsoft.com/Custom-Authentication-96ca3d20

于 2012-02-19T15:07:24.750 に答える
0

IAuthorizationインターフェイスを実装するのはどうですか?

于 2010-05-28T07:40:28.080 に答える