requires 'Text::Tradition::StemmaUtil';
# Catalyst libraries
requires 'Catalyst::Runtime' => '5.90002';
+requires 'Catalyst::Plugin::Cache';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::StackTrace';
requires 'Catalyst::Plugin::Static::Simple';
requires 'namespace::autoclean';
requires 'Config::General'; # This should reflect the config file format you've chosen
# See Catalyst::Plugin::ConfigLoader for supported formats
+requires 'Cache::FileCache';
test_requires 'Test::More' => '0.88';
test_requires 'LWP::Protocol::PSGI';
test_requires 'Test::WWW::Mechanize';
Session::State::Cookie
StatusMessage
StackTrace
+ Cache
/;
extends 'Catalyst';
+use Cache::FileCache;
use stemmaweb::Authentication::FormHandler;
our $VERSION = '0.01';
stemmaweb->path_to( 'root', 'src' ),
],
},
+
+ 'Plugin::Cache' => {
+ backend => {
+ class => 'Cache::FileCache',
+ namespace => 'cache',
+ default_expires_in => 86400,
+ },
+ },
+
## kiokudb auth store testing
'Plugin::Authentication' => {
default => {
sub retrieve_certs {
my ($self, $url) = @_;
- $url ||= ( $self->{_app}->config->{'Authentication::Credential::Google'}->{public_cert_url} || 'https://www.googleapis.com/oauth2/v1/certs' );
- return decode_json(get($url));
+ my $c = $self->{_app};
+ my $cached = 0;
+ my $certs;
+ my $cache;
+
+ $url ||= ( $c->config->{'Authentication::Credential::Google'}->{public_cert_url} || 'https://www.googleapis.com/oauth2/v1/certs' );
+
+ if ( ($c->registered_plugins('Catalyst::Plugin::Cache')) && ($cache = $c->cache) ) {
+ if ($certs = $cache->get('certs')) {
+ $certs = decode_json($certs);
+
+ foreach my $key (keys %$certs) {
+ my $cert = $certs->{$key};
+ my $x509 = Crypt::OpenSSL::X509->new_from_string($cert);
+
+ if ($self->is_cert_expired($x509)) {
+ $cached = 0;
+ last;
+ } else {
+ $cached = 1;
+ }
+ }
+ }
+ }
+
+ if (!$cached) {
+ my $certs_encoded = get($url);
+
+ if ($cache) {
+ $cache->set('certs', $certs_encoded);
+ }
+
+ $certs = decode_json($certs_encoded);
+ }
+
+ return $certs;
}
=head2 get_key_from_cert