Skip to content

Commit

Permalink
Improved SSO login & autologin
Browse files Browse the repository at this point in the history
  • Loading branch information
1earch committed Sep 3, 2019
1 parent 03f0137 commit fa9c778
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ angular.module('thehive', [
}
},
params: {
autoLogin: false
disableSsoAutoLogin: false
},
title: 'Login'
})
Expand Down
10 changes: 7 additions & 3 deletions ui/app/scripts/controllers/AuthenticationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('AuthenticationCtrl', function($scope, $state, $location, $uibModalStack, $stateParams, AuthenticationSrv, NotificationSrv, UtilsSrv, UrlParser, appConfig) {
.controller('AuthenticationCtrl', function($scope, $state, $location, $uibModalStack, $stateParams, AuthenticationSrv, NotificationSrv, appConfig) {
$scope.params = {};
$scope.ssoLogingIn = false;

$uibModalStack.dismissAll();

$scope.ssoLogin = function (code) {
$scope.ssoLogingIn = true;
AuthenticationSrv.ssoLogin(code)
.then(function(response) {
var redirectLocation = response.headers().location;
if(angular.isDefined(redirectLocation)) {
window.location = redirectLocation;
} else {
$location.search('code', null);
$state.go('app.cases');
}
})
Expand All @@ -25,6 +28,7 @@
} else {
NotificationSrv.log(err.data.message, 'error');
}
$scope.ssoLogingIn = false;
$location.url($location.path());
});
};
Expand All @@ -49,8 +53,8 @@
});
};

var code = UtilsSrv.extractQueryParam('code', UrlParser('query', $location.absUrl()));
if(angular.isDefined(code) || $stateParams.autoLogin) {
var code = $location.search().code;
if(angular.isDefined(code) || (appConfig.config.ssoAutoLogin && !$stateParams.disableSsoAutoLogin)) {
$scope.ssoLogin(code);
}
});
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/controllers/RootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module('theHiveControllers').controller('RootCtrl',
$state.go('maintenance');
return;
}else if(!currentUser || !currentUser.id) {
$state.go('login', {autoLogin: appConfig.config.ssoAutoLogin });
$state.go('login');
return;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ angular.module('theHiveControllers').controller('RootCtrl',

$scope.logout = function() {
AuthenticationSrv.logout(function() {
$state.go('login');
$state.go('login', {disableSsoAutoLogin: true});
}, function(data, status) {
NotificationSrv.error('RootCtrl', data, status);
});
Expand Down
17 changes: 0 additions & 17 deletions ui/app/scripts/services/UtilsSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,6 @@
scope.value = scope.oldValue;
scope.updatable.updating = false;
};
},

extractQueryParam: function(paramName, queryString) {
if (!queryString || !paramName) {
return;
}

var param = $location.search()[paramName];

if (param) {
return param;
} else {
var parsedQuery = _.find(queryString.split('&'), function(str) {
return str.startsWith(paramName + '=');
});
return parsedQuery ? parsedQuery.substr(paramName.length + 1) : undefined;
}
}
};

Expand Down
10 changes: 5 additions & 5 deletions ui/app/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
<p class="login-box-msg">Sign in to start your session</p>
<form name="loginForm">
<div class="form-group has-feedback has-feedback-left">
<input type="text" class="form-control" placeholder="Login" ng-model="params.username" autocomplete="off" required>
<input type="text" class="form-control" placeholder="Login" ng-model="params.username" autocomplete="off" required ng-disabled="ssoLogingIn">
<i class="form-control-feedback glyphicon glyphicon-user"></i>
</div>
<div class="form-group has-feedback has-feedback-left">
<input type="password" class="input form-control" placeholder="Password" ng-model="params.password" autocomplete="off" required>
<input type="password" class="input form-control" placeholder="Password" ng-model="params.password" autocomplete="off" required ng-disabled="ssoLogingIn">
<i class="form-control-feedback glyphicon glyphicon-lock "></i>
</div>

<div class="row">
<div class="col-xs-offset-8 col-xs-4">
<button type="submit" ng-click="login()" class="btn btn-primary btn-sm btn-block btn-flat" ng-disabled="loginForm.$invalid">Sign In</button>
<button type="submit" ng-click="login()" class="btn btn-primary btn-sm btn-block btn-flat" ng-disabled="loginForm.$invalid || ssoLogingIn">Sign In</button>
</div>
</div>
</form>
</div>
<div class="sso-login-box" ng-if="::ssoEnabled()">
<div class="row">
<div class="col-xs-offset-4 col-xs-4">
<button type="submit" class="btn btn-success btn-sm btn-block btn-flat" ng-click="ssoLogin()">Sign In with SSO</button>
<div class="col-xs-6" style="margin: 0 auto; float: none;">
<button type="submit" class="btn btn-sm btn-flat" ng-class="{'btn-warning': ssoLogingIn, 'btn-success': !ssoLogingIn}" ng-click="ssoLogin()" ng-disabled="ssoLogingIn">{{ ssoLogingIn ? "Signing in with SSO..." : "Sign in with SSO" }}</button>
</div>
</div>
</div>
Expand Down

0 comments on commit fa9c778

Please sign in to comment.