@@ -27,6 +27,7 @@ class PluginSession extends SSOData
2727{
2828 const QUERY_PARAM_JWT = 'jwt ' ;
2929 const QUERY_PARAM_PID = 'pid ' ;
30+ const QUERY_PARAM_SID = 'sessionID ' ;
3031 const QUERY_PARAM_USERVIEW = 'userView ' ;
3132
3233 const KEY_SSO = 'sso ' ;
@@ -37,6 +38,11 @@ class PluginSession extends SSOData
3738 */
3839 private $ pluginInstanceId = null ;
3940
41+ /**
42+ * @var String $sessionId the id of the current session.
43+ */
44+ private $ sessionId = null ;
45+
4046 /**
4147 * @var boolean $userView flag for userView mode.
4248 */
@@ -72,6 +78,7 @@ public function __construct($pluginId, $appSecret, SessionHandlerInterface $sess
7278
7379 $ pid = isset ($ _GET [self ::QUERY_PARAM_PID ]) ? $ _GET [self ::QUERY_PARAM_PID ] : null ;
7480 $ jwt = isset ($ _GET [self ::QUERY_PARAM_JWT ]) ? $ _GET [self ::QUERY_PARAM_JWT ] : null ;
81+ $ sid = isset ($ _GET [self ::QUERY_PARAM_SID ]) ? $ _GET [self ::QUERY_PARAM_SID ] : null ;
7582
7683 // lets hint to bad class usage, as these cases should never happen.
7784 if ($ pid && $ jwt ) {
@@ -83,30 +90,31 @@ public function __construct($pluginId, $appSecret, SessionHandlerInterface $sess
8390 }
8491
8592 $ this ->pluginInstanceId = $ pid ;
93+ $ this ->sessionId = $ sid ;
8694
8795 // we update the SSO info every time we get a token
8896 if ($ jwt ) {
8997 // decrypt the token
9098 $ this ->sso = new SSOToken ($ appSecret , $ jwt , $ leeway );
9199
92- // update data
93100 $ this ->pluginInstanceId = $ this ->sso ->getInstanceId ();
101+ $ this ->sessionId = $ this ->sso ->getSessionId ();
94102 }
95103
96104 // dispatch remote calls from Staffbase
97105 if ($ this ->sso ) {
98106 $ this ->deleteInstance ($ remoteCallHandler );
99107 }
100108
101- // decide if we are in user view or not
102- $ this ->userView = !$ this ->isAdminView ();
103-
104109 $ this ->openSession ($ pluginId );
105110
106111 if ($ this ->sso !== null ) {
107112 $ _SESSION [$ this ->pluginInstanceId ][self ::KEY_SSO ] = $ this ->sso ->getData ();
108113 }
109114
115+ // decide if we are in user view or not
116+ $ this ->userView = !$ this ->isAdminView ();
117+
110118 // requests with spoofed PID are not allowed
111119 if (!isset ($ _SESSION [$ this ->pluginInstanceId ][self ::KEY_SSO ])
112120 || empty ($ _SESSION [$ this ->pluginInstanceId ][self ::KEY_SSO ]))
@@ -170,9 +178,9 @@ protected function exitRemoteCall() {
170178 *
171179 * @param string $name of the session
172180 */
173- protected function openSession ($ name ) {
181+ protected function openSession (string $ name ) {
174182
175- $ sessionId = $ this ->createCompatibleSessionId ($ this ->sso -> getSessionId () );
183+ $ sessionId = $ this ->createCompatibleSessionId ($ this ->sessionId );
176184
177185 session_id ($ sessionId );
178186 session_name ($ name );
@@ -284,32 +292,32 @@ public function isUserView() {
284292 return $ this ->userView ;
285293 }
286294
287- /**
288- * Destroy the session with the given id
289- *
290- * @param String $sessionId
291- * @return bool true on success or false on failure.
292- */
293- public function destroySession (String $ sessionId = null ) {
294-
295- $ sessionId = $ sessionId ?: $ this ->sso -> getSessionId () ;
296-
297- // save the current session
298- $ currentId = session_id ();
299- session_write_close ();
300-
301- // switch to the target session and removes it
302- session_id ($ this ->createCompatibleSessionId ($ sessionId ));
303- session_start ();
304- $ result = session_destroy ();
305-
306- // switches back to the original session
307- if ($ currentId !== $ sessionId ) {
308- session_id ($ currentId );
309- session_start ();
310- }
311-
312- return $ result ;
313- }
295+ /**
296+ * Destroy the session with the given id
297+ *
298+ * @param String $sessionId
299+ * @return bool true on success or false on failure.
300+ */
301+ public function destroySession (String $ sessionId = null ) {
302+
303+ $ sessionId = $ sessionId ?: $ this ->sessionId ;
304+
305+ // save the current session
306+ $ currentId = session_id ();
307+ session_write_close ();
308+
309+ // switch to the target session and removes it
310+ session_id ($ this ->createCompatibleSessionId ($ sessionId ));
311+ session_start ();
312+ $ result = session_destroy ();
313+
314+ // switches back to the original session
315+ if ($ currentId !== $ sessionId ) {
316+ session_id ($ currentId );
317+ session_start ();
318+ }
319+
320+ return $ result ;
321+ }
314322
315323}
0 commit comments