55namespace SimpleSAML \Module \proxystatistics ;
66
77use SimpleSAML \Configuration ;
8+ use SimpleSAML \Error \Exception ;
89
910class Config
1011{
@@ -34,6 +35,12 @@ class Config
3435
3536 private const KEEP_PER_USER = 'keepPerUser ' ;
3637
38+ private const API_WRITE_ENABLED = 'apiWriteEnabled ' ;
39+
40+ private const API_WRITE_USERNAME = 'apiWriteUsername ' ;
41+
42+ private const API_WRITE_PASSWORD_HASH = 'apiWritePasswordHash ' ;
43+
3744 private $ config ;
3845
3946 private $ store ;
@@ -50,6 +57,12 @@ class Config
5057
5158 private $ idAttribute ;
5259
60+ private $ apiWriteEnabled ;
61+
62+ private $ apiWriteUsername ;
63+
64+ private $ apiWritePasswordHash ;
65+
5366 private static $ instance ;
5467
5568 private function __construct ()
@@ -62,6 +75,17 @@ private function __construct()
6275 $ this ->keepPerUser = $ this ->config ->getIntegerRange (self ::KEEP_PER_USER , 31 , 1827 , 31 );
6376 $ this ->requiredAuthSource = $ this ->config ->getString (self ::REQUIRE_AUTH_SOURCE , '' );
6477 $ this ->idAttribute = $ this ->config ->getString (self ::USER_ID_ATTRIBUTE , 'uid ' );
78+ $ this ->apiWriteEnabled = $ this ->config ->getBoolean (self ::API_WRITE_ENABLED , false );
79+ if ($ this ->apiWriteEnabled ) {
80+ $ this ->apiWriteUsername = $ this ->config ->getString (self ::API_WRITE_USERNAME );
81+ if (empty (trim ($ this ->apiWriteUsername ))) {
82+ throw new Exception ('Username for API write cannot be empty ' );
83+ }
84+ $ this ->apiWritePasswordHash = $ this ->config ->getString (self ::API_WRITE_PASSWORD_HASH );
85+ if (empty (trim ($ this ->apiWritePasswordHash ))) {
86+ throw new Exception ('Password for API write cannot be empty ' );
87+ }
88+ }
6589 }
6690
6791 private function __clone ()
@@ -123,4 +147,19 @@ public function getKeepPerUser()
123147 {
124148 return $ this ->keepPerUser ;
125149 }
150+
151+ public function isApiWriteEnabled ()
152+ {
153+ return $ this ->apiWriteEnabled ;
154+ }
155+
156+ public function getApiWriteUsername ()
157+ {
158+ return $ this ->apiWriteUsername ;
159+ }
160+
161+ public function getApiWritePasswordHash ()
162+ {
163+ return $ this ->apiWritePasswordHash ;
164+ }
126165}
0 commit comments