オレオレsecurityバンドル作っちゃいました

24
オレオレSecurityBundle 作っちゃいました クロコス株式会社 小川 雄大

Upload: katsuhiro-ogawa

Post on 15-Jan-2015

4.853 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: オレオレSecurityバンドル作っちゃいました

オレオレSecurityBundle作っちゃいました

クロコス株式会社 小川 雄大

Page 2: オレオレSecurityバンドル作っちゃいました

現状のSecurityBundle

設定しにくい

拡張しにくい

理解しにくい

社内でクレーム続出

Page 3: オレオレSecurityバンドル作っちゃいました

そんなわけで....

作ってみました

CrocosSecurityBundlehttps://github.com/crocos/CrocosSecurityBundle

Page 4: オレオレSecurityバンドル作っちゃいました

CrocosSecurityBundle

アノテーションのみで設定

認証状態の保持と、アクション呼び出しの制御のみを行う

Page 5: オレオレSecurityバンドル作っちゃいました

class MyController{ /** * @Secure */ public function doAction() { }}

Page 6: オレオレSecurityバンドル作っちゃいました

/** * @Secure */class MyController{ public function doAction() { }}

Page 7: オレオレSecurityバンドル作っちゃいました

Secure アノテーションを付与したアクションがログイン必須に

クラスにつけるとすべてのアクションでログインが必須に

(*)アノテーションはインポートが必要

Page 8: オレオレSecurityバンドル作っちゃいました

/** * @Secure */class MyController{ /** * @Secure(disabled=true) */ public function doAction() { }}

Page 9: オレオレSecurityバンドル作っちゃいました

Secure アノテーションに disabled オプションをつけると無効に

Page 10: オレオレSecurityバンドル作っちゃいました

/** * @Secure */class AppController {}

class FooController extends AppController {}

class BarController extends AppController {}

Page 11: オレオレSecurityバンドル作っちゃいました

親クラスを共通化して、親クラスにSecure アノテーションを付与すれば全体でログインを必須に

Page 12: オレオレSecurityバンドル作っちゃいました

/** * @Secure * @SecureConfig( forward=“Acme:My:login”) */class MyController{ public function loginAction() { }}

Page 13: オレオレSecurityバンドル作っちゃいました

ログインが必須なアクションにアクセスしたら、SecureConfigアノテーションのforward属性に指定したコントローラが呼び出される

forwardは必須

Page 14: オレオレSecurityバンドル作っちゃいました

/** * @Secure * @SecureConfig(domain=“default”) */class UserController {}

/** * @Secure * @SecureConfig(domain=“admin”) */class AdminController {}

Page 15: オレオレSecurityバンドル作っちゃいました

SecureConfigアノテーションのdomain

属性ごとに認証状態を管理できる

defaultドメインで認証されていても、adminドメインでは認証されていない

Page 16: オレオレSecurityバンドル作っちゃいました

/** * @Secure * @SecureConfig(auth=“facebook”) */class FacebookController {}

Page 17: オレオレSecurityバンドル作っちゃいました

SecureConfigアノテーションにauth属性を指定すると認証状態の管理方法を切り替えることができる

デフォルトはsession

facebookにするとFacebookのPHP SDK

に認証状態の管理を委譲

Page 18: オレオレSecurityバンドル作っちゃいました

SecurityContext

認証状態の管理はSecurityContextオブジェクトが行っている

crocos_security.context(DIコンテナ)

Page 19: オレオレSecurityバンドル作っちゃいました

$context = $this->get( ‘crocos_security.context’);

$user = $userRepo->find(1);

$context->login($user);

$context->logout();

Page 20: オレオレSecurityバンドル作っちゃいました

login()メソッドにユーザを識別できる値を渡してログインする

ユーザオブジェクトでも、IDでも

logout()メソッドでログアウト

Page 21: オレオレSecurityバンドル作っちゃいました

if ($context->isAuthenticated()) { $user = $context->getUser();}

Page 22: オレオレSecurityバンドル作っちゃいました

isAuthenticated()メソッドで判定

getUser()メソッドでユーザの取得

Page 23: オレオレSecurityバンドル作っちゃいました

今後

基本的に欲しい機能は実装してあるので、あまり大きなアップデートはしないと思います。

Page 24: オレオレSecurityバンドル作っちゃいました

GitHubで公開中

https://github.com/crocos/CrocosSecurityBundleREADMEに日本語で使い方書いてます