@@ -14,27 +14,101 @@ class Oidc extends BaseController
14
14
* @SuppressWarnings(Param)
15
15
* @return \Psr\Http\Message\ResponseInterface
16
16
*/
17
- public function readResponse (
17
+ public function readResponse (
18
18
\Psr \Http \Message \RequestInterface $ request ,
19
19
\Psr \Http \Message \ResponseInterface $ response ,
20
20
array $ args
21
21
) {
22
- if ($ request ->getParam ("state " ) == \BO \Zmsclient \Auth::getKey ()) {
23
- $ workstation = \App::$ http ->readGetResult ('/workstation/ ' , ['resolveReferences ' => 2 ])->getEntity ();
24
- if (0 == $ workstation ->getUseraccount ()->getDepartmentList ()->count ()) {
25
- return \BO \Slim \Render::redirect (
26
- 'index ' ,
27
- [],
28
- [
29
- 'oidclogin ' => true
30
- ]
31
- );
22
+ try {
23
+ $ state = $ request ->getParam ("state " );
24
+ $ authKey = \BO \Zmsclient \Auth::getKey ();
25
+
26
+ // Log state validation attempt
27
+ error_log (json_encode ([
28
+ 'event ' => 'oauth_state_validation ' ,
29
+ 'timestamp ' => date ('c ' ),
30
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
31
+ 'application ' => 'zmsstatistic ' ,
32
+ 'state_match ' => ($ state == $ authKey )
33
+ ]));
34
+
35
+ if ($ state == $ authKey ) {
36
+ try {
37
+ $ workstation = \App::$ http ->readGetResult ('/workstation/ ' , ['resolveReferences ' => 2 ])->getEntity ();
38
+ $ username = $ workstation ->getUseraccount ()->id . '@ ' . \BO \Zmsclient \Auth::getOidcProvider ();
39
+
40
+ // Log workstation access with username
41
+ error_log (json_encode ([
42
+ 'event ' => 'oauth_workstation_access ' ,
43
+ 'timestamp ' => date ('c ' ),
44
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
45
+ 'application ' => 'zmsstatistic ' ,
46
+ 'username ' => $ username ,
47
+ 'workstation_id ' => $ workstation ->id ?? 'unknown '
48
+ ]));
49
+
50
+ $ departmentCount = $ workstation ->getUseraccount ()->getDepartmentList ()->count ();
51
+
52
+ // Log department check with username
53
+ error_log (json_encode ([
54
+ 'event ' => 'oauth_department_check ' ,
55
+ 'timestamp ' => date ('c ' ),
56
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
57
+ 'application ' => 'zmsstatistic ' ,
58
+ 'username ' => $ username ,
59
+ 'department_count ' => $ departmentCount ,
60
+ 'has_departments ' => ($ departmentCount > 0 )
61
+ ]));
62
+
63
+ if (0 == $ departmentCount ) {
64
+ return \BO \Slim \Render::redirect (
65
+ 'index ' ,
66
+ [],
67
+ [
68
+ 'oidclogin ' => true
69
+ ]
70
+ );
71
+ }
72
+ return \BO \Slim \Render::redirect (
73
+ 'workstationSelect ' ,
74
+ [],
75
+ []
76
+ );
77
+ } catch (\Exception $ e ) {
78
+ // Log workstation access error
79
+ error_log (json_encode ([
80
+ 'event ' => 'oauth_workstation_error ' ,
81
+ 'timestamp ' => date ('c ' ),
82
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
83
+ 'application ' => 'zmsstatistic ' ,
84
+ 'error ' => $ e ->getMessage (),
85
+ 'code ' => $ e ->getCode ()
86
+ ]));
87
+ throw $ e ;
88
+ }
32
89
}
33
- return \BO \Slim \Render::redirect (
34
- 'workstationSelect ' ,
35
- [],
36
- []
37
- );
90
+
91
+ // Log invalid state
92
+ error_log (json_encode ([
93
+ 'event ' => 'oauth_invalid_state ' ,
94
+ 'timestamp ' => date ('c ' ),
95
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
96
+ 'application ' => 'zmsstatistic '
97
+ ]));
98
+
99
+ throw new \BO \Slim \Exception \OAuthInvalid ();
100
+
101
+ } catch (\Exception $ e ) {
102
+ // Log any uncaught exceptions
103
+ error_log (json_encode ([
104
+ 'event ' => 'oauth_error ' ,
105
+ 'timestamp ' => date ('c ' ),
106
+ 'provider ' => \BO \Zmsclient \Auth::getOidcProvider (),
107
+ 'application ' => 'zmsstatistic ' ,
108
+ 'error ' => $ e ->getMessage (),
109
+ 'code ' => $ e ->getCode ()
110
+ ]));
111
+ throw $ e ;
38
112
}
39
113
}
40
114
}
0 commit comments