Skip to content

Commit 62a9a19

Browse files
Merge pull request #15793 from rabbitmq/fix-oauth2-basic-auth-reload
rabbitmq_management: Fix issue with oauth2+basic_auth
2 parents 8a01260 + 49c2979 commit 62a9a19

File tree

12 files changed

+102
-31
lines changed

12 files changed

+102
-31
lines changed

deps/rabbitmq_management/priv/www/js/oidc-oauth/helper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,18 @@ function get_oauth_settings() {
100100
export function oauth_initialize_if_required(state = "index") {
101101
let oauth = oauth_initialize(get_oauth_settings())
102102
if (!oauth.enabled) return oauth;
103+
103104
switch (state) {
104105
case 'login-callback':
105106
oauth_completeLogin(); break;
106107
case 'logout-callback':
107108
oauth_completeLogout(); break;
108109
default:
109-
oauth = oauth_initiate(oauth);
110+
if (has_auth_credentials(BASIC_AUTH_SCHEME)) {
111+
break;
112+
} else {
113+
oauth = oauth_initiate(oauth);
114+
}
110115
}
111116
return oauth;
112117
}

deps/rabbitmq_management/priv/www/js/prefs.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const LOGGED_IN = 'loggedIn'
1414
const LOGIN_SESSION_TIMEOUT = "login_session_timeout"
1515
const AUTH_RESOURCE = 'auth_resource'
1616

17+
const BASIC_AUTH_SCHEME = "Basic"
18+
const BEARER_AUTH_SCHEME = "Bearer"
19+
20+
1721
function set_auth_resource(resource) {
1822
store_local_pref(AUTH_RESOURCE, resource)
1923
}
@@ -24,9 +28,12 @@ function get_auth_resource() {
2428
return get_local_pref(AUTH_RESOURCE)
2529
}
2630

27-
function has_auth_credentials() {
28-
return get_local_pref(CREDENTIALS) != undefined && get_local_pref(AUTH_SCHEME) != undefined &&
29-
get_cookie_value(LOGGED_IN) != undefined
31+
// When auth_scheme is undefined, matches any scheme for backwards compatibility.
32+
function has_auth_credentials(auth_scheme) {
33+
let authenticated =get_local_pref(CREDENTIALS) != undefined && get_local_pref(AUTH_SCHEME) != undefined &&
34+
get_cookie_value(LOGGED_IN) != undefined;
35+
return authenticated && (auth_scheme == undefined
36+
|| auth_scheme == get_auth_scheme());
3037
}
3138
function get_auth_credentials() {
3239
return get_local_pref(CREDENTIALS)
@@ -54,6 +61,7 @@ function set_auth(auth_scheme, credentials, validUntil) {
5461
store_local_pref(AUTH_SCHEME, auth_scheme)
5562
store_cookie_value_with_expiration(LOGGED_IN, "true", validUntil) // session marker
5663
}
64+
5765
function authorization_header() {
5866
if (has_auth_credentials()) {
5967
return get_auth_scheme() + ' ' + get_auth_credentials();

selenium/bin/components/fakeproxy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ init_fakeproxy() {
2020
CLIENT_ID="${CLIENT_ID:-rabbit_idp_user}"
2121
CLIENT_SECRET="${CLIENT_SECRET:-rabbit_idp_user}"
2222
RABBITMQ_HOST_FOR_FAKEPROXY=${RABBITMQ_HOST_FOR_FAKEPROXY:-rabbitmq:15672}
23-
UAA_URL_FOR_FAKEPROXY=${UAA_URL_FOR_FAKEPROXY:-http://uaa:8080}
2423

2524
RABBITMQ_URL_FOR_FAKEPROXY=$(calculate_rabbitmq_url $RABBITMQ_HOST_FOR_FAKEPROXY)
2625

2726
print "> FAKEPROXY_URL: ${FAKEPROXY_URL}"
28-
print "> UAA_URL: ${UAA_URL_FOR_FAKEPROXY}"
27+
print "> IDP_TOKEN_ENDPOINT: ${IDP_TOKEN_ENDPOINT}"
2928
print "> RABBITMQ_HOST_FOR_FAKEPROXY: ${RABBITMQ_HOST_FOR_FAKEPROXY}"
3029
print "> CLIENT_ID: ${CLIENT_ID}"
3130
print "> CLIENT_SECRET: ${CLIENT_SECRET}"
@@ -46,7 +45,7 @@ start_fakeproxy() {
4645
--publish 9090:9090 \
4746
--env PORT=9090 \
4847
--env RABBITMQ_URL="${RABBITMQ_URL_FOR_FAKEPROXY}" \
49-
--env UAA_URL="${UAA_URL_FOR_FAKEPROXY}" \
48+
--env IDP_TOKEN_ENDPOINT="${IDP_TOKEN_ENDPOINT}" \
5049
--env CLIENT_ID="${CLIENT_ID}" \
5150
--env CLIENT_SECRET="${CLIENT_SECRET}" \
5251
--env NODE_EXTRA_CA_CERTS=/etc/uaa/ca_uaa_certificate.pem \

selenium/fakeportal/proxy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var http = require('http'),
2-
httpProxy = require('http-proxy');
2+
httpProxy = require('http-proxy');
33

44
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
55

66
const rabbitmq_url = process.env.RABBITMQ_URL || 'http://0.0.0.0:15672/';
77
const client_id = process.env.CLIENT_ID;
88
const client_secret = process.env.CLIENT_SECRET;
9-
const uaa_url = process.env.UAA_URL;
109
const port = process.env.PORT;
10+
const idp_token_endpoint = process.env.IDP_TOKEN_ENDPOINT;
1111

1212
//
1313
// Create a proxy server with custom application logic
@@ -52,7 +52,7 @@ function default_if_blank(value, defaultValue) {
5252

5353
function access_token(id, secret) {
5454
const req = new XMLHttpRequest();
55-
const url = uaa_url + '/oauth/token';
55+
const url = idp_token_endpoint;
5656
const params = 'client_id=' + id +
5757
'&client_secret=' + secret +
5858
'&grant_type=client_credentials' +

selenium/test/amqp.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ module.exports = {
5252
resolve()
5353
})
5454
})
55-
console.log("Opening amqp connection using " + JSON.stringify(connectionOptions))
55+
log("Opening amqp connection using " + JSON.stringify(connectionOptions,
56+
(key, value) => {
57+
// Omit the private key from the log output.
58+
if (key === "key") return undefined;
59+
return value;
60+
}
61+
))
5662

5763
let connection = container.connect(connectionOptions)
5864
let receiver = connection.open_receiver({

selenium/test/oauth/with-basic-auth/happy-login.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { By, Key, until, Builder } = require('selenium-webdriver')
22
require('chromedriver')
33
const assert = require('assert')
4-
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage } = require('../../utils')
4+
const { buildDriver, goToHome, captureScreensFor, teardown, idpLoginPage, log } = require('../../utils')
55

66
const SSOHomePage = require('../../pageobjects/SSOHomePage')
77
const OverviewPage = require('../../pageobjects/OverviewPage')
@@ -40,6 +40,46 @@ describe('An user with administrator tag', function () {
4040
await overview.logout()
4141
})
4242

43+
describe("and logged in via OAuth 2.0", function() {
44+
before(async function() {
45+
await homePage.clickToLogin()
46+
await idpLogin.login('rabbit_admin', 'rabbit_admin')
47+
if (!await overview.isLoaded()) {
48+
throw new Error('Failed to login via OAuth 2.0')
49+
}
50+
})
51+
it ('can reload page without being logged out', async function() {
52+
log("About to refresh page")
53+
await overview.refresh()
54+
if (!await overview.isLoaded()) {
55+
throw new Error('Failed to keep session opened')
56+
}
57+
})
58+
after(async function () {
59+
await overview.logout()
60+
})
61+
})
62+
63+
describe("and logged in via basic auth", function() {
64+
before(async function() {
65+
await homePage.toggleBasicAuthSection()
66+
await homePage.basicAuthLogin('guest', 'guest')
67+
if (!await overview.isLoaded()) {
68+
throw new Error('Failed to login')
69+
}
70+
})
71+
it ('can reload page without being logged out', async function() {
72+
log("About to refresh page")
73+
await overview.refresh()
74+
if (!await overview.isLoaded()) {
75+
throw new Error('Failed to keep session opened')
76+
}
77+
})
78+
after(async function () {
79+
await overview.logout()
80+
})
81+
})
82+
4383
after(async function () {
4484
await teardown(driver, this, captureScreen)
4585
})

selenium/test/oauth/with-basic-auth/unauthorized.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ describe('An user without management tag', function () {
4040
assert.ok(!await homePage.isOAuth2SectionVisible())
4141
})
4242

43-
describe("After clicking on logout button", function() {
44-
45-
before(async function () {
46-
await homePage.clickToLogout()
47-
})
48-
49-
it('should get redirected to home page again without error message', async function(){
50-
const visible = await homePage.isWarningVisible()
51-
assert.ok(!visible)
52-
})
53-
54-
})
55-
56-
5743
after(async function () {
5844
await teardown(driver, this, captureScreen)
5945
})

selenium/test/oauth/with-idp-initiated-via-proxy/happy-login.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ describe('A user with a JWT token', function () {
2222
assert.equal(await overview.getUser(), 'User rabbit_idp_user')
2323
})
2424

25+
26+
it ('can reload page without being logged out', async function() {
27+
await goToHome(driver);
28+
await overview.isLoaded();
29+
30+
await overview.refresh()
31+
if (!await overview.isLoaded()) {
32+
throw new Error('Failed to keep session opened')
33+
}
34+
})
35+
36+
2537
after(async function () {
2638
await teardown(driver, this, captureScreen)
2739
})

selenium/test/oauth/with-idp-initiated/happy-login.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ describe('A user with a JWT token', function () {
3333
assert.equal(await overview.getUser(), 'User ' + username)
3434
})
3535

36+
it ('can reload page without being logged out', async function() {
37+
await fakePortal.goToHome(username, password)
38+
if (!await fakePortal.isLoaded()) {
39+
throw new Error('Failed to load fakePortal')
40+
}
41+
await fakePortal.login()
42+
await overview.isLoaded()
43+
44+
await overview.refresh()
45+
if (!await overview.isLoaded()) {
46+
throw new Error('Failed to keep session opened')
47+
}
48+
})
49+
3650
after(async function () {
3751
await teardown(driver, this, captureScreen)
3852
})

selenium/test/oauth/with-idp-initiated/logout.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { By, Key, until, Builder } = require('selenium-webdriver')
22
require('chromedriver')
33
const assert = require('assert')
4-
const { buildDriver, captureScreensFor, teardown } = require('../../utils')
4+
const { buildDriver, captureScreensFor, teardown, delay } = require('../../utils')
55

66
const OverviewPage = require('../../pageobjects/OverviewPage')
77
const FakePortalPage = require('../../pageobjects/FakePortalPage')
@@ -28,6 +28,7 @@ describe('When a logged in user', function () {
2828

2929
it('logs out', async function () {
3030
await overview.logout()
31+
await delay(1500)
3132
await fakePortal.isLoaded()
3233
})
3334

0 commit comments

Comments
 (0)