diff Lib/Engine/Security.pm @ 0:03e58a454b20

Создан репозитарий
author Sergey
date Tue, 14 Jul 2009 12:54:37 +0400
parents
children 16ada169ca75
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/Engine/Security.pm	Tue Jul 14 12:54:37 2009 +0400
@@ -0,0 +1,36 @@
+use strict;
+package Engine::Security;
+use Security::Auth;
+use Security;
+use Engine::Security::Auth;
+
+our @AuthMethods;
+my $AuthResult;
+my $AuthMod;
+my $AuthMethod;
+
+# use last auth method as default
+$AuthMethod = Engine::Security::Auth->new(%{$AuthMethods[$#AuthMethods]}) if @AuthMethods;
+
+sub AuthenticateContext {
+    Security->CurrentSession(undef); #prevent previous session from closing
+    foreach my $method (@AuthMethods) {
+        my $AuthObj = Engine::Security::Auth->new(%$method);
+        $AuthResult = $AuthObj->DoAuth();
+        # îáíîâèòü òåêóùèé êîíòåêñò áåçîïàñíîñòè, òîëüêî åñëè ýòî íåîáõîäèìî
+        $AuthObj->SetAuthResult($AuthResult) if $AuthResult->State == Security::AUTH_FAILED or $AuthResult->State == Security::AUTH_SUCCESS;
+        $AuthMethod = $AuthObj and last if $AuthResult->State != Security::AUTH_FAILED and $AuthResult->State != Security::AUTH_NOAUTH;
+    }
+    $AuthMod = $AuthMethod->AuthMod if $AuthMethod;
+}
+
+sub SetAuthResult {
+    shift;
+    $AuthMethod->SetAuthResult(@_) if $AuthMethod;
+}
+
+sub AuthMod {
+    return $AuthMethod ? $AuthMethod->AuthMod : undef;
+}
+
+1;
\ No newline at end of file