Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Issue #15: Remove hard-coded Dutch labels
Browse files Browse the repository at this point in the history
- Controller\GuardStatsController replaced label values by translation keys
    replaced options and their lookup by methods and calls
    ::addStatsPeriodForm now passes datetype and datetime pattern to formtype
    ::translateRelativeDate adapted
    ::initDateFormatAndPattern, ::initDateTimeTransformer now use configuration parameter and support locale-dependent date formatting
- Form\Type\StatsPeriodType now expects and uses datetype and datetime pattern
- Resources/translations/metaclass_auth_guard.nl.yml added with Dutch translations
- Resources/translations/metaclass_auth_guard.en.yml added with English translations
- Resources/views/Guard/statistics_content.html.twig added trans calls
- DependencyInjection\Configuration::getConfigTreeBuilder added ui.dateTimeFormat
- DependencyInjection\MetaclassAuthenticationGuardExtension::load now sets param:
      metaclass_auth_guard.ui.dateTimeFormat
- Readme.md restored the Web based user interface feature
- Resources/doc/Installation.md added doc on:
  - Bundle parameter metaclass_auth_guard.ui.dateTimeFormat
  - services parameter metaclass_auth_guard.statistics.StatsPeriod.formType
  - Available translations (&clone me on Github)

Issue #17: Default configuration set without adding to config.yml
- DependencyInjection\Configuration::getConfigTreeBuilder added ->addDefaultsIfNotSet() to each arraynode

Make web based user interface more extendable:
- Resources/config/services.yml added parameters metaclass_auth_guard.statistics.StatsPeriod.formType
- Controller\GuardStatsController::addStatsPeriodForm now uses parameter metaclass_auth_guard.statistics.StatsPeriod.formType
    ::initDateFormatAndPattern may be overridden for setting locale dependent (custom) patterns
  • Loading branch information
metaclass-nl committed Dec 23, 2015
1 parent 726865c commit b2bb71c
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 101 deletions.
204 changes: 129 additions & 75 deletions Controller/GuardStatsController.php

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ public function getConfigTreeBuilder()
$rootNode = $treeBuilder->root('metaclass_authentication_guard');

$rootNode
->addDefaultsIfNotSet()
->children()
->arrayNode('db_connection')
->addDefaultsIfNotSet()
->children()
->scalarNode('name')->defaultValue('default')->end()
->end()
->end()
->arrayNode('ui')
->addDefaultsIfNotSet()
->children()
->scalarNode('dateTimeFormat')->defaultValue('SHORT')->end()
->end()
->end()
->arrayNode('tresholds_governor_params')
->addDefaultsIfNotSet()
->children()
->scalarNode('counterDurationInSeconds')->defaultValue(180)->end()
->scalarNode('blockUsernamesFor')->defaultValue('25 minutes')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('metaclass_auth_guard.db_connection.name', $config['db_connection']['name']);
$container->setParameter('metaclass_auth_guard.ui.dateTimeFormat', $config['ui']['dateTimeFormat']);
$container->setParameter('metaclass_auth_guard.tresholds_governor_params', $config['tresholds_governor_params']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down
11 changes: 7 additions & 4 deletions Form/Type/StatsPeriodType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class StatsPeriodType extends AbstractType
{
protected $labels;

public function __construct($labels, \DateTime $min, $dateTimeFormat)
public function __construct($labels, \DateTime $min, $dateFormat, $formatPattern)
{
$this->labels = $labels;
$this->min = $min;
$this->dateTimeFormat = $dateTimeFormat;
$this->dateFormat = $dateFormat;
$this->formatPattern = $formatPattern;
}

public function buildForm(FormBuilderInterface $builder, array $options)
Expand All @@ -27,14 +28,16 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => $this->labels['From'],
'required' => true,
'widget' => 'single_text',
'format' => $this->dateTimeFormat,
'date_format' => $this->dateFormat,
'format' => $this->formatPattern,
'constraints' => $constraints
));
$builder->add('Until', 'datetime', array(
'label' => $this->labels['Until'],
'required' => false,
'widget' => 'single_text',
'format' => $this->dateTimeFormat,
'date_format' => $this->dateFormat,
'format' => $this->formatPattern,
'constraints' => $constraints
));
}
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ FEATURES

- Stores counters instead of individual requests to prevent database flooding from brute force attacks,

- Web based user interface for user administrators to look into why a user may have been blocked.

REQUIREMENTS
------------
This bundle is for the symfony framework and requires Symfony >=2.3 and <=2.6.*
This is for the symfony framework and this version requires Symfony >=2.3 and <=2.6.*.
Another version will support Symfony >=2.6.
Requires metaclass-nl/tresholds-governor 0.2@dev which uses Doctrine DBAL >=2.3
Tested with MySQL 5.5.

Expand All @@ -43,13 +46,16 @@ login form to hide differences between them that should not be reported to users

May be vurnerable to enumeration of usernames through timing attacks because of
differences in database query performance for frequently and infrequently used usernames.
This can be mitigated by calling ::sleepUntilFixedExecutionTime. Under normal circomstances
This is mitigated by sleeping until a fixed execution time is reached. Under normal circomstances
that should be sufficient if the fixedExecutionSeconds is set long enough, but under
high (database) server loads when performance degrades, under specific conditions
information may still be extractable by timing. Furthermore, the measures against
timing attacks where not tested for practical effectiveness.

The web based administration user interface is experimental and requires doctrine/doctrine-bundle.
The web based administration user interface is experimental, requires doctrine/doctrine-bundle
and is currenly only in English and Dutch (Please clone me on Github and add your own language translation!).

0.3.* versions are tested with Symfony 2.3 and 2.6.

DOCUMENTATION
-------------
Expand Down
3 changes: 2 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ parameters:
metaclass_auth_guard.manager.class: "Metaclass\TresholdsGovernor\Manager\RdbManager"
metaclass_auth_guard.gateway.class: "Metaclass\TresholdsGovernor\Gateway\DbalGateway"
metaclass_auth_guard.tresholds_governor.class: "Metaclass\TresholdsGovernor\Service\TresholdsGovernor"
metaclass_auth_guard.authentication.listener.form.class: Metaclass\AuthenticationGuardBundle\Service\UsernamePasswordFormAuthenticationGuard
metaclass_auth_guard.authentication.listener.form.class: "Metaclass\AuthenticationGuardBundle\Service\UsernamePasswordFormAuthenticationGuard"
metaclass_auth_guard.statistics.StatsPeriod.formType: "Metaclass\AuthenticationGuardBundle\Form\Type\StatsPeriodType"
metaclass_auth_guard.statistics.template: "MetaclassAuthenticationGuardBundle:Guard:statistics.html.twig"

services:
Expand Down
28 changes: 27 additions & 1 deletion Resources/doc/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Installation
- [setAuthExecutionSeconds, [0.99]] # voluntary
```

7. You also need to add the following configuraton parameters (defaults shown):
7. You may also add the following configuraton parameters (defaults shown):

```yml
metaclass_authentication_guard:
Expand All @@ -93,6 +93,8 @@ Installation
keepCountsFor: "4 days"
fixedExecutionSeconds: "0.1"
randomSleepingNanosecondsMax: 99999
ui:
dateTimeFormat: "SHORT"
```

8. From cron or so you may garbage-collect/pack stored RequestCounts:
Expand Down Expand Up @@ -146,6 +148,12 @@ Installation
in your applications routing.yml after the metaclass_auth_guard resource configuration
or replace the resource configuration entirely.
If you want to use other datetime widgets you may override the parameter
metaclass_auth_guard.statistics.StatsPeriod.formType to refer to a class of your own.
Currently the web based user interface only supports English and Dutch.
Please clone the Bundle on Github and add your own language translation!
10. If you want to run the tests you may add the following to the testsuites section of your app/phpunit.xml:
```xml
<testsuite name="MetaclassAUthenticationGuardBundle Test Suite">
Expand Down Expand Up @@ -281,6 +289,24 @@ Configurations
details a random between 0 and this value is added by ::sleepUntilSinceInit (which
is called by ::sleepUntilFixedExecutionTime).

12.
ui:
dateTimeFormat

\IntlDateFormatter pattern or datetype. If a dattype is set
(FULL, LONG, MEDIUM or SHORT) (case independent) the corresponding
dateformat is used and no pattern so that the formatting will depend
on the locale. Otherwise the parameter is used as pattern with
\Symfony\Component\Form\Extension\Core\Type\DateTimeType::DEFAULT_DATE_FORMAT
as datetype. As timetype DateTimeType::DEFAULT_TIME_FORMAT allways used so that
the formatting is the same as done by the DateTimeType widgets in the Period form.

If you need specific patterns for different locales you may use your own subclass
of GuardStatsController and override ::initDateFormatAndPattern to set the appropriate
datetype and format, or override ::initDateTimeTransformer to set whatever
transformer you may like (but that will not be used by the DateTimeType widgets in the
Period form so you may want to set your own form type too).

Notes

- releasing is possible for a username in general, an IP address in general, or for the combination of a username with an ip address
Expand Down
38 changes: 28 additions & 10 deletions Resources/doc/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,35 @@ created branche 0_3
(branche 0_3)
- Corrected README.md (Requirements)
- composer.json now requires symfony >=2.3.8,<=2.6.*
committed, pushed
------------------------------------------------
(branche 0_3)
Issue #15: Remove hard-coded Dutch labels
- Controller\GuardStatsController replaced label values by translation keys
replaced options and their lookup by methods and calls
::addStatsPeriodForm now passes datetype and datetime pattern to formtype
::translateRelativeDate adapted
::initDateFormatAndPattern, ::initDateTimeTransformer now use configuration parameter and support locale-dependent date formatting
- Form\Type\StatsPeriodType now expects and uses datetype and datetime pattern
- Resources/translations/metaclass_auth_guard.nl.yml added with Dutch translations
- Resources/translations/metaclass_auth_guard.en.yml added with English translations
- Resources/views/Guard/statistics_content.html.twig added trans calls
- DependencyInjection\Configuration::getConfigTreeBuilder added ui.dateTimeFormat
- DependencyInjection\MetaclassAuthenticationGuardExtension::load now sets param:
metaclass_auth_guard.ui.dateTimeFormat
- Readme.md restored the Web based user interface feature
- Resources/doc/Installation.md added doc on:
- Bundle parameter metaclass_auth_guard.ui.dateTimeFormat
- services parameter metaclass_auth_guard.statistics.StatsPeriod.formType
- Available translations (&clone me on Github)

Issue #17: Default configuration set without adding to config.yml
- DependencyInjection\Configuration::getConfigTreeBuilder added ->addDefaultsIfNotSet() to each arraynode

2DO:
ArboSDW verbeteren:
- normale hyperlinks onderscheiden, maar hyperlinks in menu grijs houden
Make web based user interface more extendable:
- Resources/config/services.yml added parameters metaclass_auth_guard.statistics.StatsPeriod.formType
- Controller\GuardStatsController::addStatsPeriodForm now uses parameter metaclass_auth_guard.statistics.StatsPeriod.formType
::initDateFormatAndPattern may be overridden for setting locale dependent (custom) patterns

- tanslation
----------------------------------------------------

- solve problem with params if not defined:
metaclass_authentication_guard:
db_connection:
name: ""
tresholds_governor_params:
counterDurationInSeconds: 300
55 changes: 55 additions & 0 deletions Resources/translations/metaclass_auth_guard.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
statistics:
title: Authentication Guard

history:
title: Authentication history
show: Show authentication history

statisticsByUserName:
isUsernameBlocked: Username blocked

tresholds_governor_params:
countingSince: Counting since
blockUsernamesFor: Block usernames for
blockIpAddressesFor: Block IP addresses for
allowReleasedUserOnAddressFor: Release user on address for
limitPerUserName: Maximum per username
limitBasePerIpAddress: Maximum per IP adress

secu_requests:
username: Username
loginsFailed: Failed logins
loginsSucceeded: Successfull logins
col:
dtFrom: From
username: Username
ipAddress: Address
loginsSucceeded: Succeeded
loginsFailed: Failed
ipAddressBlocked: address
usernameBlocked: name
usernameBlockedForIpAddress: name on addresd
usernameBlockedForCookie: name on cookie
blockedColumns: Number of attepmts blocked for

countsGroupedByIpAddress:
col:
blocked: Blocked
usernames: Names

StatsPeriod:
From: From
Until: Until
history: History
statistics: IP Adresses
submit: Show

relativeDate:
minutes: minutes
hours: hours
days: days

boolean:
0: Yes
1: No

55 changes: 55 additions & 0 deletions Resources/translations/metaclass_auth_guard.nl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
statistics:
title: Inlogbeveiliging

history:
title: Inloghistorie
show: Toon inloghistorie

statisticsByUserName:
isUsernameBlocked: Gebruikersnaam geblokkeerd

tresholds_governor_params:
countingSince: Telt sinds
blockUsernamesFor: Blokkeeer gebruikersnamen voor
blockIpAddressesFor: Blokkeeer IP adressen voor
allowReleasedUserOnAddressFor: Gebruikersnaam op adres vrijgeven voor
limitPerUserName: Maximum per gebruikersnaam
limitBasePerIpAddress: Maximum per Adres

secu_requests:
username: Gebruikersnaam
loginsFailed: Mislukte inlogpogingen
loginsSucceeded: Succesvolle inlogpogingen
col:
dtFrom: Vanaf
username: Naam
ipAddress: Adres
loginsSucceeded: Succesvol
loginsFailed: Mislukt
ipAddressBlocked: adres
usernameBlocked: naam
usernameBlockedForIpAddress: naam op adres
usernameBlockedForCookie: naam op cookie
blockedColumns: Aantal pogingen geblokkeerd op

countsGroupedByIpAddress:
col:
blocked: Blok
usernames: Namen

StatsPeriod:
From: Van
Until: Tot
history: Historie
statistics: IP Adressen
submit: Tonen

relativeDate:
minutes: minuten
hours: uren
days: dagen

boolean:
0: Nee
1: Ja

14 changes: 7 additions & 7 deletions Resources/views/Guard/statistics_content.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<fieldset class="editform-fieldset" for="GuardStats_show">
{% for label, field in fieldSpec %}
<div class="form-group" for="{{ field }}">
<label for="GuardStats_{{ field }}">{{ label }}</label>
<label for="GuardStats_{{ field }}">{{ label|trans({}, 'metaclass_auth_guard') }}</label>
<div class="form-value">
{{ fieldValues[field] }}
</div>
Expand All @@ -16,7 +16,7 @@
{% if form is defined %}
<form id="{{ form.vars.name }}" class="form-inline" role="form" action="{{ path(routes.this, action_params) }}" method="post" {{ form_enctype(form) }}>
<fieldset class="editform-fieldset" for="GuardStats_period">
<legend class="fieldset-legend">{{ form.vars.label }}</legend>
<legend class="fieldset-legend">{{ form.vars.label|trans({}, 'metaclass_auth_guard') }}</legend>
<div class="form-group">
{% for eachError in form.vars.errors %}
<div class="form-error">{{ eachError.message }}</div>
Expand All @@ -26,7 +26,7 @@
{{ include("MetaclassAuthenticationGuardBundle:Entity:editrow.html.twig") }}
{% endfor %}

<input type="submit" class="btn btn-default" value="Show"/>
<input type="submit" class="btn btn-default" value="{{ 'StatsPeriod.submit'|trans({}, 'metaclass_auth_guard') }}"/>
</fieldset>
</form>
{% endif %}
Expand All @@ -36,11 +36,11 @@
<thead>
<tr>
<th colspan="{{ blockedHeaderIndent }}">&nbsp;</th>
<th colspan="4">Aantal pogingen geblokkeerd op</th>
<th colspan="4"> {{ 'secu_requests.blockedColumns'|trans({}, 'metaclass_auth_guard') }}</th>
</tr>
<tr>
{% for label, key in columnSpec %}
<th>{{ label }}</th>
<th>{{ label|trans({}, 'metaclass_auth_guard') }}</th>
{% endfor %}
</tr>
</thead>
Expand All @@ -49,10 +49,10 @@
<tr>
{% for label, key in columnSpec %}
<td>{% if (key == 'ipAddress' and route_history is defined) %}
<a title="{{ labels.show }}" href="{{ path(route_history, {'ipAddress': entity.ipAddress, 'StatsPeriod[From]': limits.From, 'StatsPeriod[Until]': limits.Until }) }}">
<a title="{{ labels.show|trans({}, 'metaclass_auth_guard') }}" href="{{ path(route_history, {'ipAddress': entity.ipAddress, 'StatsPeriod[From]': limits.From, 'StatsPeriod[Until]': limits.Until }) }}">
{{ entity[key] }}</a>
{% elseif (key == 'username' and route_byUsername is defined) %}
<a title="{{ labels.show }}" href="{{ path(route_byUsername, {'username': entity.username, 'StatsPeriod[From]': limits.From, 'StatsPeriod[Until]': limits.Until }) }}">
<a title="{{ labels.show|trans({}, 'metaclass_auth_guard') }}" href="{{ path(route_byUsername, {'username': entity.username, 'StatsPeriod[From]': limits.From, 'StatsPeriod[Until]': limits.Until }) }}">
{{ entity[key] }}</a>
{% else %}
{{ entity[key] }}
Expand Down

0 comments on commit b2bb71c

Please sign in to comment.