|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the login-cidadao project or it's bundles. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Guilherme Donato <guilhermednt on github> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace LoginCidadao\OpenIDBundle\Form; |
|
12
|
|
|
|
|
13
|
|
|
use LoginCidadao\CoreBundle\Form\Type\SwitchType; |
|
14
|
|
|
use LoginCidadao\OpenIDBundle\Entity\ClientMetadata; |
|
15
|
|
|
use Symfony\Component\Form\AbstractType; |
|
16
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
|
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
|
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\UrlType; |
|
21
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
22
|
|
|
use Symfony\Component\Form\FormEvent; |
|
23
|
|
|
use Symfony\Component\Form\FormEvents; |
|
24
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
25
|
|
|
use LoginCidadao\CoreBundle\Form\DataTransformer\FromArray; |
|
26
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
|
27
|
|
|
|
|
28
|
|
|
class ClientMetadataWebForm extends AbstractType |
|
29
|
|
|
{ |
|
30
|
|
|
const RESPONSE_TYPE_CHOICES = [ |
|
31
|
|
|
'code' => 'code', |
|
32
|
|
|
'id_token' => 'id_token', |
|
33
|
|
|
'token id_token' => 'token id_token', |
|
34
|
|
|
'code id_token' => 'code id_token', |
|
35
|
|
|
'code token' => 'code token', |
|
36
|
|
|
'code token id_token' => 'code token id_token', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
const GRANT_TYPE_CHOICES = [ |
|
40
|
|
|
'authorization_code' => 'authorization_code', |
|
41
|
|
|
'implicit' => 'implicit', |
|
42
|
|
|
'refresh_token' => 'refresh_token', |
|
43
|
|
|
'client_credentials' => 'client_credentials', |
|
44
|
|
|
]; |
|
45
|
|
|
|
|
46
|
|
|
const SUBJECT_TYPE_CHOICES = [ |
|
47
|
|
|
'pairwise' => 'pairwise', |
|
48
|
|
|
'public' => 'public', |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
const TOKEN_ENDPOINT_AUTH_METHOD_CHOICES = [ |
|
52
|
|
|
'client_secret_basic' => 'client_secret_basic', |
|
53
|
|
|
'client_secret_post' => 'client_secret_post', |
|
54
|
|
|
'client_secret_jwt' => 'client_secret_jwt', |
|
55
|
|
|
'private_key_jwt' => 'private_key_jwt', |
|
56
|
|
|
'none' => 'none', |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
|
|
/** @var AuthorizationCheckerInterface */ |
|
60
|
|
|
private $authChecker; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* ClientMetadataWebForm constructor. |
|
64
|
|
|
* @param AuthorizationCheckerInterface $authChecker |
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct(AuthorizationCheckerInterface $authChecker) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->authChecker = $authChecker; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
72
|
|
|
{ |
|
73
|
|
|
$builder |
|
74
|
|
|
->add('organization', 'text', ['disabled' => true]) |
|
75
|
|
|
->add( |
|
76
|
|
|
$builder->create('request_uris', TextareaType::class, ['required' => false]) |
|
77
|
|
|
->addModelTransformer(new FromArray()) |
|
78
|
|
|
) |
|
79
|
|
|
->add( |
|
80
|
|
|
$builder->create('post_logout_redirect_uris', TextareaType::class, ['required' => false]) |
|
81
|
|
|
->addModelTransformer(new FromArray()) |
|
82
|
|
|
) |
|
83
|
|
|
->add('response_types', ChoiceType::class, [ |
|
84
|
|
|
'multiple' => true, |
|
85
|
|
|
'choices' => self::RESPONSE_TYPE_CHOICES, |
|
86
|
|
|
]) |
|
87
|
|
|
->add('grant_types', ChoiceType::class, [ |
|
88
|
|
|
'multiple' => true, |
|
89
|
|
|
'choices' => self::GRANT_TYPE_CHOICES, |
|
90
|
|
|
]) |
|
91
|
|
|
->add('application_type', ChoiceType::class, ['choices' => ['web' => 'web', 'native' => 'native']]) |
|
92
|
|
|
->add('logo_uri', UrlType::class) |
|
93
|
|
|
->add('policy_uri', UrlType::class, ['required' => false]) |
|
94
|
|
|
->add('jwks_uri', UrlType::class, ['required' => false]) |
|
95
|
|
|
->add('jwks', TextType::class, ['required' => false]) |
|
96
|
|
|
->add('sector_identifier_uri', UrlType::class, ['required' => false]) |
|
97
|
|
|
->add('id_token_signed_response_alg', TextType::class, ['required' => false]) |
|
98
|
|
|
->add('id_token_encrypted_response_alg', TextType::class, ['required' => false]) |
|
99
|
|
|
->add('id_token_encrypted_response_enc', TextType::class, ['required' => false]) |
|
100
|
|
|
->add('userinfo_signed_response_alg', TextType::class, ['required' => false]) |
|
101
|
|
|
->add('userinfo_encrypted_response_alg', TextType::class, ['required' => false]) |
|
102
|
|
|
->add('userinfo_encrypted_response_enc', TextType::class, ['required' => false]) |
|
103
|
|
|
->add('request_object_signing_alg', TextType::class, ['required' => false]) |
|
104
|
|
|
->add('request_object_encryption_alg', TextType::class, ['required' => false]) |
|
105
|
|
|
->add('request_object_encryption_enc', TextType::class, ['required' => false]) |
|
106
|
|
|
->add('token_endpoint_auth_method', ChoiceType::class, |
|
107
|
|
|
['choices' => self::TOKEN_ENDPOINT_AUTH_METHOD_CHOICES,]) |
|
108
|
|
|
->add('token_endpoint_auth_signing_alg', TextType::class, ['required' => false]) |
|
109
|
|
|
->add('default_max_age', IntegerType::class, ['required' => false]) |
|
110
|
|
|
->add('require_auth_time', SwitchType::class, ['required' => false]) |
|
111
|
|
|
->add( |
|
112
|
|
|
$builder->create('default_acr_values', TextareaType::class, ['required' => false]) |
|
113
|
|
|
->addModelTransformer(new FromArray()) |
|
114
|
|
|
) |
|
115
|
|
|
->addEventListener(FormEvents::PRE_SET_DATA, $this->getCheckSubjectTypeCallback()); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
119
|
|
|
{ |
|
120
|
|
|
parent::configureOptions($resolver); |
|
121
|
|
|
$resolver->setDefaults([ |
|
122
|
|
|
'data_class' => ClientMetadata::class, |
|
123
|
|
|
'csrf_protection' => true, |
|
124
|
|
|
]); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function getBlockPrefix() |
|
128
|
|
|
{ |
|
129
|
|
|
return ''; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
private function getCheckSubjectTypeCallback() |
|
133
|
|
|
{ |
|
134
|
|
|
$authChecker = $this->authChecker; |
|
135
|
|
|
|
|
136
|
|
|
return function (FormEvent $event) use ($authChecker) { |
|
137
|
|
|
if ($authChecker->isGranted('ROLE_EDIT_CLIENT_SUBJECT_TYPE')) { |
|
138
|
|
|
$event->getForm() |
|
139
|
|
|
->add('subject_type', ChoiceType::class, ['choices' => self::SUBJECT_TYPE_CHOICES]); |
|
140
|
|
|
} |
|
141
|
|
|
}; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* {@inheritdoc} |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getName() |
|
148
|
|
|
{ |
|
149
|
|
|
return 'oidc_client_metadata_form_type'; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|