From 50e4d45f8dc08d7eb73c0e109ceb1937f94eb5c0 Mon Sep 17 00:00:00 2001 From: Guilherme Donato Date: Mon, 4 Apr 2016 09:25:54 -0300 Subject: [PATCH 01/14] Updating from Rede Livre --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c9eea18d1..0a4699b94 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ /.buildpath /app/check.php /.vagrant +.idea From eddccf5a93608c2885e192415472b6be9a154927 Mon Sep 17 00:00:00 2001 From: Guilherme Donato Date: Mon, 4 Apr 2016 15:02:53 -0300 Subject: [PATCH 02/14] Deprecated usernames #378 * added feature flag to hide/show username change link #378 * username hidden #378 --- app/config/security.yml | 2 + src/LoginCidadao/CoreBundle/Entity/Person.php | 9 +++ .../views/Default/dashboard.html.twig | 58 +++++++++++++------ .../views/Person/profile/edit.html.twig | 2 +- .../views/Person/profile/show.html.twig | 2 +- .../Person/registration/confirmed.html.twig | 2 +- .../views/Person/registration/email.html.twig | 8 +-- .../views/Person/resetting/email.html.twig | 5 +- .../Resources/views/base.loggedIn.html.twig | 22 +++---- .../Resources/views/navbar.html.twig | 2 +- 10 files changed, 72 insertions(+), 40 deletions(-) diff --git a/app/config/security.yml b/app/config/security.yml index 50effd324..1c0518976 100644 --- a/app/config/security.yml +++ b/app/config/security.yml @@ -17,6 +17,7 @@ security: - ROLE_USER - ROLE_ORGANIZATIONS_BIND_CLIENT - ROLE_EDIT_CLIENT_ALLOWED_SCOPES + - FEATURE_EDIT_USERNAME ROLE_SUPER: - ROLE_DEV - ROLE_ORGANIZATIONS_CREATE @@ -47,6 +48,7 @@ security: FEATURE_IGP_VALIDATION: FEATURE_ORGANIZATIONS: FEATURE_IMPERSONATION_REPORTS: + FEATURE_EDIT_USERNAME: providers: chainprovider: diff --git a/src/LoginCidadao/CoreBundle/Entity/Person.php b/src/LoginCidadao/CoreBundle/Entity/Person.php index 5d65f8fb9..645fc0273 100644 --- a/src/LoginCidadao/CoreBundle/Entity/Person.php +++ b/src/LoginCidadao/CoreBundle/Entity/Person.php @@ -1317,4 +1317,13 @@ public function getEncoderName() return $encoder; } + + public function getShortDisplayName() + { + if ($this->getGivenName()) { + return $this->getGivenName(); + } else { + return $this->getEmail(); + } + } } diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Default/dashboard.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Default/dashboard.html.twig index 5e8f276ec..d58d38702 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Default/dashboard.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Default/dashboard.html.twig @@ -7,15 +7,20 @@
{% trans %}Profile{% endtrans %} - +
- +
-

- - {{ app.user.firstName }} -

+ {% if app.user.firstName is not null %} +

+ + {{ app.user.firstName }} +

+ {% endif %} {% if app.user.birthdate is not null %}
{{ app.user.birthdate | date('birthdate.format' | trans) }}
{% endif %} @@ -41,21 +46,24 @@
{% trans %}Services{% endtrans %} - +
{% if app.user.getAuthorizations|length > 0 %} {% for auth in app.user.getAuthorizations %} {% if auth.client.uid != defaultClientUid %} - + {% endif %} {% endfor %} {% else %}

{% trans %}You don't have any active service.{% endtrans %}

{{ 'Check the services available' | trans }}

- {% endif %} + {% endif %}
@@ -67,15 +75,18 @@
{{ 'Badges' | trans }} - +
{% if userBadges|length == 0 %} - + {% endif %} {% for client, badges in allBadges %} {% for badge, content in badges %} - {% set key = client ~ '.' ~ badge %} + {% set key = client ~ '.' ~ badge %} {% if key in userBadges|keys %}
{% endif %} @@ -92,11 +103,14 @@
{% if notifications|length == 0 %} - + {% endif %} {% for notification in notifications %} - - {{ notification.sender.name }} - {{ notification.title }} - {{ notification.createdAt|date("d/m/Y H:i:s") }} + + {{ notification.sender.name }} - {{ notification.title }} + - {{ notification.createdAt|date("d/m/Y H:i:s") }} {% endfor %}
@@ -111,12 +125,15 @@
{{ 'access_log.panel_title' | trans }} - +
    {% if logs.logins|length == 0 %} - + {% endif %} {% for log in logs.logins %}
  • @@ -132,12 +149,15 @@
    {% trans %}Activity Log{% endtrans %} - +
      {% if logs.activity|length == 0 %} - + {% endif %} {% for log in logs.activity %}
    • diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/edit.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/edit.html.twig index 36d0a0f7c..d69485902 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/edit.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/edit.html.twig @@ -23,7 +23,7 @@

    {{ 'Personal Information' | trans }}

    - {{ app.user.username }} + {{ app.user.shortDisplayName }}
diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/show.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/show.html.twig index 650a43dd6..4b17fc65c 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/show.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Person/profile/show.html.twig @@ -13,7 +13,7 @@ {% trans_default_domain 'FOSUserBundle' %}
-

{{ 'profile.show.username'|trans }}: {{ user.username }}

+

{{ 'profile.show.username'|trans }}: {{ user.shortDisplayName }}

{{ 'profile.show.email'|trans }}: {{ user.email }}

diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/confirmed.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/confirmed.html.twig index bfd5c32cd..345ea7b32 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/confirmed.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/confirmed.html.twig @@ -4,7 +4,7 @@ {% trans_default_domain 'FOSUserBundle' %} -

{{ 'registration.confirmed'|trans({'%username%': user.username}) }}

+

{{ 'registration.confirmed'|trans({'%username%': user.shortDisplayName}) }}

{% if app.session is not empty %} {% set targetUrl = app.session.get('_security.' ~ app.security.token.providerKey ~ '.target_path') %} {% if targetUrl is not empty %}

{{ 'registration.back'|trans }}

{% endif %} diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/email.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/email.html.twig index 197b6cdf5..9ef32dbfe 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/email.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Person/registration/email.html.twig @@ -2,13 +2,13 @@ {% block subject %} {% autoescape false %} -{{ 'registration.email.subject'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} +{{ 'registration.email.subject'|trans({'%username%': user.shortDisplayName, '%confirmationUrl%': confirmationUrl}) }} {% endautoescape %} {% endblock %} {% block body_text %} {% autoescape false %} -{{ 'registration.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} +{{ 'registration.email.message'|trans({'%username%': user.shortDisplayName, '%confirmationUrl%': confirmationUrl}) }} {% endautoescape %} {% endblock %} @@ -16,8 +16,8 @@ {% block body_html %} {% autoescape false %} {{ include("LoginCidadaoCoreBundle::common.email.html.twig", { - 'subject' : 'registration.email.subject' | trans({'%username%': user.username}), - 'msg' : 'registration.email.message.html' | trans({'%username%': user.username}) | raw, + 'subject' : 'registration.email.subject' | trans({'%username%': user.shortDisplayName}), + 'msg' : 'registration.email.message.html' | trans({'%username%': user.shortDisplayName}) | raw, 'url' : confirmationUrl, 'urlsubject' : 'registration.email.click' | trans } ) }} diff --git a/src/LoginCidadao/CoreBundle/Resources/views/Person/resetting/email.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/Person/resetting/email.html.twig index 269043519..5db8a1145 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/Person/resetting/email.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/Person/resetting/email.html.twig @@ -8,14 +8,13 @@ {% block body_text %} {% autoescape false %} -{{ 'resetting.email.message'|trans({'%username%': user.username, '%confirmationUrl%': confirmationUrl}) }} +{{ 'resetting.email.message'|trans({'%username%': user.shortDisplayName, '%confirmationUrl%': confirmationUrl}) }} {% endautoescape %} {% endblock %} {% block body_html %} {% autoescape false %} -{{ include("LoginCidadaoCoreBundle::common.email.html.twig", {'subject' : 'registration.email.subject'|trans({'%username%': user.username}), 'msg' : 'resetting.email.message'|trans, 'url' : confirmationUrl } ) }} +{{ include("LoginCidadaoCoreBundle::common.email.html.twig", {'subject' : 'registration.email.subject'|trans({'%username%': user.shortDisplayName}), 'msg' : 'resetting.email.message'|trans, 'url' : confirmationUrl } ) }} {% endautoescape %} {% endblock %} - diff --git a/src/LoginCidadao/CoreBundle/Resources/views/base.loggedIn.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/base.loggedIn.html.twig index 54ecf682d..315099399 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/base.loggedIn.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/base.loggedIn.html.twig @@ -31,7 +31,7 @@ -
  • +
  • {% trans %}Addresses{% endtrans %} @@ -49,14 +49,16 @@
  • -
  • - - {% trans %}Change Username{% endtrans %} - - -
  • -
  • - + {% if is_granted('FEATURE_EDIT_USERNAME') %} +
  • + + {% trans %}Change Username{% endtrans %} + + +
  • + {% endif %} +
  • + {% trans %}Security{% endtrans %} @@ -125,7 +127,7 @@ {% block stylesheets_custom %} {% stylesheets '@lc_logged_css' filter='cssrewrite' filter='?uglifycss' %} - + {% endstylesheets %} {% endblock %} diff --git a/src/LoginCidadao/CoreBundle/Resources/views/navbar.html.twig b/src/LoginCidadao/CoreBundle/Resources/views/navbar.html.twig index 11c9f326d..5b53abdee 100644 --- a/src/LoginCidadao/CoreBundle/Resources/views/navbar.html.twig +++ b/src/LoginCidadao/CoreBundle/Resources/views/navbar.html.twig @@ -41,7 +41,7 @@ {# Profile Card #}
  • diff --git a/src/LoginCidadao/OAuthBundle/Controller/ClientController.php b/src/LoginCidadao/OAuthBundle/Controller/ClientController.php index 3612cd676..08c32b026 100644 --- a/src/LoginCidadao/OAuthBundle/Controller/ClientController.php +++ b/src/LoginCidadao/OAuthBundle/Controller/ClientController.php @@ -9,38 +9,5 @@ class ClientController extends Controller { - /** - * @Route("/auth/initClient", name="lc_oauth_init") - * @Template() - */ - public function initClientAction() - { - $clientManager = $this->get('fos_oauth_server.client_manager'); - - $client = $clientManager->findClientBy(array('name' => "VPR")); - if ($client instanceof Client) { - $client->setAllowedGrantTypes(array('authorization_code')); - } else { - $client = $clientManager->createClient(); - $client->setRedirectUris(array('http://vpr.des.dona.to')); - $client->setAllowedGrantTypes(array('authorization_code')); - $client->setName("VPR"); - $client->setDescription("Votação de Prioridades do RS"); - } - $clientManager->updateClient($client); - - die("ok"); - } - - /** - * @Route("/auth/getPub/{id}", name="lc_oauth_getid") - */ - public function getPublicIdAction($id) - { - $clientManager = $this->get('fos_oauth_server.client_manager'); - $client = $clientManager->findClientBy(array('id' => $id)); - die($client->getPublicId()); - - } } diff --git a/src/LoginCidadao/OAuthBundle/Entity/Client.php b/src/LoginCidadao/OAuthBundle/Entity/Client.php index 0fc1a510c..8ca4ded41 100644 --- a/src/LoginCidadao/OAuthBundle/Entity/Client.php +++ b/src/LoginCidadao/OAuthBundle/Entity/Client.php @@ -16,7 +16,6 @@ use LoginCidadao\CoreBundle\Model\AbstractUniqueEntity; use LoginCidadao\CoreBundle\Model\UniqueEntityInterface; use LoginCidadao\OAuthBundle\Model\ClientInterface; -use LoginCidadao\OAuthBundle\Model\OrganizationInterface; use Vich\UploaderBundle\Mapping\Annotation as Vich; /** @@ -158,24 +157,22 @@ class Client extends BaseClient implements UniqueEntityInterface, ClientInterfac * @ORM\Column(name="updated_at", type="datetime") */ protected $updatedAt; - /** - * @var OrganizationInterface - * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients") - * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") + * @ORM\Column(type="string", nullable=true, unique=true) + * @var string */ - protected $organization; + private $uid; public function __construct() { parent::__construct(); - $this->authorizations = new ArrayCollection(); - $this->owners = new ArrayCollection(); + $this->authorizations = new ArrayCollection(); + $this->owners = new ArrayCollection(); $this->maxNotificationLevel = Notification::LEVEL_NORMAL; $this->allowedScopes = array( 'public_profile', - 'openid' + 'openid', ); } @@ -191,6 +188,21 @@ public static function getAllGrants() ); } + public function getName() + { + if ($this->getMetadata()) { + if ($this->getMetadata()->getClientName() === null && + $this->name !== null + ) { + $this->getMetadata()->setClientName($this->name); + } + + return $this->getMetadata()->getClientName(); + } + + return $this->name; + } + public function setName($name) { if ($this->getMetadata()) { @@ -201,16 +213,9 @@ public function setName($name) return $this; } - public function getName() + public function getDescription() { - if ($this->getMetadata()) { - if ($this->getMetadata()->getClientName() === null && - $this->name !== null) { - $this->getMetadata()->setClientName($this->name); - } - return $this->getMetadata()->getClientName(); - } - return $this->name; + return $this->description; } public function setDescription($description) @@ -218,9 +223,13 @@ public function setDescription($description) $this->description = $description; } - public function getDescription() + public function getSiteUrl() { - return $this->description; + if ($this->getMetadata()) { + return $this->getMetadata()->getClientUri(); + } + + return $this->siteUrl; } public function setSiteUrl($url) @@ -233,14 +242,6 @@ public function setSiteUrl($url) return $this; } - public function getSiteUrl() - { - if ($this->getMetadata()) { - return $this->getMetadata()->getClientUri(); - } - return $this->siteUrl; - } - public function getAuthorizations() { return $this->authorizations; @@ -270,6 +271,7 @@ public function getLandingPageUrl() if ($this->getMetadata()) { return $this->getMetadata()->getInitiateLoginUri(); } + return $this->landingPageUrl; } @@ -279,6 +281,7 @@ public function setLandingPageUrl($landingPageUrl) $this->getMetadata()->setInitiateLoginUri($landingPageUrl); } $this->landingPageUrl = $landingPageUrl; + return $this; } @@ -287,6 +290,7 @@ public function getTermsOfUseUrl() if ($this->getMetadata()) { return $this->getMetadata()->getTosUri(); } + return $this->termsOfUseUrl; } @@ -345,6 +349,7 @@ public function setPublished($published) public function setId($var) { $this->id = $var; + return $this; } @@ -358,17 +363,14 @@ public function getOwners() return $this->owners; } + /* Unique Interface Stuff */ + public function setOwners(ArrayCollection $owners) { $this->owners = $owners; + return $this; } - /* Unique Interface Stuff */ - /** - * @ORM\Column(type="string", nullable=true, unique=true) - * @var string - */ - private $uid; /** * Gets the Unique Id of the Entity. @@ -415,6 +417,7 @@ public function getMetadata() public function setMetadata(\LoginCidadao\OpenIDBundle\Entity\ClientMetadata $metadata) { $this->metadata = $metadata; + return $this; } @@ -423,6 +426,7 @@ public function getRedirectUris() if ($this->getMetadata()) { return $this->getMetadata()->getRedirectUris(); } + return parent::getRedirectUris(); } @@ -433,9 +437,18 @@ public function setRedirectUris(array $redirectUris) } else { parent::setRedirectUris($redirectUris); } + return $this; } + /** + * @return File + */ + public function getImage() + { + return $this->image; + } + /** * If manually uploading a file (i.e. not using Symfony Form) ensure an instance * of 'UploadedFile' is injected into this setter to trigger the update. If this @@ -455,11 +468,11 @@ public function setImage($image) } /** - * @return File + * @return string */ - public function getImage() + public function getImageName() { - return $this->image; + return $this->imageName; } /** @@ -470,14 +483,6 @@ public function setImageName($imageName) $this->imageName = $imageName; } - /** - * @return string - */ - public function getImageName() - { - return $this->imageName; - } - public function getUpdatedAt() { return $this->updatedAt; @@ -494,6 +499,7 @@ public function setUpdatedAt($updatedAt = null) } else { $this->updatedAt = new \DateTime('now'); } + return $this; } @@ -505,26 +511,8 @@ public function getAllowedGrantTypes() if ($this->getMetadata()) { return $this->getMetadata()->getGrantTypes(); } - return parent::getAllowedGrantTypes(); - } - /** - * @return OrganizationInterface - */ - public function getOrganization() - { - return $this->organization; - } - - /** - * @param OrganizationInterface $organization - * @return \LoginCidadao\OAuthBundle\Entity\Client - */ - public function setOrganization(OrganizationInterface $organization) - { - $this->organization = $organization; - - return $this; + return parent::getAllowedGrantTypes(); } public function ownsDomain($domain) diff --git a/src/LoginCidadao/OAuthBundle/Entity/Organization.php b/src/LoginCidadao/OAuthBundle/Entity/Organization.php index f24594222..299897d50 100644 --- a/src/LoginCidadao/OAuthBundle/Entity/Organization.php +++ b/src/LoginCidadao/OAuthBundle/Entity/Organization.php @@ -16,6 +16,7 @@ use LoginCidadao\OAuthBundle\Model\ClientInterface; use LoginCidadao\OAuthBundle\Model\OrganizationInterface; use LoginCidadao\OAuthBundle\Validator\Constraints\DomainOwnership; +use LoginCidadao\OAuthBundle\Validator\Constraints\SectorIdentifier; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; @@ -26,6 +27,7 @@ * @UniqueEntity("domain") * @UniqueEntity("name") * @DomainOwnership + * @SectorIdentifier */ class Organization implements OrganizationInterface { @@ -37,7 +39,7 @@ class Organization implements OrganizationInterface protected $id; /** - * @ORM\Column(type="string", nullable=false, unique=true) + * @ORM\Column(name="name", type="string", nullable=false, unique=true) * @Assert\NotBlank * @var string */ @@ -54,48 +56,55 @@ class Organization implements OrganizationInterface protected $members; /** - * @ORM\Column(type="datetime", nullable=true) + * @ORM\Column(name="verified_at", type="datetime", nullable=true) * @var \DateTime */ protected $verifiedAt; /** - * @ORM\Column(type="string", nullable=false, unique=true) + * @ORM\Column(name="domain", type="string", nullable=false, unique=true) * @var string */ protected $domain; /** - * @ORM\OneToMany(targetEntity="LoginCidadao\OAuthBundle\Model\ClientInterface", mappedBy="organization") + * @ORM\OneToMany(targetEntity="LoginCidadao\OpenIDBundle\Entity\ClientMetadata", mappedBy="organization") * @var ClientInterface */ protected $clients; /** * @Assert\Url - * @ORM\Column(type="string", nullable=true, unique=true) + * @ORM\Column(name="validation_url", type="string", nullable=true, unique=true) * @var string */ protected $validationUrl; /** - * @ORM\Column(type="string", nullable=true) + * @ORM\Column(name="validation_secret", type="string", nullable=true) * @var string */ protected $validationSecret; /** - * @ORM\Column(type="string", nullable=true) + * @ORM\Column(name="validated_url", type="string", nullable=true) * @var string */ protected $validatedUrl; /** - * @ORM\Column(type="boolean", nullable=false) + * @ORM\Column(name="trusted", type="boolean", nullable=false) * @var boolean */ protected $trusted; + /** + * @Assert\Url + * @ORM\Column(name="sector_identifier_uri", type="string", nullable=true, unique=true) + * @var string + */ + protected $sectorIdentifierUri; + public function __construct() { $this->members = new ArrayCollection(); @@ -205,6 +214,7 @@ public function setValidationUrl($validationUrl) public function getValidationSecret() { $this->initializeValidationCode(); + return $this->validationSecret; } @@ -215,26 +225,15 @@ public function setValidationSecret($validationSecret) return $this; } - /** - * @ORM\PrePersist - * @ORM\PreUpdate - */ - private function initializeValidationCode() - { - if ($this->validationSecret) { - return; - } - $random = base64_encode(random_bytes(35)); - $this->setValidationSecret($random); - } - public function checkValidation() { if ($this->validatedUrl !== $this->getValidationUrl()) { $this->setVerifiedAt(null); $this->validatedUrl = null; + return false; } + return true; } @@ -271,4 +270,35 @@ public function setTrusted($trusted) return $this; } + + /** + * @return string + */ + public function getSectorIdentifierUri() + { + return $this->sectorIdentifierUri; + } + + /** + * @param string $sectorIdentifierUri + */ + public function setSectorIdentifierUri($sectorIdentifierUri) + { + $this->sectorIdentifierUri = $sectorIdentifierUri; + } + + /** + * @ORM\PrePersist + * @ORM\PreUpdate + */ + private function initializeValidationCode() + { + if ($this->validationSecret) { + return; + } + $random = base64_encode(random_bytes(35)); + $this->setValidationSecret($random); + } + + } diff --git a/src/LoginCidadao/OAuthBundle/Form/OrganizationType.php b/src/LoginCidadao/OAuthBundle/Form/OrganizationType.php index e4da04e29..7a26b7100 100644 --- a/src/LoginCidadao/OAuthBundle/Form/OrganizationType.php +++ b/src/LoginCidadao/OAuthBundle/Form/OrganizationType.php @@ -29,11 +29,12 @@ class OrganizationType extends AbstractType /** @var TokenStorageInterface */ protected $tokenStorage; - public function __construct(AuthorizationCheckerInterface $authorizationChecker, - TokenStorageInterface $tokenStorage) - { + public function __construct( + AuthorizationCheckerInterface $authorizationChecker, + TokenStorageInterface $tokenStorage + ) { $this->authorizationChecker = $authorizationChecker; - $this->tokenStorage = $tokenStorage; + $this->tokenStorage = $tokenStorage; } /** @@ -42,33 +43,51 @@ public function __construct(AuthorizationCheckerInterface $authorizationChecker, */ public function buildForm(FormBuilderInterface $builder, array $options) { - $members = function(EntityRepository $er) { + $members = function (EntityRepository $er) { return $er->createQueryBuilder('p') - ->innerJoin('LoginCidadaoOAuthBundle:Organization', 'o', - 'WITH', 'p MEMBER OF o.members'); + ->innerJoin( + 'LoginCidadaoOAuthBundle:Organization', + 'o', + 'WITH', + 'p MEMBER OF o.members' + ); }; $builder - ->add('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', - array('label' => 'organizations.form.name.label')) - ->add('domain', + ->add( + 'name', + 'Symfony\Component\Form\Extension\Core\Type\TextType', + array('label' => 'organizations.form.name.label') + ) + ->add( + 'domain', 'Symfony\Component\Form\Extension\Core\Type\TextType', - array('label' => 'organizations.form.domain.label')) - ; + array('label' => 'organizations.form.domain.label') + ) + ->add( + 'sectorIdentifierUri', + 'Symfony\Component\Form\Extension\Core\Type\UrlType', + array('label' => 'organizations.form.sectorIdentifierUri.label') + ); if ($this->authorizationChecker->isGranted('ROLE_ORGANIZATIONS_CAN_TRUST')) { - $builder->add('trusted', + $builder->add( + 'trusted', 'LoginCidadao\CoreBundle\Form\Type\SwitchType', - array('label' => 'organizations.form.trusted.label', 'required' => false)); + array('label' => 'organizations.form.trusted.label', 'required' => false) + ); } if ($this->authorizationChecker->isGranted('ROLE_ORGANIZATIONS_VALIDATE') - && $builder->getData()->getId()) { - $builder->add('validationUrl', + && $builder->getData()->getId() + ) { + $builder->add( + 'validationUrl', 'Symfony\Component\Form\Extension\Core\Type\UrlType', array( - 'required' => false, - 'label' => 'organizations.form.validationUrl.label' - )); + 'required' => false, + 'label' => 'organizations.form.validationUrl.label', + ) + ); } $organization = $builder->getData(); @@ -77,9 +96,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefaults(array( - 'data_class' => 'LoginCidadao\OAuthBundle\Entity\Organization' - )); + $resolver->setDefaults( + array( + 'data_class' => 'LoginCidadao\OAuthBundle\Entity\Organization', + ) + ); } /** @@ -90,102 +111,117 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) $this->configureOptions($resolver); } - private function prepareMembersField(FormBuilderInterface $builder, - OrganizationInterface $organization) - { + private function prepareMembersField( + FormBuilderInterface $builder, + OrganizationInterface $organization + ) { $checker = $this->authorizationChecker; - $person = $this->tokenStorage->getToken()->getUser(); + $person = $this->tokenStorage->getToken()->getUser(); if (!$checker->isGranted('ROLE_ORGANIZATIONS_MANAGE_MEMBERS_ANY_ORG') && - !$checker->isGranted('ROLE_ORGANIZATIONS_MANAGE_MEMBERS')) { + !$checker->isGranted('ROLE_ORGANIZATIONS_MANAGE_MEMBERS') + ) { return; } if (!$organization->getMembers()->contains($person) && - !$checker->isGranted('ROLE_ORGANIZATIONS_MANAGE_MEMBERS_ANY_ORG')) { + !$checker->isGranted('ROLE_ORGANIZATIONS_MANAGE_MEMBERS_ANY_ORG') + ) { return; } - $builder->addEventListener(FormEvents::PRE_SUBMIT, - function(FormEvent $event) { - $entity = $event->getData(); - $form = $event->getForm(); - - $qb = function(EntityRepository $er) use ($entity) { - $sql = $er->createQueryBuilder('u'); - if (!empty($entity['members'])) { - $sql->where('u.id in (:members)'); - $sql->setParameter('members', $entity['members']); - $sql->orderBy('u.username', 'ASC'); - } else { - $sql->where('1 != 1'); - } - return $sql; - }; - - $form->add('members', - 'LoginCidadao\CoreBundle\Form\Type\AjaxChoiceType', - array( - 'label' => 'organizations.form.members.label', - 'ajax_choice_attr' => array( - 'filter' => array( - 'route' => 'lc_organizations_members_filter', - 'search_prop' => 'username', - 'extra_form_prop' => array('service_id' => 'id') - ), - 'selected' => array( - 'route' => 'lc_organizations_members', - 'extra_form_prop' => array('person_id' => 'members') - ), - 'property_value' => 'id', - 'property_text' => 'fullNameOrUsername', - 'search_prop_label' => 'organizations.form.members.search.label' - ), - 'required' => false, - 'class' => 'LoginCidadaoCoreBundle:Person', - 'choice_label' => 'fullNameOrUsername', - 'query_builder' => $qb - )) - ; - }); - - $builder->addEventListener(FormEvents::PRE_SET_DATA, - function(FormEvent $event) { - $entity = $event->getData(); - $form = $event->getForm(); - - $qb = function(EntityRepository $er) use (&$entity) { - return $er->createQueryBuilder('p') - ->innerJoin('LoginCidadaoOAuthBundle:Organization', 'o', - 'WITH', 'p MEMBER OF o.members') - ->orderBy('p.username', 'ASC'); - }; - - if ($entity->getId()) { - $form->add('members', + $builder->addEventListener( + FormEvents::PRE_SUBMIT, + function (FormEvent $event) { + $entity = $event->getData(); + $form = $event->getForm(); + + $qb = function (EntityRepository $er) use ($entity) { + $sql = $er->createQueryBuilder('u'); + if (!empty($entity['members'])) { + $sql->where('u.id in (:members)'); + $sql->setParameter('members', $entity['members']); + $sql->orderBy('u.username', 'ASC'); + } else { + $sql->where('1 != 1'); + } + + return $sql; + }; + + $form->add( + 'members', 'LoginCidadao\CoreBundle\Form\Type\AjaxChoiceType', array( - 'label' => 'organizations.form.members.label', - 'ajax_choice_attr' => array( - 'filter' => array( - 'route' => 'lc_organizations_members_filter', - 'search_prop' => 'username', - 'extra_form_prop' => array('service_id' => 'id') + 'label' => 'organizations.form.members.label', + 'ajax_choice_attr' => array( + 'filter' => array( + 'route' => 'lc_organizations_members_filter', + 'search_prop' => 'username', + 'extra_form_prop' => array('service_id' => 'id'), + ), + 'selected' => array( + 'route' => 'lc_organizations_members', + 'extra_form_prop' => array('person_id' => 'members'), + ), + 'property_value' => 'id', + 'property_text' => 'fullNameOrUsername', + 'search_prop_label' => 'organizations.form.members.search.label', ), - 'selected' => array( - 'route' => 'lc_organizations_members', - 'extra_form_prop' => array('person_id' => 'members') - ), - 'property_value' => 'id', - 'property_text' => 'fullNameOrUsername', - 'search_prop_label' => 'organizations.form.members.search.label' - ), - 'required' => false, - 'class' => 'LoginCidadaoCoreBundle:Person', - 'choice_label' => 'fullNameOrUsername', - 'query_builder' => $qb - )); + 'required' => false, + 'class' => 'LoginCidadaoCoreBundle:Person', + 'choice_label' => 'fullNameOrUsername', + 'query_builder' => $qb, + ) + ); + } + ); + + $builder->addEventListener( + FormEvents::PRE_SET_DATA, + function (FormEvent $event) { + $entity = $event->getData(); + $form = $event->getForm(); + + $qb = function (EntityRepository $er) use (&$entity) { + return $er->createQueryBuilder('p') + ->innerJoin( + 'LoginCidadaoOAuthBundle:Organization', + 'o', + 'WITH', + 'p MEMBER OF o.members' + ) + ->orderBy('p.username', 'ASC'); + }; + + if ($entity->getId()) { + $form->add( + 'members', + 'LoginCidadao\CoreBundle\Form\Type\AjaxChoiceType', + array( + 'label' => 'organizations.form.members.label', + 'ajax_choice_attr' => array( + 'filter' => array( + 'route' => 'lc_organizations_members_filter', + 'search_prop' => 'username', + 'extra_form_prop' => array('service_id' => 'id'), + ), + 'selected' => array( + 'route' => 'lc_organizations_members', + 'extra_form_prop' => array('person_id' => 'members'), + ), + 'property_value' => 'id', + 'property_text' => 'fullNameOrUsername', + 'search_prop_label' => 'organizations.form.members.search.label', + ), + 'required' => false, + 'class' => 'LoginCidadaoCoreBundle:Person', + 'choice_label' => 'fullNameOrUsername', + 'query_builder' => $qb, + ) + ); + } } - }); + ); } } diff --git a/src/LoginCidadao/OAuthBundle/Model/ClientInterface.php b/src/LoginCidadao/OAuthBundle/Model/ClientInterface.php index 58cfd147a..12a723a7e 100644 --- a/src/LoginCidadao/OAuthBundle/Model/ClientInterface.php +++ b/src/LoginCidadao/OAuthBundle/Model/ClientInterface.php @@ -79,14 +79,4 @@ public function setImageName($imageName); * @return string */ public function getImageName(); - - /** - * @return OrganizationInterface - */ - public function getOrganization(); - - /** - * @param \LoginCidadao\OAuthBundle\Model\OrganizationInterface $organization - */ - public function setOrganization(OrganizationInterface $organization); } diff --git a/src/LoginCidadao/OAuthBundle/Resources/views/Organization/fragment.form.html.twig b/src/LoginCidadao/OAuthBundle/Resources/views/Organization/fragment.form.html.twig index 35199304c..f05bc1b93 100644 --- a/src/LoginCidadao/OAuthBundle/Resources/views/Organization/fragment.form.html.twig +++ b/src/LoginCidadao/OAuthBundle/Resources/views/Organization/fragment.form.html.twig @@ -6,6 +6,7 @@
    {{ form_row(form.name) }} {{ form_row(form.domain) }} + {{ form_row(form.sectorIdentifierUri) }} {% if is_granted('ROLE_ORGANIZATIONS_VALIDATE') and organization is defined %} {{ form_row(form.validationUrl) }}
    diff --git a/src/LoginCidadao/OAuthBundle/Validator/Constraints/DomainOwnershipValidator.php b/src/LoginCidadao/OAuthBundle/Validator/Constraints/DomainOwnershipValidator.php index 069d0a798..f10265fa6 100644 --- a/src/LoginCidadao/OAuthBundle/Validator/Constraints/DomainOwnershipValidator.php +++ b/src/LoginCidadao/OAuthBundle/Validator/Constraints/DomainOwnershipValidator.php @@ -65,7 +65,7 @@ private function checkUrl($validationUrl, $domain, $validationCode) $response = false; } - if ($uri['query']) { + if (array_key_exists('query', $uri) && $uri['query']) { $this->buildUrlViolation('organizations.validation.error.query_string'); $response = false; } diff --git a/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifier.php b/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifier.php new file mode 100644 index 000000000..135181a08 --- /dev/null +++ b/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifier.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace LoginCidadao\OAuthBundle\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; + +/** + * @Annotation + * @Target("CLASS") + */ +class SectorIdentifier extends Constraint +{ + + public function validatedBy() + { + return get_class($this).'Validator'; + } + + public function getTargets() + { + return self::CLASS_CONSTRAINT; + } +} diff --git a/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifierValidator.php b/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifierValidator.php new file mode 100644 index 000000000..396437c7b --- /dev/null +++ b/src/LoginCidadao/OAuthBundle/Validator/Constraints/SectorIdentifierValidator.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace LoginCidadao\OAuthBundle\Validator\Constraints; + +use LoginCidadao\OAuthBundle\Entity\Organization; +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; + +class SectorIdentifierValidator extends ConstraintValidator +{ + + /** + * @param Organization $organization + * @param Constraint $constraint + */ + public function validate($organization, Constraint $constraint) + { + if (!$organization->getSectorIdentifierUri()) { + return; + } + + $sectorIdentifierUri = $organization->getSectorIdentifierUri(); + $domain = $organization->getDomain(); + + $uri = parse_url($sectorIdentifierUri); + + if ($uri['host'] !== $domain) { + $this->buildUrlViolation('organizations.validation.error.invalid_domain'); + } + } + + private function buildUrlViolation($message) + { + $this->context->buildViolation($message) + ->atPath('sectorIdentifierUri') + ->addViolation(); + } +} diff --git a/src/LoginCidadao/OpenIDBundle/Controller/AuthorizeController.php b/src/LoginCidadao/OpenIDBundle/Controller/AuthorizeController.php index 4d60616da..e75ac4077 100644 --- a/src/LoginCidadao/OpenIDBundle/Controller/AuthorizeController.php +++ b/src/LoginCidadao/OpenIDBundle/Controller/AuthorizeController.php @@ -3,6 +3,11 @@ namespace LoginCidadao\OpenIDBundle\Controller; use FOS\OAuthServerBundle\Event\OAuthEvent; +use LoginCidadao\OAuthBundle\Entity\Organization; +use LoginCidadao\OpenIDBundle\Entity\ClientMetadata; +use LoginCidadao\OpenIDBundle\Manager\ClientManager; +use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Component\HttpFoundation\Request; use OAuth2\ServerBundle\Controller\AuthorizeController as BaseController; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; @@ -20,8 +25,8 @@ class AuthorizeController extends BaseController */ public function handleAuthorizeAction() { - $request = $this->getRequest(); - $scope = $request->request->get('scope'); + $request = $this->getRequest(); + $scope = $request->request->get('scope'); $is_authorized = $request->request->has('rejected') === false || $request->request->has('accepted') === true; $request->request->set('scope', implode(' ', $scope)); @@ -41,9 +46,14 @@ public function handleAuthorizeAction() /** * @Template() */ - public function authorizeAction($client_id, $scope, $response_type, - $redirect_uri, $state = null, $nonce = null) - { + public function authorizeAction( + $client_id, + $scope, + $response_type, + $redirect_uri, + $state = null, + $nonce = null + ) { $client = $this->getClient($client_id); $scope = explode(' ', $scope); @@ -52,23 +62,27 @@ public function authorizeAction($client_id, $scope, $response_type, } $scopeManager = $this->getScopeManager(); - $scopes = array_map(function($value) { - return $value->getScope(); - }, $scopeManager->findScopesByScopes($scope)); + $scopes = array_map( + function ($value) { + return $value->getScope(); + }, + $scopeManager->findScopesByScopes($scope) + ); $warnUntrusted = $this->shouldWarnUntrusted($client); - - $qs = compact('client_id', 'scope', 'response_type', 'redirect_uri', - 'state', 'nonce'); - return compact('qs', 'scopes', 'client', 'warnUntrusted'); - } - - /** - * @return \OAuth2\ServerBundle\Manager\ScopeManager - */ - private function getScopeManager() - { - return $this->get('oauth2.scope_manager'); + $metadata = $this->getMetadata($client); + $organization = $this->getOrganization($metadata); + + $qs = compact( + 'client_id', + 'scope', + 'response_type', + 'redirect_uri', + 'state', + 'nonce' + ); + + return compact('qs', 'scopes', 'client', 'warnUntrusted', 'metadata', 'organization'); } /** @@ -79,7 +93,7 @@ private function getScopeManager() public function validateAuthorizeAction() { $request = $this->getRequest(); - $client = $this->getClient($request); + $client = $this->getClient($request); if ($client instanceof \FOS\OAuthServerBundle\Model\ClientInterface) { $event = $this->get('event_dispatcher')->dispatch( @@ -89,19 +103,32 @@ public function validateAuthorizeAction() $server = $this->get('oauth2.server'); if ($event->isAuthorizedClient()) { - return $this->handleAuthorize($server, - $event->isAuthorizedClient()); + return $this->handleAuthorize( + $server, + $event->isAuthorizedClient() + ); } } return parent::validateAuthorizeAction(); } + /** + * @return \OAuth2\ServerBundle\Manager\ScopeManager + */ + private function getScopeManager() + { + return $this->get('oauth2.scope_manager'); + } + private function handleAuthorize($server, $is_authorized) { - return $server->handleAuthorizeRequest($this->get('oauth2.request'), - $this->get('oauth2.response'), $is_authorized, - $this->getUser()->getId()); + return $server->handleAuthorizeRequest( + $this->get('oauth2.request'), + $this->get('oauth2.response'), + $is_authorized, + $this->getUser()->getId() + ); } private function getClient($fullId) @@ -110,27 +137,66 @@ private function getClient($fullId) $fullId = $fullId->get('client_id'); } - $id = explode('_', $fullId); - $er = $this->getDoctrine() - ->getRepository('LoginCidadaoOAuthBundle:Client'); + /** @var ClientManager $clientManager */ + $clientManager = $this->get('lc.client_manager'); - return $er->find($id[0]); + return $clientManager->getClientById($fullId); } private function shouldWarnUntrusted(ClientInterface $client) { - $authorizeUntrusted = $this->getParameter('warn_untrusted'); + $warnUntrusted = $this->getParameter('warn_untrusted'); + $metadata = $this->getMetadata($client); - if ($client->getOrganization() instanceof OrganizationInterface) { - $isTrusted = $client->getOrganization()->isTrusted(); + if ($metadata->getOrganization() instanceof OrganizationInterface) { + $isTrusted = $metadata->getOrganization()->isTrusted(); } else { $isTrusted = false; } - if ($isTrusted || $authorizeUntrusted) { + if ($isTrusted || !$warnUntrusted) { return false; // do not warn } return true; // warn } + + private function getMetadata(ClientInterface $client) + { + $repo = $this->getDoctrine()->getRepository('LoginCidadaoOpenIDBundle:ClientMetadata'); + + return $repo->findOneBy(['client' => $client]); + } + + private function getOrganization(ClientMetadata $metadata = null) + { + if ($metadata === null) { + return null; + } + + if ($metadata->getOrganization() === null && $metadata->getSectorIdentifierUri()) { + $sectorIdentifierUri = $metadata->getSectorIdentifierUri(); + $verified = $this->getSectorIdentifierUriChecker()->check($metadata, $sectorIdentifierUri); + $uri = parse_url($sectorIdentifierUri); + $domain = $uri['host']; + + $organization = new Organization(); + $organization->setDomain($domain) + ->setName($domain) + ->setTrusted(false) + ->setVerifiedAt($verified ? new \DateTime() : null); + + return $organization; + } + + return $metadata->getOrganization(); + } + + /** + * @return SectorIdentifierUriChecker + */ + private function getSectorIdentifierUriChecker() + { + return $this->get('checker.sector_identifier_uri'); + } } diff --git a/src/LoginCidadao/OpenIDBundle/Entity/ClientMetadata.php b/src/LoginCidadao/OpenIDBundle/Entity/ClientMetadata.php index b4177928d..171e51c30 100644 --- a/src/LoginCidadao/OpenIDBundle/Entity/ClientMetadata.php +++ b/src/LoginCidadao/OpenIDBundle/Entity/ClientMetadata.php @@ -10,8 +10,9 @@ namespace LoginCidadao\OpenIDBundle\Entity; +use LoginCidadao\OAuthBundle\Model\OrganizationInterface; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; -use LoginCidadao\OpenIDBundle\Constraints\SectorIdentifier; +use LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUri; use Symfony\Component\Validator\Constraints as Assert; use LoginCidadao\OAuthBundle\Entity\Client; use JMS\Serializer\Annotation as JMS; @@ -23,7 +24,7 @@ * @ORM\HasLifecycleCallbacks * @ORM\Table(name="client_metadata") * @JMS\ExclusionPolicy("all") - * @SectorIdentifier + * @SectorIdentifierUri */ class ClientMetadata { @@ -157,7 +158,7 @@ class ClientMetadata /** * @JMS\Expose * @JMS\Groups({"client_metadata"}) - * @Assert\Url(checkDNS = true) + * @Assert\Url(checkDNS = true, protocols = {"https"}) * @Assert\Type(type="string") * @ORM\Column(type="string", length=2000, nullable=true) */ @@ -310,6 +311,13 @@ class ClientMetadata */ protected $registration_access_token; + /** + * @var OrganizationInterface + * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients") + * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL") + */ + protected $organization; + public function __construct() { $this->response_types = array('code'); @@ -693,6 +701,13 @@ public function getClientId() return $this->client_id; } + public function setClientId($client_id) + { + $this->client_id = $client_id; + + return $this; + } + /** * @JMS\Groups({"client_metadata"}) * @JMS\VirtualProperty @@ -707,13 +722,6 @@ public function getClientSecret() return $this->client_secret; } - public function setClientId($client_id) - { - $this->client_id = $client_id; - - return $this; - } - public function setClientSecret($client_secret) { $this->client_secret = $client_secret; @@ -841,4 +849,20 @@ public function getRegistrationAccessToken() { return $this->registration_access_token; } + + /** + * @return OrganizationInterface + */ + public function getOrganization() + { + return $this->organization; + } + + /** + * @param OrganizationInterface $organization + */ + public function setOrganization($organization = null) + { + $this->organization = $organization; + } } diff --git a/src/LoginCidadao/OpenIDBundle/EventListenner/CoreEventsSubscriber.php b/src/LoginCidadao/OpenIDBundle/EventListenner/CoreEventsSubscriber.php new file mode 100644 index 000000000..b30a30258 --- /dev/null +++ b/src/LoginCidadao/OpenIDBundle/EventListenner/CoreEventsSubscriber.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace LoginCidadao\OpenIDBundle\EventListenner; + +use Doctrine\ORM\EntityManager; +use LoginCidadao\CoreBundle\Event\GetClientEvent; +use LoginCidadao\CoreBundle\Event\LoginCidadaoCoreEvents; +use LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +class CoreEventsSubscriber implements EventSubscriberInterface +{ + /** @var EntityManager */ + protected $em; + + /** @var SectorIdentifierUriChecker */ + protected $sectorIdentifierUriChecker; + + /** @var boolean */ + protected $revalidateSectorIdentifierUriOnAuth; + + /** + * CoreEventsListener constructor. + * @param EntityManager $em + * @param SectorIdentifierUriChecker $sectorIdentifierUriChecker + * @param boolean $revalidateSectorIdentifierUriOnAuth + */ + public function __construct( + EntityManager $em, + SectorIdentifierUriChecker $sectorIdentifierUriChecker, + $revalidateSectorIdentifierUriOnAuth + ) { + $this->em = $em; + $this->sectorIdentifierUriChecker = $sectorIdentifierUriChecker; + $this->revalidateSectorIdentifierUriOnAuth = $revalidateSectorIdentifierUriOnAuth; + } + + + public static function getSubscribedEvents() + { + return array( + LoginCidadaoCoreEvents::GET_CLIENT => array( + array('onGetClient', 10), + ), + ); + } + + public function onGetClient(GetClientEvent $event) + { + if ($this->revalidateSectorIdentifierUriOnAuth === false) { + return; + } + + $repo = $this->em->getRepository('LoginCidadaoOpenIDBundle:ClientMetadata'); + $metadata = $repo->findOneBy( + array( + 'client' => $event->getClient(), + ) + ); + $this->sectorIdentifierUriChecker->recheck($metadata); + } +} diff --git a/src/LoginCidadao/OpenIDBundle/Form/ClientMetadataWebForm.php b/src/LoginCidadao/OpenIDBundle/Form/ClientMetadataWebForm.php index cff8d2b00..6db723fb7 100644 --- a/src/LoginCidadao/OpenIDBundle/Form/ClientMetadataWebForm.php +++ b/src/LoginCidadao/OpenIDBundle/Form/ClientMetadataWebForm.php @@ -21,6 +21,7 @@ class ClientMetadataWebForm extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder + ->add('organization', 'text', array('disabled' => true)) ->add($builder->create('request_uris', 'Symfony\Component\Form\Extension\Core\Type\TextareaType', array('required' => false) diff --git a/src/LoginCidadao/OpenIDBundle/Manager/ClientManager.php b/src/LoginCidadao/OpenIDBundle/Manager/ClientManager.php index 261c6b277..4ea95bc09 100644 --- a/src/LoginCidadao/OpenIDBundle/Manager/ClientManager.php +++ b/src/LoginCidadao/OpenIDBundle/Manager/ClientManager.php @@ -11,26 +11,39 @@ namespace LoginCidadao\OpenIDBundle\Manager; use Doctrine\ORM\EntityManager; -use LoginCidadao\OAuthBundle\Model\AccessTokenManager; +use LoginCidadao\CoreBundle\Event\GetClientEvent; +use LoginCidadao\CoreBundle\Event\LoginCidadaoCoreEvents; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class ClientManager { + /** @var EventDispatcherInterface */ + protected $dispatcher; + /** @var EntityManager */ private $em; - /** @var AccessTokenManager */ - private $accessTokenManager; - - public function __construct(EntityManager $em, - AccessTokenManager $accessTokenManager) - { + public function __construct( + EntityManager $em, + EventDispatcherInterface $dispatcher + ) { $this->em = $em; - - $this->accessTokenManager = $accessTokenManager; + $this->dispatcher = $dispatcher; } - public function getClient() + public function getClientById($id) { - + if (strstr($id, '_') !== false) { + $parts = explode('_', $id); + $id = $parts[0]; + } + + $repo = $this->em->getRepository('LoginCidadaoOAuthBundle:Client'); + + $client = $repo->find($id); + $event = new GetClientEvent($client); + $this->dispatcher->dispatch(LoginCidadaoCoreEvents::GET_CLIENT, $event); + + return $event->getClient(); } } diff --git a/src/LoginCidadao/OpenIDBundle/Resources/config/services.yml b/src/LoginCidadao/OpenIDBundle/Resources/config/services.yml index d0a17bf8b..efcef4b52 100644 --- a/src/LoginCidadao/OpenIDBundle/Resources/config/services.yml +++ b/src/LoginCidadao/OpenIDBundle/Resources/config/services.yml @@ -1,4 +1,7 @@ parameters: + validator.sector_identifier_uri.class: LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUriValidator + checker.sector_identifier_uri.class: LoginCidadao\OpenIDBundle\Validator\SectorIdentifierUriChecker + oidc.person.serialize.listenner.class: LoginCidadao\OpenIDBundle\EventListenner\PersonSerializeEventListenner oidc.storage.session_state.class: LoginCidadao\OpenIDBundle\Storage\SessionState @@ -78,3 +81,38 @@ services: arguments: - "@oauth2.response_types.code" - "@oauth2.response_types.id_token" + + organization.repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - LoginCidadao\OAuthBundle\Entity\Organization + + checker.sector_identifier_uri: + arguments: + - "@doctrine.orm.entity_manager" + class: %checker.sector_identifier_uri.class% + + validator.sector_identifier_uri: + class: %validator.sector_identifier_uri.class% + arguments: + - "@organization.repository" + - "@checker.sector_identifier_uri" + tags: + - { name: validator.constraint_validator, alias: sector_identifier_uri } + + oidc.core.events_subscriber: + class: LoginCidadao\OpenIDBundle\EventListenner\CoreEventsSubscriber + arguments: + - "@doctrine.orm.entity_manager" + - "@checker.sector_identifier_uri" + - "%revalidate_sector_identifier_uri_on_auth%" + tags: + - { name: kernel.event_subscriber } + + lc.client_manager: + class: LoginCidadao\OpenIDBundle\Manager\ClientManager + arguments: + - "@doctrine.orm.entity_manager" + - "@event_dispatcher" + - "" diff --git a/src/LoginCidadao/OpenIDBundle/Resources/views/Authorize/form.html.twig b/src/LoginCidadao/OpenIDBundle/Resources/views/Authorize/form.html.twig index f71432012..005a85bd3 100644 --- a/src/LoginCidadao/OpenIDBundle/Resources/views/Authorize/form.html.twig +++ b/src/LoginCidadao/OpenIDBundle/Resources/views/Authorize/form.html.twig @@ -3,7 +3,7 @@ {% set not_verified %}{% endset %}
    {% if is_granted('FEATURE_ORGANIZATIONS') %} - {% if client.organization is empty or client.organization.isVerified is same as(false) %} + {% if organization is empty or organization.isVerified is same as(false) %} {% set status_label = not_verified %}