-
Notifications
You must be signed in to change notification settings - Fork 37
/
GetJWTFactory.php
99 lines (88 loc) · 3.37 KB
/
GetJWTFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Gfreeau\Bundle\GetJWTBundle\DependencyInjection\Security\Factory;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\SecurityFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
class GetJWTFactory implements SecurityFactoryInterface
{
/**
* {@inheritdoc}
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
$providerId = 'security.authentication.provider.get.jwt.'.$id;
$container
->setDefinition($providerId, new DefinitionDecorator($config['authentication_provider']))
->replaceArgument(0, new Reference($userProvider))
->replaceArgument(1, new Reference($config['user_checker']))
->replaceArgument(2, $id)
;
$listenerId = 'security.authentication.listener.get.jwt.'.$id;
$listener = $container
->setDefinition($listenerId, new DefinitionDecorator('gfreeau_get_jwt.security.authentication.listener'))
->replaceArgument(2, $id)
->replaceArgument(5, $config)
;
if (isset($config['success_handler'])) {
$listener->replaceArgument(3, new Reference($config['success_handler']));
}
if ($config['throw_exceptions']) {
// remove failure handler
$listener->replaceArgument(4, null);
} else if (isset($config['failure_handler'])) {
$listener->replaceArgument(4, new Reference($config['failure_handler']));
}
return array($providerId, $listenerId, $defaultEntryPoint);
}
/**
* {@inheritdoc}
*/
public function getPosition()
{
return 'pre_auth';
}
/**
* {@inheritdoc}
*/
public function getKey()
{
return 'gfreeau_get_jwt';
}
/**
* {@inheritdoc}
*/
public function addConfiguration(NodeDefinition $node)
{
$node
->children()
->scalarNode('username_parameter')
->defaultValue('username')
->end()
->scalarNode('password_parameter')
->defaultValue('password')
->end()
->booleanNode('post_only')
->defaultTrue()
->end()
->scalarNode('success_handler')
->defaultValue('lexik_jwt_authentication.handler.authentication_success')
->end()
->scalarNode('failure_handler')
->defaultValue('lexik_jwt_authentication.handler.authentication_failure')
->end()
->booleanNode('throw_exceptions')
->defaultFalse()
->end()
->scalarNode('authentication_provider')
->defaultValue('security.authentication.provider.dao')
->end()
->scalarNode('user_checker')
->defaultValue('security.user_checker')
->treatNullLike('security.user_checker')
->info('The UserChecker to use when authenticating users in this firewall.')
->end()
->end();
}
}