LDAP Configuration Laravel5 - Authentication user provider [adldap] is not defined - php

I'm fresh beginner in Laravel 5.8 and i'm trying to develop an app with LDAP authentication.
I use this package : https://adldap2.github.io/Adldap2-Laravel/#/auth/setup
So, here is my configuration code (app.php) :
// service providers array
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class
// aliases array
'Adldap' => Adldap\Laravel\Facades\Adldap::class
The LDAP configuration (ldap.php) :
'hosts' => explode(' ', env('LDAP_HOSTS', 'myserver1 myserver2'))
'port' => env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=mydc1,dc=mydc2,dc=mydc3'),
'username' => env('admin'),
'password' => env('admin'),
The authentication configuration (auth.php) :
// user provider fields
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'users' => [
'driver' => 'adldap',
'model' => App\User::class,
],
],
And then the UserController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Adldap\AdldapInterface;
class UserController extends Controller
{
protected $ldap;
public function __construct(AdldapInterface $ldap) {
$this->ldap = $ldap;
}
public function index() {
$users = $this->ldap->search()->users()->get();
return view('users.index',compact('users'));
}
}
And i got this error : Authentication user provider [adldap] is not defined.
Does anyone know this error and could tell me where my configuration can be wrong ?
Thansk for your help :)
EDIT : Idk if this could help but this morning the error precise me that the problem is in the welcome.blade.php file

You need to add some basic configuration in your .env file
ACCOUNT_PREFIX = local
ACCOUNT_SUFFIX = local
DOMAIN_CONTROLLERS = "172.16.20.142"
PORT = 389
TIMEOUT = 5
BASE_DN = "dc=local,dc=local"
USER_DN = "cn=users,dc=dummy,dc=local"
ADMIN_ACCOUNT_SUFFIX = #man.local
ADMIN_USERNAME = administrator
ADMIN_PASSWORD = dsds
LDAP_USER_CUSTOM_EMAIL_DOMAIN = #man.local
and check your aldap.config once
after that please clear cache of config by following command
php artisan config:clear && php artisan cache:clear && php artisan view:clear && php artisan route:clear && php artisan config:cache

Related

Laravel: Jasper reports in laravel lumen5.6

I already implemented jasper reports with laravel and it works fine for me. Now i shifted to laravel lumen for api building so i try to integrate jasper as same as i integrate in my laravel projects but in laravel lumen it throws some error as below:-
Call to undefined method Laravel\Lumen\Application::booting()
below is my connection code
class_alias(JasperPHP\JasperPHPServiceProvider::class,'JasperPHP');
$app->withFacades(); $app->withEloquent();
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(JasperPHP\JasperPHPServiceProvider::class);
Please share your thoughts, Thanks in advance
I finally come up with a solution and it works fine with laravel lumen 5.6 below are the steps:-
1)Install JasperReports 6 library by below command
composer require cossou/jasperphp
In bootstrap/app.php uncomment this line $app->withFacades(); and add below code
$app->singleton('jasperphp', function ($app) {
return new JasperPHP;
});
$app->alias('JasperPHP\JasperPHPServiceProvider\JasperPHP', 'JasperPHP');
Controller part Changes
namespace App\Http\Controllers;
use JasperPHP\JasperPHP as JasperPHP;
use Illuminate\Http\Request;
//dd(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper');
class ReportController extends Controller {
public function generateReport() {
//JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
$jasper = new JasperPHP;
$filename = 'gau';
$output = base_path('//public/reports/' . $filename);
$jasper->process(
base_path('/vendor/cossou/jasperphp/examples/LaravelIreporTest.jasper'),
$output,
array("pdf"),
array("test" => "Tax Invoice"),
array(
'driver' => 'mysql',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'database' => 'database name',
'port' => '3306',
)
)->execute();
}
}

Laravel 5.2 queue job keeps on retrying

class ProcessComment extends Job implements ShouldQueue
{
use InteractsWithQueue;
/**
* #var int
*/
public $tries = 1;
public function handle(Somedepency $someDependency) {
// method body....
// tries to connect to a database
// deliberately provide the wrong database url so that the job .
// will throw exception and hence faild
}
The problem is that when i run php artisan queue:work --daemon or php artisan queue:work --daemon --tries=1
The tries option doesn't seem to work. In my redis queue I continuously see the attempts it tries to make like. It should try only one time and if the job failed, just ignore that job and move ahead.
"EXEC"
1522044746.165780 [0 172.20.0.5:48992] "WATCH" "queues:comments:reserved"
1522044746.166110 [0 172.20.0.5:48992] "ZRANGEBYSCORE" "queues:comments:reserved" "-inf" "1522044746"
1522044746.166718 [0 172.20.0.5:48992] "UNWATCH"
1522044746.167436 [0 172.20.0.5:48992] "LPOP" "queues:comments"
1522044746.168051 [0 172.20.0.5:48992] "ZADD" "queues:comments:reserved" "1522044806" {"some serialized data here ... "attempts: 4"}
and so on
This is my configs/queue.php
'default' => env('QUEUE_DRIVER', 'redis'),
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'comments'
],
],
tried to google it alot but couldn't find satisfactory answer.
Thanks

How to use functions in services.php laravel config file

I needed to use a dynamic callback url for socialite so I added the url() function to my services.php file it worked fine(and its still working on my live server) But when tried to start the project locally I get the following error. When I remove the url() method everything works fine please help.
PHP Fatal error: Uncaught ReflectionException: Class log does not exist in /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php:734
Stack trace:
#0 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('log')
#1 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php(849): Illuminate\Foundation\Application->make('log')
#4 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php(7 in /home/fenn/projects/jokwit/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 734
Here is my services.php file
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, Mandrill, and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
'mandrill' => [
'secret' => env('MANDRILL_SECRET'),
],
'ses' => [
'key' => env('SES_KEY'),
'secret' => env('SES_SECRET'),
'region' => 'us-east-1',
],
'stripe' => [
'model' => App\User::class,
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
'facebook' => [
'client_id' => '1700935300171729',
'client_secret' => 'XXXXXXXXXXXXXXXXXXX',
'redirect' => url('/facebook/callback'),
],
'google' => [
'client_id' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
'client_secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
'redirect' => url('google/callback'),
],
];
In services.php file
...
'redirect' => 'google/callback',
...
Next create service provider for example ConfigServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* #return void
*/
public function register()
{
\Config::set("services.google.redirect", url(\Config::get('services')['google']['redirect']));
}
}
now should work fine
It doesn't work because in production Laravel cached all configuration files and using this cache. In development environment Laravel didn't create cache.
You can check it by commenting url() in config and then running php artisan config:cache command. Uncomment url() part and you'll see error is disappeared.
The best you can do here is to not use Laravel or manually defined functions in config files and find another solution for your problem.

How to accommodate Amazon FIFO SQS in Laravel queue?

Amazon has announced their new FIFO SQS service and I'd like to use it in Laravel Queue to solve some concurrency issues.
I've created several new queues and changed the configurations. However, I got a MissingParameter error which says
The request must contain the parameter MessageGroupId.
So I modified the file vendor/laravel/framework/src/Illuminate/Queue/SqsQueue.php
public function pushRaw($payload, $queue = null, array $options = [])
{
$response = $this->sqs->sendMessage(['QueueUrl' => $this->getQueue($queue), 'MessageBody' => $payload,
'MessageGroupId' => env('APP_ENV', getenv('APP_ENV'))]);
return $response->get('MessageId');
}
public function later($delay, $job, $data = '', $queue = null)
{
$payload = $this->createPayload($job, $data);
$delay = $this->getSeconds($delay);
return $this->sqs->sendMessage([
'QueueUrl' => $this->getQueue($queue), 'MessageBody' => $payload, 'DelaySeconds' => $delay,
'MessageGroupId' => env('APP_ENV', getenv('APP_ENV'))
])->get('MessageId');
}
I'm using APP_ENV as the group ID (it's a single message queue so actually it doesn't matter a lot. I just want everything to be FIFO).
But I'm still getting the same error message. How could I fix it? Any help would be appreciated.
(btw, where has the SDK defined sendMessage? I can find a stub for it but I didn't find the detailed implementation)
I want to point out to others who might stumble across the same issue that, although editing SqsQueue.php works, it will easily be reset by a composer install or composer update. An alternative is to implement a new Illuminate\Queue\Connectors\ConnectorInterface for SQS FIFO then add it to Laravel's queue manager.
My approach is as follows:
Create a new SqsFifoQueue class that extends Illuminate\Queue\SqsQueue but supports SQS FIFO.
Create a new SqsFifoConnector class that extends Illuminate\Queue\Connectors\SqsConnector that would establish a connection using SqsFifoQueue.
Create a new SqsFifoServiceProvider that registers the SqsFifoConnector to Laravel's queue manager.
Add SqsFifoServiceProvider to your config/app.php.
Update config/queue.php to use the new SQS FIFO Queue driver.
Example:
Create a new SqsFifoQueue class that extends Illuminate\Queue\SqsQueue but supports SQS FIFO.
<?php
class SqsFifoQueue extends \Illuminate\Queue\SqsQueue
{
public function pushRaw($payload, $queue = null, array $options = [])
{
$response = $this->sqs->sendMessage([
'QueueUrl' => $this->getQueue($queue),
'MessageBody' => $payload,
'MessageGroupId' => uniqid(),
'MessageDeduplicationId' => uniqid(),
]);
return $response->get('MessageId');
}
}
Create a new SqsFifoConnector class that extends Illuminate\Queue\Connectors\SqsConnector that would establish a connection using SqsFifoQueue.
<?php
use Aws\Sqs\SqsClient;
use Illuminate\Support\Arr;
class SqsFifoConnector extends \Illuminate\Queue\Connectors\SqsConnector
{
public function connect(array $config)
{
$config = $this->getDefaultConfiguration($config);
if ($config['key'] && $config['secret']) {
$config['credentials'] = Arr::only($config, ['key', 'secret']);
}
return new SqsFifoQueue(
new SqsClient($config), $config['queue'], Arr::get($config, 'prefix', '')
);
}
}
Create a new SqsFifoServiceProvider that registers the SqsFifoConnector to Laravel's queue manager.
<?php
class SqsFifoServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->app->afterResolving('queue', function ($manager) {
$manager->addConnector('sqsfifo', function () {
return new SqsFifoConnector;
});
});
}
}
Add SqsFifoServiceProvider to your config/app.php.
<?php
return [
'providers' => [
...
SqsFifoServiceProvider::class,
],
];
Update config/queue.php to use the new SQS FIFO Queue driver.
<?php
return [
'default' => 'sqsfifo',
'connections' => [
'sqsfifo' => [
'driver' => 'sqsfifo',
'key' => 'my_key'
'secret' => 'my_secret',
'queue' => 'my_queue_url',
'region' => 'my_sqs_region',
],
],
];
Then your queue should now support SQS FIFO Queues.
Shameless plug: While working on the steps above I've created a laravel-sqs-fifo composer package to handle this at https://github.com/maqe/laravel-sqs-fifo.
FIFO message works in a different way than standard AWS SQS queues.
You need a separate driver for handling FIFO queues.
I had to face the same situation and the below package was a lifesaver.
https://packagist.org/packages/shiftonelabs/laravel-sqs-fifo-queue
in queue.php
'sqs-fifo' => [
'driver' => 'sqs-fifo',
'key' => env('SQS_KEY'),
'secret' => env('SQS_SECRET'),
'prefix' => env('SQS_PREFIX'),
'queue' => env('SQS_QUEUE'),
'region' => env('SQS_REGION'),
'group' => 'default',
'deduplicator' => 'unique',
],
then
dispatch(new TestJob([]))->onQueue('My_Mail_Queue.fifo');
NB:
you need to specify default queue name you are going to use in your application in the .env
SQS_QUEUE=My_Default_queue.fifo
Also, you need to specify all the queue names you are going to use in your application in the listener. (if you are using the same queue name for the whole application, you don't need to specify the queue name in the listener)
php artisan queue:listen --queue=My_Default_queue.fifo,My_Mail_Queue.fifo,My_Message_Queue.fifo
Apart from the MessageGroupId, it needs a MessageDeduplicationId or enabling content-based deduplication.

Unable to Subscribe to Redis Channel Laravel 5.2

I am following Laravel office Redis guide but i am having some problem
https://laravel.com/docs/5.2/redis#pubsub
After creating the command when i run " -> php artisan redis:subscribe" in console i get following error
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "redis" namespace.
I am unable to listen to Redis Chanel.
Redis Publish Channel method is working fine. To check this.
In console I typed "-> redis-cli" and then "subscribe mychannel"
On refreshing browser I am getting publish data in console.
I am unable to subscribe via Laravel.
I also tried using wild card
Route::get('/subscribe', function()
{
Redis::psubscribe(['*'], function($message, $channel) {
echo $message;
});
});
but browser keep loading and i don't get any data.
I also tried making a method in controller
public function subscribeChannel()
{
$redis = Redis::Connection();
$redis->subscribe(['channel'], function($message) {
echo $message;
});
}
This subscribeChannel method gives me following error
ErrorException in StreamConnection.php line 390:
strlen() expects parameter 1 to be string, array given
My configuration in config/database.php is folowing
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'read_write_timeout' => 0
],
],
Looking for help
thanks
Redis::connection & then subscribe not working for Laravel 5.2.
You can use following command for the same:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
});
If you want to use another connection for the same then you can use following command:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
}, $connection = 'socket');

Categories