Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

(closes #500) add sessionTimeout option to config #519

Merged
merged 1 commit into from
Sep 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,15 @@ In this sections you can specify limits for custom offerings in the following fo

Any of these parameters may be left unspecified, in which case 0 will be used for min and infinity will be used for max.

### sessionTimeout

Number of minutes a user's session should stay active. After this time passes the user is
logged out.

Defaults to `30` (minutes).

You can set it to `0` to turn this off, although in this case the session is likely to expire on the server side.

### allowReorderingSidebar

A boolean value which allows or forbids a user to reorder links in the main sidebar
Expand Down
6 changes: 3 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ZoneService } from './shared/services/zone.service';
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{
export class AppComponent implements OnInit {

@ViewChild(MdlLayoutComponent) public layoutComponent: MdlLayoutComponent;
public loggedIn: boolean;
Expand Down Expand Up @@ -57,13 +57,13 @@ export class AppComponent implements OnInit{
this.loggedIn = isLoggedIn;
this.updateAccount(this.loggedIn);
if (isLoggedIn) {
this.userService.startInactivityCounter();
this.userService.startIdleMonitor();
this.loadSettings();
this.zoneService
.areAllZonesBasic()
.subscribe(basic => (this.disableSecurityGroups = basic));
} else {
this.userService.clearInactivityTimer();
this.userService.stopIdleMonitor();
}
this.asyncJobService.completeAllJobs();
this.cacheService.invalidateAll();
Expand Down
1 change: 0 additions & 1 deletion src/app/security-group/sg-rules/sg-rules.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ describe('Security group firewall rules component', () => {
TestBed.compileComponents().then(() => {
f = TestBed.createComponent(SgRulesComponent);
comp = f.componentInstance;
console.log(comp);
});
}));

Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('User service session', () => {
const inactivityTimeout = 10;
const logout = spyOn(router, 'navigate').and.callThrough();
const refresh = spyOn(userService, 'sendRefreshRequest');
userService.startInactivityCounter();
userService.startIdleMonitor();
userService.setInactivityTimeout(inactivityTimeout).subscribe();

tick(getRefreshInterval() * (inactivityTimeout - 1) * 60 / refreshInterval);
Expand Down
23 changes: 19 additions & 4 deletions src/app/shared/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RouterUtilsService } from './router-utils.service';
import { UserTagService } from './tags/user-tag.service';

const DEFAULT_SESSION_REFRESH_INTERVAL = 60;
const DEFAULT_SESSION_TIMEOUT = 30;

@Injectable()
@BackendResource({
Expand Down Expand Up @@ -40,8 +41,7 @@ export class UserService extends BaseBackendService<User> {
return this.sendCommand('register;Keys', { id }).map(res => res.userkeys);
}


public startInactivityCounter() {
public startIdleMonitor() {
const sessionRefreshInterval = this.getSessionRefreshInterval();

this.getInactivityTimeout().subscribe(inactivityTimeout => {
Expand All @@ -67,8 +67,8 @@ export class UserService extends BaseBackendService<User> {

return this.userTagService.getSessionTimeout()
.switchMap(timeout => {
if (Number.isNaN(timeout)) {
return this.userTagService.setSessionTimeout(0);
if (Number.isNaN(timeout) || timeout < 0) {
return Observable.of(this.getSessionTimeout());
}

return Observable.of(timeout);
Expand Down Expand Up @@ -116,6 +116,11 @@ export class UserService extends BaseBackendService<User> {
clearInterval(this.refreshTimer);
}

public stopIdleMonitor(): void {
this.clearInactivityTimer();
this.inactivityTimeout = 0;
}

private setInactivityTimer(): void {
if (this.sessionRefreshInterval && this.inactivityTimeout) {
this.refreshTimer = setInterval(
Expand All @@ -134,4 +139,14 @@ export class UserService extends BaseBackendService<User> {

return DEFAULT_SESSION_REFRESH_INTERVAL;
}

private getSessionTimeout(): number {
const sessionTimeout = this.configService.get('sessionTimeout');

if (Number.isInteger(sessionTimeout) && sessionTimeout > 0) {
return sessionTimeout;
}

return DEFAULT_SESSION_TIMEOUT;
}
}
1 change: 1 addition & 0 deletions src/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
},
"apiDocLink": "https://cloudstack.apache.org/api/apidocs-4.9/",
"sessionRefreshInterval": 60,
"sessionTimeout": 30,
"allowReorderingSidebar": false,
"defaultServiceOfferingConfig": {
"031a55bb-5d6b-4336-ab93-d5dead28a887": {
Expand Down