118 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
		
		
			
		
	
	
			118 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace BookStack\Providers;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use BookStack\User;
							 | 
						||
| 
								 | 
							
								use Illuminate\Contracts\Auth\Authenticatable;
							 | 
						||
| 
								 | 
							
								use Illuminate\Contracts\Auth\UserProvider;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class LdapUserProvider implements UserProvider
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * The user model.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @var string
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    protected $model;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * LdapUserProvider constructor.
							 | 
						||
| 
								 | 
							
								     * @param $model
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function __construct($model)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $this->model = $model;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Create a new instance of the model.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @return \Illuminate\Database\Eloquent\Model
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function createModel()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $class = '\\'.ltrim($this->model, '\\');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        return new $class;
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Retrieve a user by their unique identifier.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param  mixed $identifier
							 | 
						||
| 
								 | 
							
								     * @return \Illuminate\Contracts\Auth\Authenticatable|null
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function retrieveById($identifier)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        return $this->createModel()->newQuery()->find($identifier);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Retrieve a user by their unique identifier and "remember me" token.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param  mixed  $identifier
							 | 
						||
| 
								 | 
							
								     * @param  string  $token
							 | 
						||
| 
								 | 
							
								     * @return \Illuminate\Contracts\Auth\Authenticatable|null
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function retrieveByToken($identifier, $token)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $model = $this->createModel();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        return $model->newQuery()
							 | 
						||
| 
								 | 
							
								            ->where($model->getAuthIdentifierName(), $identifier)
							 | 
						||
| 
								 | 
							
								            ->where($model->getRememberTokenName(), $token)
							 | 
						||
| 
								 | 
							
								            ->first();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Update the "remember me" token for the given user in storage.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param  \Illuminate\Contracts\Auth\Authenticatable $user
							 | 
						||
| 
								 | 
							
								     * @param  string                                     $token
							 | 
						||
| 
								 | 
							
								     * @return void
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function updateRememberToken(Authenticatable $user, $token)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $user->setRememberToken($token);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $user->save();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Retrieve a user by the given credentials.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param  array $credentials
							 | 
						||
| 
								 | 
							
								     * @return \Illuminate\Contracts\Auth\Authenticatable|null
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function retrieveByCredentials(array $credentials)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        // TODO: Implement retrieveByCredentials() method.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Get user via LDAP
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // Search current user base by looking up a uid
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        // If not exists create a new user instance with attached role
							 | 
						||
| 
								 | 
							
								        // but do not store it in the database yet
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        //
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * Validate a user against the given credentials.
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     * @param  \Illuminate\Contracts\Auth\Authenticatable $user
							 | 
						||
| 
								 | 
							
								     * @param  array                                      $credentials
							 | 
						||
| 
								 | 
							
								     * @return bool
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function validateCredentials(Authenticatable $user, array $credentials)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        // TODO: Implement validateCredentials() method.
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |