diff --git a/deps/rabbitmq_management/include/rabbit_mgmt.hrl b/deps/rabbitmq_management/include/rabbit_mgmt.hrl index 53f83c001810..be0a3dfdca65 100644 --- a/deps/rabbitmq_management/include/rabbit_mgmt.hrl +++ b/deps/rabbitmq_management/include/rabbit_mgmt.hrl @@ -14,5 +14,7 @@ -define(MANAGEMENT_DEFAULT_HTTP_MAX_BODY_SIZE, 20000000). --define(OAUTH2_ACCESS_TOKEN_COOKIE_NAME, <<"access_token">>). --define(OAUTH2_ACCESS_TOKEN_COOKIE_PATH, <<"js/oidc-oauth/bootstrap.js">>). +-define(OAUTH2_ACCESS_TOKEN, <<"access_token">>). +-define(OAUTH2_BOOTSTRAP_PATH, <<"js/oidc-oauth/bootstrap.js">>). +-define(MANAGEMENT_LOGIN_STRICT_AUTH_MECHANISM, <<"strict_auth_mechanism">>). +-define(MANAGEMENT_LOGIN_PREFERRED_AUTH_MECHANISM, <<"preferred_auth_mechanism">>). diff --git a/deps/rabbitmq_management/priv/www/js/main.js b/deps/rabbitmq_management/priv/www/js/main.js index 7e910978ed12..6604555e057a 100644 --- a/deps/rabbitmq_management/priv/www/js/main.js +++ b/deps/rabbitmq_management/priv/www/js/main.js @@ -41,12 +41,14 @@ function startWithOAuthLogin (oauth) { } } function render_login_oauth(oauth, messages) { - let formatData = {} - formatData.warnings = [] - formatData.notAuthorized = false - formatData.resource_servers = oauth.resource_servers - formatData.declared_resource_servers_count = oauth.declared_resource_servers_count - formatData.oauth_disable_basic_auth = oauth.oauth_disable_basic_auth + let formatData = {}; + formatData.warnings = []; + formatData.notAuthorized = false; + formatData.resource_servers = oauth.resource_servers; + formatData.declared_resource_servers_count = oauth.declared_resource_servers_count; + formatData.oauth_disable_basic_auth = oauth.oauth_disable_basic_auth; + formatData.strict_auth_mechanism = oauth.strict_auth_mechanism; + formatData.preferred_auth_mechanism = oauth.preferred_auth_mechanism; if (Array.isArray(messages)) { formatData.warnings = messages @@ -1133,6 +1135,9 @@ function update_truncate() { function setup_visibility() { $('div.section,div.section-hidden').each(function(_index) { + if ($(this).hasClass("disable-pref")) { + return; + } var pref = section_pref(current_template, $(this).children('h2').text()); var show = get_pref(pref); diff --git a/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js b/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js index be84377e22d6..5a2248bfb50e 100644 --- a/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js +++ b/deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js @@ -193,16 +193,24 @@ function oauth_initialize_user_manager(resource_server) { }); } + export function oauth_initialize(authSettings) { authSettings = auth_settings_apply_defaults(authSettings); let oauth = { "logged_in": false, "enabled" : authSettings.oauth_enabled, "resource_servers" : authSettings.resource_servers, - "oauth_disable_basic_auth" : authSettings.oauth_disable_basic_auth + "oauth_disable_basic_auth" : authSettings.oauth_disable_basic_auth, } if (!oauth.enabled) return oauth; - + + if (authSettings.resource_servers.length > 1 || !authSettings.oauth_disable_basic_auth) { + if (authSettings.strict_auth_mechanism) { + oauth["strict_auth_mechanism"] = authSettings.strict_auth_mechanism; + }else if (authSettings.preferred_auth_mechanism) { + oauth["preferred_auth_mechanism"] = authSettings.preferred_auth_mechanism; + } + } let resource_server = null; if (oauth.resource_servers.length == 1) { @@ -392,11 +400,12 @@ export function hasAnyResourceServerReady(oauth, onReadyCallback) { warnings.push(warningMessageOAuthResources(url, notCompliantResources, " not compliant")) } } - oauth.declared_resource_servers_count = oauth.resource_servers.length + oauth.declared_resource_servers_count = oauth.resource_servers.length; oauth.resource_servers = oauth.resource_servers.filter((resource) => - !notReadyServers.includes(resource.oauth_provider_url) && !notCompliantServers.includes(resource.oauth_provider_url)) + !notReadyServers.includes(resource.oauth_provider_url) && !notCompliantServers.includes(resource.oauth_provider_url)); + oauth.resource_servers.sort((a, b) => a.index - b.index); - onReadyCallback(oauth, warnings) + onReadyCallback(oauth, warnings) }) }else { diff --git a/deps/rabbitmq_management/priv/www/js/tmpl/login_oauth.ejs b/deps/rabbitmq_management/priv/www/js/tmpl/login_oauth.ejs index 0e6f46be873c..06fb142a419d 100644 --- a/deps/rabbitmq_management/priv/www/js/tmpl/login_oauth.ejs +++ b/deps/rabbitmq_management/priv/www/js/tmpl/login_oauth.ejs @@ -12,14 +12,22 @@ <% } %> <% if (!notAuthorized) { %> - <% if ((typeof resource_servers == 'object' && resource_servers.length == 1) && oauth_disable_basic_auth) { %> + <% if (strict_auth_mechanism !== undefined && strict_auth_mechanism.type === "oauth2") { %> + + <% } else if ((typeof resource_servers == 'object' && resource_servers.length == 1) && oauth_disable_basic_auth) { %> - <% } else if (typeof resource_servers == 'object' && resource_servers.length >= 1) { %> + <% } else if (typeof resource_servers == 'object' && resource_servers.length >= 1 && strict_auth_mechanism == undefined) { %> Login with :

+ <% const OAuth2Visible = (strict_auth_mechanism === undefined || strict_auth_mechanism.type === "oauth2") || + (preferred_auth_mechanism === undefined || preferred_auth_mechanism === "oauth2"); %> + <% const OAuth2Invisible = (preferred_auth_mechanism !== undefined && preferred_auth_mechanism.type !== "oauth2"); %> + <% const OAuth2Hidden = (strict_auth_mechanism !== undefined && strict_auth_mechanism.type !== "oauth2"); %> + <% const preferredResourceId = preferred_auth_mechanism !== undefined && preferred_auth_mechanism.type === "oauth2" ? preferred_auth_mechanism.resource_id : null; %> -

+ <% if (!OAuth2Hidden) { %> +

OAuth 2.0

@@ -27,10 +35,10 @@ <% } else { %>
- +