Przeglądaj źródła

Authenticator: added getClientCertSubjectDistinguishedName()

Fabian Peter Hammerle 8 lat temu
rodzic
commit
a4251c4324
2 zmienionych plików z 23 dodań i 1 usunięć
  1. 15 1
      Authenticator.php
  2. 8 0
      tests/AuthenticatorTest.php

+ 15 - 1
Authenticator.php

@@ -41,6 +41,18 @@ class Authenticator extends \yii\base\Component
             && $_SERVER['SSL_CLIENT_VERIFY'] == 'SUCCESS';
     }
 
+    /**
+     * @return string|null
+     */
+    public function getClientCertSubjectDistinguishedName()
+    {
+        if(isset($_SERVER['SSL_CLIENT_S_DN'])) {
+            return $_SERVER['SSL_CLIENT_S_DN'];
+        } else {
+            return null;
+        }
+    }
+
     /**
      * @return IdentityInterface|null
      */
@@ -48,7 +60,9 @@ class Authenticator extends \yii\base\Component
     {
         if($this->getClientCertVerified()) {
             // Subject DN in client certificate
-            return $this->loginByDistinguishedName($_SERVER["SSL_CLIENT_S_DN"]);
+            return $this->loginByDistinguishedName(
+                $this->getClientCertSubjectDistinguishedName()
+            );
         } else {
             return null;
         }

+ 8 - 0
tests/AuthenticatorTest.php

@@ -72,6 +72,14 @@ class AuthenticatorTest extends TestCase
         ];
     }
 
+    public function testGetClientCertSubjectDistinguishedName()
+    {
+        $a = new Authenticator;
+        $_SERVER['SSL_CLIENT_S_DN'] = 'CN=Alice,C=AT';
+        $this->assertEquals('CN=Alice,C=AT', $a->getClientCertSubjectDistinguishedName());
+        $this->assertEquals('CN=Alice,C=AT', $a->clientCertSubjectDistinguishedName);
+    }
+
     /**
      * @dataProvider loginByClientCertProvider
      */