Laravel5 は、Jasig cas 統合認証システムを統合しています
CAS: CAS (Central Authentication Service) は、Web アプリケーション用の優れたシングル サインオン フレームワークです。これは、laravel5 cas で構築に成功したフレームワークの紹介です。 。事前準備作業:laravel5プロジェクトが実行可能であり、casサーバー側が既に存在します。
環境: Linux (ubuntu)
1. phpcas ソース コードをダウンロードします。
laravel5 プロジェクトのアプリディレクトリにライブラリディレクトリを作成し、phpcas ライブラリをダウンロードします。git clone https: / /github.com/Jasig/phpCAS.git、クローンされたのは phpcas ファイル ディレクトリです。
次に、プロバイダーを作成します。
アプリの下にディレクトリ cas を作成し、次の内容の CasAuthProvider.php を作成します。 :
<span style="color: #008080;"> 1</span> <span style="color: #000000;">php</span><span style="color: #008080;"> 2</span> <span style="color: #008080;"> 3</span> <span style="color: #000000;">namespace cas;</span><span style="color: #008080;"> 4</span> <span style="color: #008080;"> 5</span> <span style="color: #0000ff;">use</span><span style="color: #000000;"> Illuminate\Contracts\Auth\UserProvider;</span><span style="color: #008080;"> 6</span> <span style="color: #0000ff;">use</span><span style="color: #000000;"> Illuminate\Contracts\Hashing\Hasher;</span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">use</span><span style="color: #000000;"> Illuminate\Contracts\Auth\Authenticatable;</span><span style="color: #008080;"> 8</span> <span style="color: #0000ff;">use</span><span style="color: #000000;"> Illuminate\Auth\GenericUser;</span><span style="color: #008080;"> 9</span> <span style="color: #008080;">10</span> <span style="color: #0000ff;">class</span> CasAuthProvider <span style="color: #0000ff;">implements</span><span style="color: #000000;"> UserProvider {</span><span style="color: #008080;">11</span> <span style="color: #008080;">12</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">13</span> <span style="color: #008000;"> * Retrieve a user by their unique identifier.</span><span style="color: #008080;">14</span> <span style="color: #008000;"> *</span><span style="color: #008080;">15</span> <span style="color: #008000;"> * @param mixed $id</span><span style="color: #008080;">16</span> <span style="color: #008000;"> * @return \Illuminate\Auth\UserInterface|null</span><span style="color: #008080;">17</span> <span style="color: #008000;">*/</span><span style="color: #008080;">18</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> retrieveById(<span style="color: #800080;">$id</span><span style="color: #000000;">) {</span><span style="color: #008080;">19</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">casUser();</span><span style="color: #008080;">20</span> <span style="color: #000000;"> }</span><span style="color: #008080;">21</span> <span style="color: #008080;">22</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">23</span> <span style="color: #008000;"> * Retrieve a user by the given credentials.</span><span style="color: #008080;">24</span> <span style="color: #008000;"> *</span><span style="color: #008080;">25</span> <span style="color: #008000;"> * @param array $credentials</span><span style="color: #008080;">26</span> <span style="color: #008000;"> * @return \Illuminate\Auth\UserInterface|null</span><span style="color: #008080;">27</span> <span style="color: #008000;">*/</span><span style="color: #008080;">28</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> retrieveByCredentials(<span style="color: #0000ff;">array</span> <span style="color: #800080;">$credentials</span><span style="color: #000000;">) {</span><span style="color: #008080;">29</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">casUser();</span><span style="color: #008080;">30</span> <span style="color: #000000;"> }</span><span style="color: #008080;">31</span> <span style="color: #008080;">32</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">33</span> <span style="color: #008000;"> * Validate a user against the given credentials.</span><span style="color: #008080;">34</span> <span style="color: #008000;"> *</span><span style="color: #008080;">35</span> <span style="color: #008000;"> * @param \Illuminate\Auth\UserInterface $user</span><span style="color: #008080;">36</span> <span style="color: #008000;"> * @param array $credentials</span><span style="color: #008080;">37</span> <span style="color: #008000;"> * @return bool</span><span style="color: #008080;">38</span> <span style="color: #008000;">*/</span><span style="color: #008080;">39</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> validateCredentials(Authenticatable <span style="color: #800080;">$user</span>, <span style="color: #0000ff;">array</span> <span style="color: #800080;">$credentials</span><span style="color: #000000;">) {</span><span style="color: #008080;">40</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;</span><span style="color: #008080;">41</span> <span style="color: #000000;"> }</span><span style="color: #008080;">42</span> <span style="color: #008080;">43</span> <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> casUser() {</span><span style="color: #008080;">44</span> <span style="color: #800080;">$cas_host</span> = \Config::get('app.cas_host'<span style="color: #000000;">);</span><span style="color: #008080;">45</span> <span style="color: #008000;">//</span><span style="color: #008000;">dump($cas_host);</span><span style="color: #008080;">46</span> <span style="color: #800080;">$cas_context</span> = \Config::get('app.cas_context'<span style="color: #000000;">);</span><span style="color: #008080;">47</span> <span style="color: #800080;">$cas_port</span> = \Config::get('app.cas_port'<span style="color: #000000;">);</span><span style="color: #008080;">48</span> \phpCAS::<span style="color: #000000;">setDebug();</span><span style="color: #008080;">49</span> \phpCAS::client(CAS_VERSION_2_0, <span style="color: #800080;">$cas_host</span>, <span style="color: #800080;">$cas_port</span>, <span style="color: #800080;">$cas_context</span><span style="color: #000000;">);</span><span style="color: #008080;">50</span> \phpCAS::<span style="color: #000000;">setNoCasServerValidation();</span><span style="color: #008080;">51</span> <span style="color: #008080;">52</span> <span style="color: #0000ff;">if</span> (\phpCAS::<span style="color: #000000;">isAuthenticated()) {</span><span style="color: #008080;">53</span> <span style="color: #800080;">$attributes</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(</span><span style="color: #008080;">54</span> 'id' => \phpCAS::getUser(),<span style="color: #008080;">55</span> 'name' => \phpCAS::<span style="color: #000000;">getUser()</span><span style="color: #008080;">56</span> <span style="color: #000000;"> );</span><span style="color: #008080;">57</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> GenericUser(<span style="color: #800080;">$attributes</span><span style="color: #000000;">);</span><span style="color: #008080;">58</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;">59</span> <span style="color: #008000;">//</span><span style="color: #008000;">\phpCAS::setServerURL(\Config::get('app.url'));</span><span style="color: #008080;">60</span> \phpCAS::<span style="color: #000000;">forceAuthentication();</span><span style="color: #008080;">61</span> <span style="color: #000000;"> }</span><span style="color: #008080;">62</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">;</span><span style="color: #008080;">63</span> <span style="color: #000000;"> }</span><span style="color: #008080;">64</span> <span style="color: #008080;">65</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">66</span> <span style="color: #008000;"> * Needed by Laravel 4.1.26 and above</span><span style="color: #008080;">67</span> <span style="color: #008000;">*/</span><span style="color: #008080;">68</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> retrieveByToken(<span style="color: #800080;">$identifier</span>, <span style="color: #800080;">$token</span><span style="color: #000000;">) {</span><span style="color: #008080;">69</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> \<span style="color: #0000ff;">Exception</span>('not implemented'<span style="color: #000000;">);</span><span style="color: #008080;">70</span> <span style="color: #000000;"> }</span><span style="color: #008080;">71</span> <span style="color: #008080;">72</span> <span style="color: #008000;">/*</span><span style="color: #008000;">*</span><span style="color: #008080;">73</span> <span style="color: #008000;"> * Needed by Laravel 4.1.26 and above</span><span style="color: #008080;">74</span> <span style="color: #008000;">*/</span><span style="color: #008080;">75</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> updateRememberToken(Authenticatable <span style="color: #800080;">$user</span>, <span style="color: #800080;">$token</span><span style="color: #000000;">) {</span><span style="color: #008080;">76</span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> \<span style="color: #0000ff;">Exception</span>('not implemented'<span style="color: #000000;">);</span><span style="color: #008080;">77</span> <span style="color: #000000;"> }</span><span style="color: #008080;">78</span> <span style="color: #008080;">79</span> <span style="color: #000000;">}</span><span style="color: #008080;">80</span> <span style="color: #008080;">81</span> ?>
3. config
を変更し、config/app.php に次の 3 つの構成項目を追加します。 🎜>
'cas_host'=>'****', //認証サーバー 'cas_context'=>'',//まだ何なのかわかりません
'cas_port'=> ;000 ,//認証サービス ポート
'url'=>'http://localhost/',
4、認証ライブラリをロードします
app/ 内 Providers/AppServiceProvider.php で、AppServiceProvider クラスの register 関数に認証メソッドを追加します。 Auth::extend('cas', function($app) { return new CasAuthProvider;
} );
"classmap": [
" " app/library",
"app/library /phpCAS",
"app/cas"
]
}
プロジェクトのルート ディレクトリでコンポーザー ダンプを実行します: -autoload
5を実装します。app/http/controllers/ に CasAuthController.php を作成します。ログインおよびログアウト メソッドを追加します。
<span style="color: #008080;"> 1</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> login() {</span><span style="color: #008080;"> 2</span> <span style="color: #008080;"> 3</span> <span style="color: #800080;">$message_error</span> = ""<span style="color: #000000;">;</span><span style="color: #008080;"> 4</span> <span style="color: #0000ff;">if</span> (Auth::<span style="color: #000000;">check()) {</span><span style="color: #008080;"> 5</span> <span style="color: #008080;"> 6</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> {</span><span style="color: #008080;"> 7</span> <span style="color: #0000ff;">if</span> (Auth::attempt(<span style="color: #0000ff;">array</span><span style="color: #000000;">())) {</span><span style="color: #008080;"> 8</span> <span style="color: #008000;">//</span><span style="color: #008000;"> Redirect to link after login</span><span style="color: #008080;"> 9</span> <span style="color: #000000;"> }</span><span style="color: #008080;">10</span> <span style="color: #008000;">//</span><span style="color: #008000;"> Redirect to un-logged in page</span><span style="color: #008080;">11</span> <span style="color: #000000;"> }</span><span style="color: #008080;">12</span> dump(\phpCAS::<span style="color: #000000;">getUser());</span><span style="color: #008080;">13</span> dump(Auth::<span style="color: #000000;">user());</span><span style="color: #008080;">14</span> <span style="color: #000000;"> }</span><span style="color: #008080;">15</span> <span style="color: #008080;">16</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> logout() {</span><span style="color: #008080;">17</span> <span style="color: #008080;">18</span> <span style="color: #800080;">$cas_host</span> = \Config::get('app.cas_host'<span style="color: #000000;">);</span><span style="color: #008080;">19</span> <span style="color: #008000;">//</span><span style="color: #008000;">dump($cas_host);</span><span style="color: #008080;">20</span> <span style="color: #800080;">$cas_context</span> = \Config::get('app.cas_context'<span style="color: #000000;">);</span><span style="color: #008080;">21</span> <span style="color: #800080;">$cas_port</span> = \Config::get('app.cas_port'<span style="color: #000000;">);</span><span style="color: #008080;">22</span> \phpCAS::<span style="color: #000000;">setDebug();</span><span style="color: #008080;">23</span> \phpCAS::client(CAS_VERSION_2_0, <span style="color: #800080;">$cas_host</span>, <span style="color: #800080;">$cas_port</span>, <span style="color: #800080;">$cas_context</span><span style="color: #000000;">);</span><span style="color: #008080;">24</span> \phpCAS::<span style="color: #000000;">setNoCasServerValidation();</span><span style="color: #008080;">25</span> \phpCAS::logoutWithRedirectService(\Config::get('app.url'<span style="color: #000000;">));</span><span style="color: #008080;">26</span> }ルーティング ルールを追加しても問題ありません。ここでプロジェクトのデフォルトのログインおよびログアウトメソッドを指定します。ログインすると、サーバーのログインページが表示されます。
この変更後、ログインせずに閲覧できるように設定したページがポップアップ表示されるようになりました。理由はわかりません。案内してもらえます、ありがとう!
参考: https://sonnguyen.ws/how-to-integrate-phpcas-in-laravel/

PHPSESSIONの障害の理由には、構成エラー、Cookieの問題、セッションの有効期限が含まれます。 1。構成エラー:正しいセッションをチェックして設定します。save_path。 2.Cookieの問題:Cookieが正しく設定されていることを確認してください。 3.セッションの有効期限:セッションを調整してください。GC_MAXLIFETIME値はセッション時間を延長します。

PHPでセッションの問題をデバッグする方法は次のとおりです。1。セッションが正しく開始されるかどうかを確認します。 2.セッションIDの配信を確認します。 3.セッションデータのストレージと読み取りを確認します。 4.サーバーの構成を確認します。セッションIDとデータを出力し、セッションファイルのコンテンツを表示するなど、セッション関連の問題を効果的に診断して解決できます。

session_start()への複数の呼び出しにより、警告メッセージと可能なデータ上書きが行われます。 1)PHPは警告を発し、セッションが開始されたことを促します。 2)セッションデータの予期しない上書きを引き起こす可能性があります。 3)session_status()を使用してセッションステータスを確認して、繰り返しの呼び出しを避けます。

PHPでのセッションライフサイクルの構成は、session.gc_maxlifetimeとsession.cookie_lifetimeを設定することで達成できます。 1)session.gc_maxlifetimeサーバー側のセッションデータのサバイバル時間を制御します。 0に設定すると、ブラウザが閉じているとCookieが期限切れになります。

データベースストレージセッションを使用することの主な利点には、持続性、スケーラビリティ、セキュリティが含まれます。 1。永続性:サーバーが再起動しても、セッションデータは変更されないままになります。 2。スケーラビリティ:分散システムに適用され、セッションデータが複数のサーバー間で同期されるようにします。 3。セキュリティ:データベースは、機密情報を保護するための暗号化されたストレージを提供します。

PHPでのカスタムセッション処理の実装は、SessionHandlerInterfaceインターフェイスを実装することで実行できます。具体的な手順には、次のものが含まれます。1)CussentsessionHandlerなどのSessionHandlerInterfaceを実装するクラスの作成。 2)セッションデータのライフサイクルとストレージ方法を定義するためのインターフェイス(オープン、クローズ、読み取り、書き込み、破壊、GCなど)の書き換え方法。 3)PHPスクリプトでカスタムセッションプロセッサを登録し、セッションを開始します。これにより、データをMySQLやRedisなどのメディアに保存して、パフォーマンス、セキュリティ、スケーラビリティを改善できます。

SessionIDは、ユーザーセッションのステータスを追跡するためにWebアプリケーションで使用されるメカニズムです。 1.ユーザーとサーバー間の複数のインタラクション中にユーザーのID情報を維持するために使用されるランダムに生成された文字列です。 2。サーバーは、ユーザーの複数のリクエストでこれらの要求を識別および関連付けるのに役立つCookieまたはURLパラメーターを介してクライアントに生成および送信します。 3.生成は通常、ランダムアルゴリズムを使用して、一意性と予測不可能性を確保します。 4.実際の開発では、Redisなどのメモリ内データベースを使用してセッションデータを保存してパフォーマンスとセキュリティを改善できます。

APIなどのステートレス環境でのセッションの管理は、JWTまたはCookieを使用して達成できます。 1。JWTは、無国籍とスケーラビリティに適していますが、ビッグデータに関してはサイズが大きいです。 2.cookiesはより伝統的で実装が簡単ですが、セキュリティを確保するために慎重に構成する必要があります。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

DVWA
Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

ホットトピック









