Central Authentication Service

□未翻訳

□翻訳中

□翻訳完了(中垣健志)

■レビュー(細田謙二)

Central Authentication Service

Central Authentication Service

CAS

Authentication

web2pyは、認証や承認機能のためのサポートをアプライアンスから提供しています。ここでは、Central Authentication Service (CAS)のためのcasアプライアンスについて解説します。執筆時点では、CASは独特で、Authと一緒に動作しません。これは将来修正する予定です。

web2py provides support for authentication and authorization via appliances. Here we discuss the cas appliance for Central Authentication Service (CAS). Notice that at the time of writing CAS is distinct and does not work with Auth. This will change in the future.

CASは分散認証を行うためのオープンなプロトコルで、次のように動作します:訪問者がWebサイトに着いたとき、アプリケーションはユーザーが既に認証されているかどうかをセッションを使ってチェックします(例えば、session.token オブジェクトを介して)。もし認証されていない場合、コントローラはCASアプライアンスからユーザーをリダイレクトします。リダイレクト先は、ユーザーが、ログイン、ユーザー登録、認証情報(名前、メールアドレス、パスワード)の管理ができるところです。

ユーザー登録を行った場合、そのユーザーはメールを受け取り、ユーザーがそのメールに対応するまで登録は保留されます。いったん登録に成功し、ログインすると、CASアプライアンスはキーとともにユーザーをアプリケーションへリダイレクトします。アプリケーションではこのキーを使ってユーザーの認証情報を取得します。これは、内部ではCASサーバへのHTTPリクエストを介して行われます。

CAS is an open protocol for distributed authentication and it works in the following way: When a visitor arrives at our web site, our application check in the session if the user is already authenticated (for example via a session.token object). If the user is not authenticated, the controller redirects the visitor from the CAS appliance, where the user can log in, register, and manage his credentials (name, email and password). If the user registers, he receives an email, and registration is not complete until he responds to the email. Once the user has successfully registered and logged in, the CAS appliance redirects the user to our application together with a key. Our application uses the key to get the credentials of the user via an HTTP request in the background to the CAS server.

この仕組みを使うと、複数のアプリケーションが一つのCASサーバを通じてシングルサインオンを使用することができます。認証を提供するサーバは、サービスプロバイダと呼ばれます。訪問者を認証しようとするアプリケーションは、サービスコンシューマと呼ばれます。

Using this mechanism, multiple applications can use the a single sign-on via a single CAS server. The server providing authentication is called a service provider. Applications seeking to authenticate visitors are called service consumers.

CASはOpenIDと似ていますが、大きな違いが一つあります。OpenIDの場合、訪問者はサービスプロバイダを選択することができます。CASの場合は、アプリケーションがサービスプロバイダを選択します。そのため、CASはより安全です。

CAS is similar to OpenID, with one main difference. In the the case of OpenID, the visitor chooses the service provider. In the case of CAS, our application makes this choice, making CAS more secure.

コンシューマのみ、プロバイダのみ、または、両方を(単一または独立した複数のアプリケーションにおいて)実行することができます。

You can run only the consumer, only the provider, or both (in a single or separate applications).

CASをコンシューマとして実行させる場合、以下のファイルをダウンロードする必要があります。

To run CAS as consumer you must download the file:

https://www.web2py.com/cas/static/cas.py

そして、"cas.py"という名のモデルファイルとして保存します。さらに、認証を必要とするコントローラ(例えば"default.py")の編集を行い、先頭に以下のコードを追加します。

and store it as a model file called "cas.py". Then you must edit the controllers that need authentication (for example "default.py") and, at the top, add the following code:

1.

2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

CAS.login_url='https://www.web2py.com/cas/cas/login'

CAS.check_url='https://www.web2py.com/cas/cas/check'

CAS.logout_url='https://www.web2py.com/cas/cas/logout'

CAS.my_url='http://127.0.0.1:8000/myapp/default/login'

if not session.token and not request.function=='login':

redirect(URL('login'))

def login():

session.token=CAS.login(request)

id,email,name=session.token

return dict()

def logout():

session.token=None

CAS.logout()

上記のCASオブジェクトの属性を編集する必要があります。デフォルトでは、"https://mdp.cti.depaul.edu"で動作しているCASプロバイダを指しています。これは我々が主にテスト用として公開しているサービスです。 CAS.my_url はこのコードで示すように、アプリケーションで定義されているログインアクションへの完全なURLにしてください。CASプロバイダが、このアクションへリダイレクトする必要があるからです。

You must edit the attributes of the CAS object above. By default, they point to the CAS provider that runs on "https://mdp.cti.depaul.edu". We provide this service mainly for testing purposes. The CAS.my_url has to be the full URL to the login action defined in your application and shown in the code. The CAS provider needs to redirect your browser to this action.

我々のCASプロバイダは(id, email, name)のタプルを含むトークンを返します。idには訪問者の一意なレコードidを(プロバイダのデータベースで割り当てられているもの)、emailには、訪問者のメールアドレスを(訪問者がプロバイダに宣言し、プロバイダによって検証されたもの)、nameには訪問者の名前(訪問者によって選択されたもので、実際の名前とは限らない)が定義されます。

Our CAS provider returns a token containing a tuple (id, email, name), where id is the unique record id of the visitor (as assigned by the provider's database), email is the email address of the visitor (as declared by the visitor to the provider and verified by the provider), and name is the name of the visitor (it is chosen by the visitor and there is no guarantee this is a real name).

次のようなローカルURLに訪れた場合は、

If you visit the local url:

1.

/myapp/default/login

CASのログインページにリダイレクトされます。

you get redirected to the CAS login page:

https://mdp.cti.depaul.edu/cas/cas/login

このような感じです。

which looks like this:

サードパーティ製のCASサービスを使うこともできますが、上記の10行目を修正する必要があります。異なるCASプロバイダは異なる値を含むトークンを返します。詳細は、アクセスしたいそれぞれのCASサービスのドキュメントを確認してください。ほとんどのサービスは(id,username)を返します。

You may also use third-party CAS services, but you may need to edit line 10 above, since different CAS providers may return tokens containing different values. Check the documentation of the CAS service you need to access for details. Most services only return (id, username).

ログインが成功した後は、ローカルのログインアクションにリダイレクトされます。ローカルのログインアクションのビューは、CASのログインが成功した後にだけ実行されます。

After a successful login, you are redirected to the local login action. The view of the local login action is executed only after a successful CAS login.

CASプロバイダのアプライアンスは、ここ33からダウンロードできます。そして、あなた自身で実行できます。そうする場合、アプライアンスにある"email.py"モデルの最初の行を、利用するSMTPサーバを指すように編集する必要があります。

You can download the CAS provider appliance from ref.33 and run it yourself. If you choose to do so, you must also edit the first lines of the "email.py" model in the appliance, so that it points to your SMPT server.

ファイル名がかぶらない限り、CASアプライアンスのプロバイダのファイルを、あなたのアプリケーション(models以下にあるモデル)にマージすることができます。

You can also merge the files of the CAS provider appliance provider with those of your application (models under models, etc.) as long there is no filename conflict.