Skip to content

Commit

Permalink
fix problems iwth firewall with dash symbol and validate webspace in …
Browse files Browse the repository at this point in the history
…community admin
  • Loading branch information
alexander-schranz committed Mar 7, 2018
1 parent 5e4d4a8 commit 3b9966b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
30 changes: 28 additions & 2 deletions Admin/CommunityAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,35 @@ public function getSecurityContexts()
{
$systems = [];

$webspaceCollection = $this->webspaceManager->getWebspaceCollection();

$webspaceKeys = array_keys($webspaceCollection->getWebspaces());

foreach ($this->webspacesConfiguration as $webspaceKey => $webspaceConfig) {
$webspace = $this->webspaceManager->getWebspaceCollection()->getWebspace($webspaceKey);
$system = $webspace->getSecurity()->getSystem();
$webspace = $webspaceCollection->getWebspace($webspaceKey);

if (!$webspace) {
throw new \InvalidArgumentException(
sprintf(
'Webspace "%s" not found for "sulu_community" expected one of %s.',
$webspaceKey,
'"' . implode('", "', $webspaceKeys) . '"'
)
);
}

$security = $webspace->getSecurity();

if (!$security) {
throw new \InvalidArgumentException(
sprintf(
'Missing "<security><system>Website</system><security>" configuration in webspace "%s" for "sulu_community".',
$webspaceKey
)
);
}

$system = $security->getSystem();
$systems[$system] = [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ private function updateWebspaceConfig($webspaceKey, array $webspaceConfig)
$webspaceConfig[Configuration::FIREWALL] = $webspaceKey;
}

// TODO currently symfony normalize the security firewalls key which will replace "-" with "_".
$webspaceConfig[Configuration::FIREWALL] = str_replace('-', '_', $webspaceConfig[Configuration::FIREWALL]);

// Set role by webspace key
if (null === $webspaceConfig[Configuration::ROLE]) {
$webspaceConfig[Configuration::ROLE] = ucfirst($webspaceKey) . 'User';
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Listener/BlacklistListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testValidateEmail()
$user->getEmail()->willReturn('[email protected]');

$event = $this->prophesize(CommunityEvent::class);
$event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu_io');
$event->getConfigProperty(Configuration::WEBSPACE_KEY)->willReturn('sulu-io');
$event->getConfigProperty(Configuration::EMAIL_TO)->willReturn(['[email protected]' => '[email protected]']);
$event->getConfigProperty(Configuration::EMAIL_FROM)->willReturn(['[email protected]' => '[email protected]']);
$event->getConfigTypeProperty(Configuration::TYPE_BLACKLISTED, Configuration::EMAIL)->willReturn(
Expand All @@ -92,7 +92,7 @@ public function testValidateEmail()
Argument::that(
function (BlacklistUser $item) use ($user) {
return '123-123-123' === $item->getToken()
&& 'sulu_io' === $item->getWebspaceKey()
&& 'sulu-io' === $item->getWebspaceKey()
&& $item->getUser() === $user->reveal();
}
)
Expand Down
2 changes: 1 addition & 1 deletion Tests/app/Resources/webspaces/sulu.io.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd">

<name>Sulu CMF</name>
<key>sulu_io</key>
<key>sulu-io</key>

<localizations>
<localization language="de" default="true"/>
Expand Down
2 changes: 1 addition & 1 deletion Tests/app/config/config_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ framework:

sulu_community:
webspaces:
sulu_io:
sulu-io:
to: '[email protected]'

sulu_security:
Expand Down

0 comments on commit 3b9966b

Please sign in to comment.