1
1
2
- $ ( document ) . ready ( function ( ) {
3
- var url_string = window . location . href ;
4
- var url = new URL ( url_string ) ;
5
- var error = url . searchParams . get ( 'error' ) ;
6
- if ( error ) {
7
- renderWarningMessageInLoginStatus ( fmt_escape_html ( error ) ) ;
8
- } else {
9
- if ( oauth . enabled ) {
10
- startWithOAuthLogin ( ) ;
11
- } else {
12
- startWithLoginPage ( ) ;
13
- }
2
+ $ ( document ) . ready ( function ( ) {
3
+ var url_string = window . location . href ;
4
+ var url = new URL ( url_string ) ;
5
+ var error = url . searchParams . get ( 'error' ) ;
6
+ if ( error ) {
7
+ if ( oauth . enabled ) {
8
+ renderWarningMessageInLoginStatus ( oauth , fmt_escape_html ( error ) ) ;
14
9
}
10
+ } else {
11
+ if ( oauth . enabled ) {
12
+ startWithOAuthLogin ( oauth ) ;
13
+ } else {
14
+ startWithLoginPage ( ) ;
15
+ }
16
+ }
15
17
} ) ;
16
18
17
19
function startWithLoginPage ( ) {
@@ -27,85 +29,18 @@ function removeDuplicates(array){
27
29
}
28
30
return output
29
31
}
30
- function warningMessageOAuthResource ( oauthResource , reason ) {
31
- return "OAuth resource [<b>" + ( oauthResource [ "label" ] != null ? oauthResource . label : oauthResource . id ) +
32
- "</b>] not available. OpenId Discovery endpoint " + readiness_url ( oauthResource ) + reason
33
- }
34
- function warningMessageOAuthResources ( commonProviderURL , oauthResources , reason ) {
35
- return "OAuth resources [ <b>" + oauthResources . map ( resource => resource [ "label" ] != null ? resource . label : resource . id ) . join ( "</b>,<b>" )
36
- + "</b>] not available. OpenId Discovery endpoint " + commonProviderURL + reason
37
- }
38
32
39
- function startWithOAuthLogin ( ) {
33
+
34
+ function startWithOAuthLogin ( oauth ) {
40
35
store_pref ( "oauth-return-to" , window . location . hash ) ;
41
36
42
37
if ( ! oauth . logged_in ) {
43
-
44
- // Find out how many distinct oauthServers are configured
45
- let oauthServers = removeDuplicates ( oauth . resource_servers . filter ( ( resource ) => resource . sp_initiated ) )
46
- oauthServers . forEach ( function ( entry ) { console . log ( readiness_url ( entry ) ) } )
47
- if ( oauthServers . length > 0 ) { // some resources are sp_initiated but there could be idp_initiated too
48
- Promise . allSettled ( oauthServers . map ( oauthServer => fetch ( readiness_url ( oauthServer ) ) . then ( res => res . json ( ) ) ) )
49
- . then ( results => {
50
- results . forEach ( function ( entry ) { console . log ( entry ) } )
51
- let notReadyServers = [ ]
52
- let notCompliantServers = [ ]
53
-
54
- for ( let i = 0 ; i < results . length ; i ++ ) {
55
- switch ( results [ i ] . status ) {
56
- case "fulfilled" :
57
- try {
58
- validate_openid_configuration ( results [ i ] . value )
59
- } catch ( e ) {
60
- console . log ( "Unable to connect to " + oauthServers [ i ] . oauth_provider_url + ". " + e )
61
- notCompliantServers . push ( oauthServers [ i ] . oauth_provider_url )
62
- }
63
- break
64
- case "rejected" :
65
- notReadyServers . push ( oauthServers [ i ] . oauth_provider_url )
66
- break
67
- }
68
- }
69
- const spOauthServers = oauth . resource_servers . filter ( ( resource ) => resource . sp_initiated )
70
- const groupByProviderURL = spOauthServers . reduce ( ( group , oauthServer ) => {
71
- const { oauth_provider_url } = oauthServer ;
72
- group [ oauth_provider_url ] = group [ oauth_provider_url ] ?? [ ] ;
73
- group [ oauth_provider_url ] . push ( oauthServer ) ;
74
- return group ;
75
- } , { } )
76
- let warnings = [ ]
77
- for ( var url in groupByProviderURL ) {
78
- console . log ( url + ': ' + groupByProviderURL [ url ] ) ;
79
- const notReadyResources = groupByProviderURL [ url ] . filter ( ( oauthserver ) => notReadyServers . includes ( oauthserver . oauth_provider_url ) )
80
- const notCompliantResources = groupByProviderURL [ url ] . filter ( ( oauthserver ) => notCompliantServers . includes ( oauthserver . oauth_provider_url ) )
81
- if ( notReadyResources . length == 1 ) {
82
- warnings . push ( warningMessageOAuthResource ( notReadyResources [ 0 ] , " not reachable" ) )
83
- } else if ( notReadyResources . length > 1 ) {
84
- warnings . push ( warningMessageOAuthResources ( url , notReadyResources , " not reachable" ) )
85
- }
86
- if ( notCompliantResources . length == 1 ) {
87
- warnings . push ( warningMessageOAuthResource ( notCompliantResources [ 0 ] , " not compliant" ) )
88
- } else if ( notCompliantResources . length > 1 ) {
89
- warnings . push ( warningMessageOAuthResources ( url , notCompliantResources , " not compliant" ) )
90
- }
91
- }
92
- console . log ( "warnings:" + warnings )
93
- oauth . declared_resource_servers_count = oauth . resource_servers . length
94
- oauth . resource_servers = oauth . resource_servers . filter ( ( resource ) =>
95
- ! notReadyServers . includes ( resource . oauth_provider_url ) && ! notCompliantServers . includes ( resource . oauth_provider_url ) )
96
- render_login_oauth ( warnings )
97
- start_app_login ( )
98
-
99
- } )
100
- } else { // there are only idp_initiated resources
101
- render_login_oauth ( )
102
- start_app_login ( )
103
- }
38
+ hasAnyResourceServerReady ( oauth , ( oauth , warnings ) => { render_login_oauth ( oauth , warnings ) ; start_app_login ( ) ; } )
104
39
} else {
105
40
start_app_login ( )
106
41
}
107
42
}
108
- function render_login_oauth ( messages ) {
43
+ function render_login_oauth ( oauth , messages ) {
109
44
let formatData = { }
110
45
formatData . warnings = [ ]
111
46
formatData . notAuthorized = false
@@ -118,7 +53,6 @@ function render_login_oauth(messages) {
118
53
} else if ( typeof messages == "string" ) {
119
54
formatData . warnings = [ messages ]
120
55
formatData . notAuthorized = messages == "Not authorized"
121
- console . log ( "Single error message" )
122
56
}
123
57
replace_content ( 'outer' , format ( 'login_oauth' , formatData ) )
124
58
@@ -127,13 +61,11 @@ function render_login_oauth(messages) {
127
61
$ ( '#login' ) . on ( 'click' , 'div.section h2, div.section-hidden h2' , function ( ) {
128
62
toggle_visibility ( $ ( this ) ) ;
129
63
} ) ;
130
-
131
64
}
132
- function renderWarningMessageInLoginStatus ( message ) {
133
- render_login_oauth ( message )
65
+ function renderWarningMessageInLoginStatus ( oauth , message ) {
66
+ render_login_oauth ( oauth , message )
134
67
}
135
68
136
-
137
69
function dispatcher_add ( fun ) {
138
70
dispatcher_modules . push ( fun ) ;
139
71
if ( dispatcher_modules . length == extension_count ) {
@@ -187,9 +119,10 @@ function check_login () {
187
119
if ( user == false || user . error ) {
188
120
clear_auth ( ) ;
189
121
if ( oauth . enabled ) {
190
- hide_popup_warn ( ) ;
191
- renderWarningMessageInLoginStatus ( 'Not authorized' ) ;
122
+ // hide_popup_warn();
123
+ renderWarningMessageInLoginStatus ( oauth , 'Not authorized' ) ;
192
124
} else {
125
+ //hide_popup_warn();
193
126
replace_content ( 'login-status' , '<p>Login failed</p>' ) ;
194
127
}
195
128
return false ;
@@ -323,6 +256,7 @@ function dynamic_load(filename) {
323
256
element . setAttribute ( 'type' , 'text/javascript' ) ;
324
257
element . setAttribute ( 'src' , 'js/' + filename ) ;
325
258
document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( element ) ;
259
+ return element ;
326
260
}
327
261
328
262
function update_interval ( ) {
@@ -350,7 +284,11 @@ function update_interval() {
350
284
function go_to ( url ) {
351
285
this . location = url ;
352
286
}
353
-
287
+ function go_to_home ( ) {
288
+ // location.href = rabbit_path_prefix() + "/"
289
+ location . href = "/"
290
+ }
291
+
354
292
function set_timer_interval ( interval ) {
355
293
timer_interval = interval ;
356
294
reset_timer ( ) ;
@@ -1472,16 +1410,16 @@ function sync_req(type, params0, path_template, options) {
1472
1410
else
1473
1411
// rabbitmq/rabbitmq-management#732
1474
1412
// https://developer.mozilla.org/en-US/docs/Glossary/Truthy
1475
- return { result : true , http_status : req . status , req_params : params } ;
1413
+ return { result : true , http_status : req . status , req_params : params , responseText : req . responseText } ;
1476
1414
}
1477
1415
else {
1478
1416
return false ;
1479
1417
}
1480
1418
}
1481
- function initiate_logout ( error = "" ) {
1419
+ function initiate_logout ( oauth , error = "" ) {
1482
1420
clear_pref ( 'auth' ) ;
1483
- clear_cookie_value ( 'auth' ) ;
1484
- renderWarningMessageInLoginStatus ( error ) ;
1421
+ clear_cookie_value ( 'auth' ) ;
1422
+ renderWarningMessageInLoginStatus ( oauth , error ) ;
1485
1423
}
1486
1424
function check_bad_response ( req , full_page_404 ) {
1487
1425
// 1223 == 204 - see https://www.enhanceie.com/ie/bugs.asp
@@ -1502,7 +1440,7 @@ function check_bad_response(req, full_page_404) {
1502
1440
1503
1441
if ( error == 'bad_request' || error == 'not_found' || error == 'not_authorised' || error == 'not_authorized' ) {
1504
1442
if ( ( req . status == 401 || req . status == 403 ) && oauth . enabled ) {
1505
- initiate_logout ( reason ) ;
1443
+ initiate_logout ( oauth , reason ) ;
1506
1444
} else {
1507
1445
show_popup ( 'warn' , fmt_escape_html ( reason ) ) ;
1508
1446
}
0 commit comments