You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2024/06/27 13:41:48 UTC
(brooklyn-ui) 02/02: add logging and extra headers to login form
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git
commit 2429a734217cb70135a9c28ea394b0b5a4b5644c
Author: Alex Heneveld <gi...@alex.heneveld.org>
AuthorDate: Thu Jun 27 13:52:23 2024 +0100
add logging and extra headers to login form
---
ui-modules/login/app/views/main/main.controller.js | 32 ++++++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/ui-modules/login/app/views/main/main.controller.js b/ui-modules/login/app/views/main/main.controller.js
index d35c6518..a8f6d2bd 100644
--- a/ui-modules/login/app/views/main/main.controller.js
+++ b/ui-modules/login/app/views/main/main.controller.js
@@ -27,7 +27,13 @@ import './login-failed.less';
const MODULE_NAME = 'states.login';
angular.module(MODULE_NAME, [uiRouter, serverApi])
- .config(['$stateProvider', loginStateConfig]);
+ .config(['$stateProvider', loginStateConfig])
+ .config(['$httpProvider', function($httpProvider) {
+ // Sometimes this can help prevent the auth popup from appearing,
+ // by indicating the apache and nginx that WWW-Authenticate should be omitted.
+ // Not necessary because Brooklyn server rewrites BASIC where necessary, but potentially useful.
+ $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
+ }]);
export default MODULE_NAME;
@@ -52,13 +58,27 @@ export function loginStateController($scope, $http, $window, $uibModal, brBrandI
let loginController = this;
loginController.error = {};
- var testAuthReq = {
+ const testAuthReq = {
method: 'HEAD',
- url: '/v1/server/up/extended'
+ url: '/v1/server/up/extended',
+ headers: {
+ // as above (httpProvider)
+ 'X-Requested-With': 'XMLHttpRequest'
+ }
}
// If the user is already logged in then redirect to home
- $http(testAuthReq).then( () => ( $window.location.href = '/' ) );
+ // (note httpProvider call above to prevent browser popup)
+ $http(testAuthReq).then( () => {
+ if ($window.location.pathname = '/') {
+ throw new Error('Actually API request was successful, and we are logged in, but this page is configured to be shown as the root. A redirect will result in an infinite loop, so will ignore and simply show this form.');
+ // will get caught below
+ }
+ console.debug("API request successful. Either already logged in or no login necessary. Redirecting to main page instead of showing login form. Coming from: "+$window.location.href);
+ $window.location.href = '/';
+ }).catch(err => {
+ console.debug("API request unsuccessful. Not already logged in. Showing login form.", err);
+ });
$scope.login = (user)=> {
if (user==null) {
@@ -66,9 +86,9 @@ export function loginStateController($scope, $http, $window, $uibModal, brBrandI
return;
}
var req = {
- method: 'HEAD',
- url: '/v1/server/up/extended',
+ ...testAuthReq,
headers: {
+ ...testAuthReq.headers,
'Authorization': 'Basic ' + btoa(user.name +":" + user.password)
}
}