Skip to content
Snippets Groups Projects
Unverified Commit 939cd8c1 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

PSR2

parent 1ddf2b79
No related branches found
No related tags found
No related merge requests found
...@@ -24,134 +24,133 @@ namespace SimpleSAML\Module\expirycheck\Auth\Process; ...@@ -24,134 +24,133 @@ namespace SimpleSAML\Module\expirycheck\Auth\Process;
class ExpiryDate extends \SimpleSAML\Auth\ProcessingFilter class ExpiryDate extends \SimpleSAML\Auth\ProcessingFilter
{ {
private $warndaysbefore = 0; private $warndaysbefore = 0;
private $netid_attr = NULL; private $netid_attr = null;
private $expirydate_attr = NULL; private $expirydate_attr = null;
private $date_format = 'd.m.Y'; private $date_format = 'd.m.Y';
/** /**
* Initialize this filter. * Initialize this filter.
* *
* @param array $config Configuration information about this filter. * @param array $config Configuration information about this filter.
* @param mixed $reserved For future use. * @param mixed $reserved For future use.
*/ */
public function __construct($config, $reserved) { public function __construct($config, $reserved)
parent::__construct($config, $reserved); {
parent::__construct($config, $reserved);
assert(is_array($config));
assert(is_array($config));
if (array_key_exists('warndaysbefore', $config)) {
$this->warndaysbefore = $config['warndaysbefore']; if (array_key_exists('warndaysbefore', $config)) {
if (!is_string($this->warndaysbefore)) { $this->warndaysbefore = $config['warndaysbefore'];
throw new \Exception('Invalid value for number of days given to expirycheck::ExpiryDate filter.'); if (!is_string($this->warndaysbefore)) {
} throw new \Exception('Invalid value for number of days given to expirycheck::ExpiryDate filter.');
} }
}
if (array_key_exists('netid_attr', $config)) {
$this->netid_attr = $config['netid_attr']; if (array_key_exists('netid_attr', $config)) {
if (!is_string($this->netid_attr)) { $this->netid_attr = $config['netid_attr'];
throw new \Exception('Invalid attribute name given as eduPersonPrincipalName to expirycheck::ExpiryDate filter.'); if (!is_string($this->netid_attr)) {
} throw new \Exception('Invalid attribute name given as eduPersonPrincipalName to expirycheck::ExpiryDate filter.');
} }
}
if (array_key_exists('expirydate_attr', $config)) {
$this->expirydate_attr = $config['expirydate_attr']; if (array_key_exists('expirydate_attr', $config)) {
if (!is_string($this->expirydate_attr)) { $this->expirydate_attr = $config['expirydate_attr'];
throw new \Exception('Invalid attribute name given as schacExpiryDate to expirycheck::ExpiryDate filter.'); if (!is_string($this->expirydate_attr)) {
} throw new \Exception('Invalid attribute name given as schacExpiryDate to expirycheck::ExpiryDate filter.');
} }
}
if (array_key_exists('date_format', $config)) {
$this->date_format = $config['date_format']; if (array_key_exists('date_format', $config)) {
if (!is_string($this->date_format)) { $this->date_format = $config['date_format'];
throw new \Exception('Invalid date format given to expirycheck::ExpiryDate filter.'); if (!is_string($this->date_format)) {
} throw new \Exception('Invalid date format given to expirycheck::ExpiryDate filter.');
} }
} }
}
/**
* Show expirational warning if remaining days is equal or under defined $warndaysbefore /**
* @param integer $expireOnDate * Show expirational warning if remaining days is equal or under defined $warndaysbefore
* @param integer $warndaysbefore * @param integer $expireOnDate
* @return bool * @param integer $warndaysbefore
* * @return bool
*/ *
public function shWarning(&$state, $expireOnDate, $warndaysbefore) { */
$now = time(); public function shWarning(&$state, $expireOnDate, $warndaysbefore)
$end = $expireOnDate; {
$now = time();
if ($expireOnDate >= $now) { $end = $expireOnDate;
$days = (int)(($end - $now) / (24*60*60));
if ($days <= $warndaysbefore) { if ($expireOnDate >= $now) {
$state['daysleft'] = $days; $days = (int)(($end - $now) / (24*60*60));
return true; if ($days <= $warndaysbefore) {
} $state['daysleft'] = $days;
} return true;
return false; }
} }
return false;
/** }
* Check if given date is older than today
* @param integer $expireOnDate /**
* @return bool * Check if given date is older than today
* * @param integer $expireOnDate
*/ * @return bool
public function checkDate($expireOnDate) { *
$now = time(); */
$end = $expireOnDate; public function checkDate($expireOnDate)
{
if ($now <= $end) { $now = time();
return true; $end = $expireOnDate;
} else {
return false; if ($now <= $end) {
} return true;
} else {
} return false;
}
/** }
* Apply filter
* /**
* @param array &$state The current state. * Apply filter
*/ *
public function process(&$state) { * @param array &$state The current state.
/* */
* UTC format: 20090527080352Z public function process(&$state)
*/ {
$netId = $state['Attributes'][$this->netid_attr][0]; /*
$expireOnDate = strtotime($state['Attributes'][$this->expirydate_attr][0]); * UTC format: 20090527080352Z
*/
if (self::shWarning($state, $expireOnDate, $this->warndaysbefore)) { $netId = $state['Attributes'][$this->netid_attr][0];
assert(is_array($state)); $expireOnDate = strtotime($state['Attributes'][$this->expirydate_attr][0]);
if (isset($state['isPassive']) && $state['isPassive'] === TRUE) {
// We have a passive request. Skip the warning. if ($this->shWarning($state, $expireOnDate, $this->warndaysbefore)) {
return; assert(is_array($state));
} if (isset($state['isPassive']) && $state['isPassive'] === true) {
// We have a passive request. Skip the warning.
\SimpleSAML\Logger::warning('expirycheck: NetID ' . $netId . return;
' is about to expire!'); }
// Save state and redirect \SimpleSAML\Logger::warning('expirycheck: NetID '.$netId.' is about to expire!');
$state['expireOnDate'] = date($this->date_format, $expireOnDate);
$state['netId'] = $netId; // Save state and redirect
$id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:about2expire'); $state['expireOnDate'] = date($this->date_format, $expireOnDate);
$url = \SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php'); $state['netId'] = $netId;
\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id)); $id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:about2expire');
} $url = \SimpleSAML\Module::getModuleURL('expirycheck/about2expire.php');
\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
if (!self::checkDate($expireOnDate)) { }
\SimpleSAML\Logger::error('expirycheck: NetID ' . $netId .
' has expired [' . date($this->date_format, $expireOnDate) . ']. Access denied!'); if (!$this->checkDate($expireOnDate)) {
\SimpleSAML\Logger::error('expirycheck: NetID '.$netId.
/* Save state and redirect. */ ' has expired ['.date($this->date_format, $expireOnDate).']. Access denied!');
$state['expireOnDate'] = date($this->date_format, $expireOnDate);
$state['netId'] = $netId; /* Save state and redirect. */
$id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:expired'); $state['expireOnDate'] = date($this->date_format, $expireOnDate);
$url = \SimpleSAML\Module::getModuleURL('expirycheck/expired.php'); $state['netId'] = $netId;
\SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id)); $id = \SimpleSAML\Auth\State::saveState($state, 'expirywarning:expired');
$url = \SimpleSAML\Module::getModuleURL('expirycheck/expired.php');
} \SimpleSAML\Utils\HTTP::redirectTrustedURL($url, array('StateId' => $id));
} }
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment