


Integrate Jasig cas unified authentication system in Laravel5, laravel5jasig_PHP tutorial
Laravel5 integrates Jasig cas unified authentication system, laravel5jasig
CAS: CAS (Central Authentication Service) is a good single sign-on framework for web applications. Here I will introduce the cas that I just successfully built on laravel5. Preparation work in advance: The laravel5 project can be run, and the cas server side already exists.
Environment: Linux (ubuntu)
1. Download the phpcas source code.
Create the library directory in the laravel5 project app directory, download the phpcas library, git clone https://github.com/Jasig /phpCAS.git, cloned is a phpcas file directory.
2. Create provider
Create the directory cas under the app and create CasAuthProvider.php with the following content:
<span> 1</span> <?<span>php </span><span> 2</span> <span> 3</span> <span>namespace cas; </span><span> 4</span> <span> 5</span> <span>use</span><span> Illuminate\Contracts\Auth\UserProvider; </span><span> 6</span> <span>use</span><span> Illuminate\Contracts\Hashing\Hasher; </span><span> 7</span> <span>use</span><span> Illuminate\Contracts\Auth\Authenticatable; </span><span> 8</span> <span>use</span><span> Illuminate\Auth\GenericUser; </span><span> 9</span> <span>10</span> <span>class</span> CasAuthProvider <span>implements</span><span> UserProvider { </span><span>11</span> <span>12</span> <span>/*</span><span>* </span><span>13</span> <span> * Retrieve a user by their unique identifier. </span><span>14</span> <span> * </span><span>15</span> <span> * @param mixed $id </span><span>16</span> <span> * @return \Illuminate\Auth\UserInterface|null </span><span>17</span> <span>*/</span> <span>18</span> <span>public</span> <span>function</span> retrieveById(<span>$id</span><span>) { </span><span>19</span> <span>return</span> <span>$this</span>-><span>casUser(); </span><span>20</span> <span> } </span><span>21</span> <span>22</span> <span>/*</span><span>* </span><span>23</span> <span> * Retrieve a user by the given credentials. </span><span>24</span> <span> * </span><span>25</span> <span> * @param array $credentials </span><span>26</span> <span> * @return \Illuminate\Auth\UserInterface|null </span><span>27</span> <span>*/</span> <span>28</span> <span>public</span> <span>function</span> retrieveByCredentials(<span>array</span> <span>$credentials</span><span>) { </span><span>29</span> <span>return</span> <span>$this</span>-><span>casUser(); </span><span>30</span> <span> } </span><span>31</span> <span>32</span> <span>/*</span><span>* </span><span>33</span> <span> * Validate a user against the given credentials. </span><span>34</span> <span> * </span><span>35</span> <span> * @param \Illuminate\Auth\UserInterface $user </span><span>36</span> <span> * @param array $credentials </span><span>37</span> <span> * @return bool </span><span>38</span> <span>*/</span> <span>39</span> <span>public</span> <span>function</span> validateCredentials(Authenticatable <span>$user</span>, <span>array</span> <span>$credentials</span><span>) { </span><span>40</span> <span>return</span> <span>true</span><span>; </span><span>41</span> <span> } </span><span>42</span> <span>43</span> <span>protected</span> <span>function</span><span> casUser() { </span><span>44</span> <span>$cas_host</span> = \Config::get('app.cas_host'<span>); </span><span>45</span> <span>//</span><span>dump($cas_host);</span> <span>46</span> <span>$cas_context</span> = \Config::get('app.cas_context'<span>); </span><span>47</span> <span>$cas_port</span> = \Config::get('app.cas_port'<span>); </span><span>48</span> \phpCAS::<span>setDebug(); </span><span>49</span> \phpCAS::client(CAS_VERSION_2_0, <span>$cas_host</span>, <span>$cas_port</span>, <span>$cas_context</span><span>); </span><span>50</span> \phpCAS::<span>setNoCasServerValidation(); </span><span>51</span> <span>52</span> <span>if</span> (\phpCAS::<span>isAuthenticated()) { </span><span>53</span> <span>$attributes</span> = <span>array</span><span>( </span><span>54</span> 'id' => \phpCAS::getUser(), <span>55</span> 'name' => \phpCAS::<span>getUser() </span><span>56</span> <span> ); </span><span>57</span> <span>return</span> <span>new</span> GenericUser(<span>$attributes</span><span>); </span><span>58</span> } <span>else</span><span> { </span><span>59</span> <span>//</span><span>\phpCAS::setServerURL(\Config::get('app.url'));</span> <span>60</span> \phpCAS::<span>forceAuthentication(); </span><span>61</span> <span> } </span><span>62</span> <span>return</span> <span>null</span><span>; </span><span>63</span> <span> } </span><span>64</span> <span>65</span> <span>/*</span><span>* </span><span>66</span> <span> * Needed by Laravel 4.1.26 and above </span><span>67</span> <span>*/</span> <span>68</span> <span>public</span> <span>function</span> retrieveByToken(<span>$identifier</span>, <span>$token</span><span>) { </span><span>69</span> <span>return</span> <span>new</span> \<span>Exception</span>('not implemented'<span>); </span><span>70</span> <span> } </span><span>71</span> <span>72</span> <span>/*</span><span>* </span><span>73</span> <span> * Needed by Laravel 4.1.26 and above </span><span>74</span> <span>*/</span> <span>75</span> <span>public</span> <span>function</span> updateRememberToken(Authenticatable <span>$user</span>, <span>$token</span><span>) { </span><span>76</span> <span>return</span> <span>new</span> \<span>Exception</span>('not implemented'<span>); </span><span>77</span> <span> } </span><span>78</span> <span>79</span> <span>} </span><span>80</span> <span>81</span> ?>
3. Modify config
Add the following three configuration items in config/app.php:
'cas_host'=>'****', //Authentication server
'cas_context'=>'',//I haven't figured out what it is yet
'cas_port'=>000 ,//Authentication service port
'url'=>'http://localhost/',
4. Load the authentication library
In app/providers/AppServiceProvider.php, add the authentication method in the register function of class AppServiceProvider:
Auth::extend('cas', function($app) {
return new CasAuthProvider;
});
Modify app/config/auth.php authentication driver: 'driver' => 'cas',
Configure the add-in in composer.json and add the following path to the classmap in autoload:
"autoload": {
"classmap": [
"app/library" "app/library",
"app/library/ phpCAS",
"app/cas"
]
Execute in the project root directory: composer dump-autoload
Five, realize
Create CasAuthController.php under app/http/controllers/ and add login and logout methods:
<span> 1</span> <span>public</span> <span>function</span><span> login() { </span><span> 2</span> <span> 3</span> <span>$message_error</span> = ""<span>; </span><span> 4</span> <span>if</span> (Auth::<span>check()) { </span><span> 5</span> <span> 6</span> } <span>else</span><span> { </span><span> 7</span> <span>if</span> (Auth::attempt(<span>array</span><span>())) { </span><span> 8</span> <span>//</span><span> Redirect to link after login</span> <span> 9</span> <span> } </span><span>10</span> <span>//</span><span> Redirect to un-logged in page</span> <span>11</span> <span> } </span><span>12</span> dump(\phpCAS::<span>getUser()); </span><span>13</span> dump(Auth::<span>user()); </span><span>14</span> <span> } </span><span>15</span> <span>16</span> <span>public</span> <span>function</span><span> logout() { </span><span>17</span> <span>18</span> <span>$cas_host</span> = \Config::get('app.cas_host'<span>); </span><span>19</span> <span>//</span><span>dump($cas_host);</span> <span>20</span> <span>$cas_context</span> = \Config::get('app.cas_context'<span>); </span><span>21</span> <span>$cas_port</span> = \Config::get('app.cas_port'<span>); </span><span>22</span> \phpCAS::<span>setDebug(); </span><span>23</span> \phpCAS::client(CAS_VERSION_2_0, <span>$cas_host</span>, <span>$cas_port</span>, <span>$cas_context</span><span>); </span><span>24</span> \phpCAS::<span>setNoCasServerValidation(); </span><span>25</span> \phpCAS::logoutWithRedirectService(\Config::get('app.url'<span>)); </span><span>26</span> }
I have a problem. After making this change, the page I originally set up to be able to browse without logging in will now jump out of the login page when I enter it. I don’t know why. I hope an expert can guide me. Thank you!
Reference: https://sonnguyen.ws/how-to-integrate-phpcas-in-laravel/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

The best version of the Apple 16 system is iOS16.1.4. The best version of the iOS16 system may vary from person to person. The additions and improvements in daily use experience have also been praised by many users. Which version of the Apple 16 system is the best? Answer: iOS16.1.4 The best version of the iOS 16 system may vary from person to person. According to public information, iOS16, launched in 2022, is considered a very stable and performant version, and users are quite satisfied with its overall experience. In addition, the addition of new features and improvements in daily use experience in iOS16 have also been well received by many users. Especially in terms of updated battery life, signal performance and heating control, user feedback has been relatively positive. However, considering iPhone14

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

Linux and Windows are two common operating systems, representing the open source Linux system and the commercial Windows system respectively. In both operating systems, there is a command line interface for users to interact with the operating system. In Linux systems, users use the Shell command line, while in Windows systems, users use the cmd command line. The Shell command line in Linux system is a very powerful tool that can complete almost all system management tasks.

Detailed explanation of the method of modifying the system date in the Oracle database. In the Oracle database, the method of modifying the system date mainly involves modifying the NLS_DATE_FORMAT parameter and using the SYSDATE function. This article will introduce these two methods and their specific code examples in detail to help readers better understand and master the operation of modifying the system date in the Oracle database. 1. Modify NLS_DATE_FORMAT parameter method NLS_DATE_FORMAT is Oracle data

In which folder are the system fonts located? In modern computer systems, fonts play a vital role, affecting our reading experience and the beauty of text expression. For some users who are keen on personalization and customization, it is particularly important to understand the storage location of system fonts. So, in which folder are system fonts stored? This article will reveal them one by one for everyone. In the Windows operating system, system fonts are stored in a folder called "Fonts". This folder is located in the Win C drive by default.

Recently, Huawei announced that it will launch a new smart wearable product equipped with Xuanji sensing system in September, which is expected to be Huawei's latest smart watch. This new product will integrate advanced emotional health monitoring functions. The Xuanji Perception System provides users with a comprehensive health assessment with its six characteristics - accuracy, comprehensiveness, speed, flexibility, openness and scalability. The system uses a super-sensing module and optimizes the multi-channel optical path architecture technology, which greatly improves the monitoring accuracy of basic indicators such as heart rate, blood oxygen and respiration rate. In addition, the Xuanji Sensing System has also expanded the research on emotional states based on heart rate data. It is not limited to physiological indicators, but can also evaluate the user's emotional state and stress level. It supports the monitoring of more than 60 sports health indicators, covering cardiovascular, respiratory, neurological, endocrine,
