ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amag...@apache.org
Subject [20/50] [abbrv] ambari git commit: AMBARI-22429 Log Search UI: implement logout. (Istvan Tobias via ababiichuk)
Date Wed, 22 Nov 2017 11:17:15 GMT
AMBARI-22429 Log Search UI: implement logout. (Istvan Tobias via ababiichuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7428e51d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7428e51d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7428e51d

Branch: refs/heads/branch-feature-AMBARI-22008
Commit: 7428e51d8e3759edf5248762f0a257a46cc053a5
Parents: 4fa9ac5
Author: Istvan Tobias <tobias.istvan@gmail.com>
Authored: Tue Nov 14 00:31:01 2017 +0200
Committer: ababiichuk <ababiichuk@hortonworks.com>
Committed: Tue Nov 14 00:31:01 2017 +0200

----------------------------------------------------------------------
 .../ambari-logsearch-web/src/app/app.module.ts  |   4 +-
 .../src/app/components/app.component.spec.ts    |   4 +-
 .../dropdown-button.component.spec.ts           |   4 +-
 .../dropdown-list.component.spec.ts             |   4 +-
 .../filter-button.component.spec.ts             |   4 +-
 .../filter-dropdown.component.spec.ts           |   4 +-
 .../login-form/login-form.component.spec.ts     |   7 +-
 .../login-form/login-form.component.ts          |  34 +++--
 .../menu-button/menu-button.component.spec.ts   |   4 +-
 .../timezone-picker.component.spec.ts           |   4 +-
 .../components/top-menu/top-menu.component.ts   |   3 +-
 .../ambari-logsearch-web/src/app/mock-data.ts   |   3 +-
 .../src/app/services/auth.service.spec.ts       | 132 +++++++++++++++++++
 .../src/app/services/auth.service.ts            | 123 +++++++++++++++++
 .../services/component-actions.service.spec.ts  |   4 +-
 .../app/services/component-actions.service.ts   |  20 ++-
 .../src/assets/i18n/en.json                     |   1 +
 17 files changed, 328 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts b/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
index 37f3a49..805f8e2 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/app.module.ts
@@ -53,6 +53,7 @@ import {ComponentsService} from '@app/services/storage/components.service';
 import {ServiceLogsFieldsService} from '@app/services/storage/service-logs-fields.service';
 import {AuditLogsFieldsService} from '@app/services/storage/audit-logs-fields.service';
 import {TabsService} from '@app/services/storage/tabs.service';
+import {AuthService} from '@app/services/auth.service';
 import {reducer} from '@app/services/storage/reducers.service';
 
 import {AppComponent} from '@app/components/app.component';
@@ -185,7 +186,8 @@ export function getXHRBackend(injector: Injector, browser: BrowserXhr,
xsrf: XSR
       provide: XHRBackend,
       useFactory: getXHRBackend,
       deps: [Injector, BrowserXhr, XSRFStrategy, ResponseOptions]
-    }
+    },
+    AuthService
   ],
   bootstrap: [AppComponent],
   entryComponents: [NodeBarComponent],

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/app.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/app.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/app.component.spec.ts
index 490e058..bae05ce 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/app.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/app.component.spec.ts
@@ -53,9 +53,9 @@ describe('AppComponent', () => {
     }).compileComponents();
   }));
 
-  it('should create the app', async(() => {
+  it('should create the app', () => {
     const fixture = TestBed.createComponent(AppComponent);
     const app = fixture.debugElement.componentInstance;
     expect(app).toBeTruthy();
-  }));
+  });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-button/dropdown-button.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-button/dropdown-button.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-button/dropdown-button.component.spec.ts
index bd41c04..fc42e3c 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-button/dropdown-button.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-button/dropdown-button.component.spec.ts
@@ -36,6 +36,7 @@ import {UtilsService} from '@app/services/utils.service';
 import {ComponentActionsService} from '@app/services/component-actions.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {DropdownButtonComponent} from './dropdown-button.component';
 
@@ -90,7 +91,8 @@ describe('DropdownButtonComponent', () => {
           provide: HttpClientService,
           useValue: httpClient
         },
-        LogsContainerService
+        LogsContainerService,
+        AuthService
       ],
       schemas: [NO_ERRORS_SCHEMA]
     })

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-list/dropdown-list.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-list/dropdown-list.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-list/dropdown-list.component.spec.ts
index ac2fa84..63824cb 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-list/dropdown-list.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/dropdown-list/dropdown-list.component.spec.ts
@@ -36,6 +36,7 @@ import {ComponentGeneratorService} from '@app/services/component-generator.servi
 import {LogsContainerService} from '@app/services/logs-container.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {ComponentActionsService} from '@app/services/component-actions.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {DropdownListComponent} from './dropdown-list.component';
 
@@ -91,7 +92,8 @@ describe('DropdownListComponent', () => {
         ClustersService,
         ComponentsService,
         ServiceLogsTruncatedService,
-        TabsService
+        TabsService,
+        AuthService
       ]
     })
     .compileComponents();

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.spec.ts
index f9ae154..6a9aca5 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-button/filter-button.component.spec.ts
@@ -36,6 +36,7 @@ import {ComponentActionsService} from '@app/services/component-actions.service';
 import {UtilsService} from '@app/services/utils.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {FilterButtonComponent} from './filter-button.component';
 
@@ -90,7 +91,8 @@ describe('FilterButtonComponent', () => {
           provide: HttpClientService,
           useValue: httpClient
         },
-        LogsContainerService
+        LogsContainerService,
+        AuthService
       ],
       schemas: [NO_ERRORS_SCHEMA]
     })

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts
index f9192f4..8293ba0 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/filter-dropdown/filter-dropdown.component.spec.ts
@@ -35,6 +35,7 @@ import {UtilsService} from '@app/services/utils.service';
 import {ComponentActionsService} from '@app/services/component-actions.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
 import {HttpClientService} from '@app/services/http-client.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {FilterDropdownComponent} from './filter-dropdown.component';
 
@@ -109,7 +110,8 @@ describe('FilterDropdownComponent', () => {
         {
           provide: HttpClientService,
           useValue: httpClient
-        }
+        },
+        AuthService
       ],
       schemas: [NO_ERRORS_SCHEMA]
     })

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.spec.ts
index fb5c2a0..ac9f3a8 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.spec.ts
@@ -22,6 +22,7 @@ import {TranslationModules} from '@app/test-config.spec';
 import {StoreModule} from '@ngrx/store';
 import {AppStateService, appState} from '@app/services/storage/app-state.service';
 import {HttpClientService} from '@app/services/http-client.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {LoginFormComponent} from './login-form.component';
 
@@ -58,7 +59,8 @@ describe('LoginFormComponent', () => {
         {
           provide: HttpClientService,
           useValue: httpClient
-        }
+        },
+        AuthService
       ]
     })
     .compileComponents();
@@ -101,9 +103,6 @@ describe('LoginFormComponent', () => {
           expect(component.isLoginAlertDisplayed).toEqual(test.isLoginAlertDisplayed);
         });
 
-        it('isLoginInProgress', () => {
-          expect(component.isLoginInProgress).toEqual(false);
-        });
       });
     });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.ts
index 2bc45404..39a4975 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/login-form/login-form.component.ts
@@ -17,9 +17,10 @@
  */
 
 import {Component} from '@angular/core';
+import {Response} from '@angular/http';
 import 'rxjs/add/operator/finally';
-import {HttpClientService} from '@app/services/http-client.service';
 import {AppStateService} from '@app/services/storage/app-state.service';
+import {AuthService} from '@app/services/auth.service';
 
 @Component({
   selector: 'login-form',
@@ -28,7 +29,7 @@ import {AppStateService} from '@app/services/storage/app-state.service';
 })
 export class LoginFormComponent {
 
-  constructor(private httpClient: HttpClientService, private appState: AppStateService) {
+  constructor(private authService: AuthService, private appState: AppStateService) {
     appState.getParameter('isLoginInProgress').subscribe(value => this.isLoginInProgress
= value);
   }
 
@@ -40,20 +41,25 @@ export class LoginFormComponent {
 
   isLoginInProgress: boolean;
 
-  private setIsAuthorized(value: boolean): void {
-    this.appState.setParameters({
-      isAuthorized: value,
-      isLoginInProgress: false
-    });
-    this.isLoginAlertDisplayed = !value;
-  }
+  /**
+   * Handling the response from the login action. Actually the goal only to show or hide
the login error alert.
+   * When it gets error response it shows.
+   * @param {Response} resp
+   */
+  private onLoginError = (resp: Response): void => {
+    this.isLoginAlertDisplayed = true;
+  };
+  /**
+   * Handling the response from the login action. Actually the goal only to show or hide
the login error alert.
+   * When it gets success response it hides.
+   * @param {Response} resp
+   */
+  private onLoginSuccess = (resp: Response): void => {
+    this.isLoginAlertDisplayed = false;
+  };
 
   login() {
-    this.appState.setParameter('isLoginInProgress', true);
-    this.httpClient.postFormData('login', {
-      username: this.username,
-      password: this.password
-    }).subscribe(() => this.setIsAuthorized(true), () => this.setIsAuthorized(false));
+    this.authService.login(this.username,this.password).subscribe(this.onLoginSuccess, this.onLoginError);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.spec.ts
index 71bbf67..3836e7a 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/menu-button/menu-button.component.spec.ts
@@ -35,6 +35,7 @@ import {TabsService, tabs} from '@app/services/storage/tabs.service';
 import {ComponentActionsService} from '@app/services/component-actions.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {MenuButtonComponent} from './menu-button.component';
 
@@ -88,7 +89,8 @@ describe('MenuButtonComponent', () => {
           provide: HttpClientService,
           useValue: httpClient
         },
-        LogsContainerService
+        LogsContainerService,
+        AuthService
       ],
       schemas: [NO_ERRORS_SCHEMA]
     })

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/timezone-picker/timezone-picker.component.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/timezone-picker/timezone-picker.component.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/timezone-picker/timezone-picker.component.spec.ts
index 0e4c8a8..ab56589 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/timezone-picker/timezone-picker.component.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/timezone-picker/timezone-picker.component.spec.ts
@@ -34,6 +34,7 @@ import {TabsService, tabs} from '@app/services/storage/tabs.service';
 import {ComponentActionsService} from '@app/services/component-actions.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 import {TimeZoneAbbrPipe} from '@app/pipes/timezone-abbr.pipe';
 import {ModalComponent} from '@app/components/modal/modal.component';
 
@@ -93,7 +94,8 @@ describe('TimeZonePickerComponent', () => {
           provide: HttpClientService,
           useValue: httpClient
         },
-        LogsContainerService
+        LogsContainerService,
+        AuthService
       ],
     })
     .compileComponents();

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/components/top-menu/top-menu.component.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/components/top-menu/top-menu.component.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/components/top-menu/top-menu.component.ts
index 05c1a62..91f27e8 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/components/top-menu/top-menu.component.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/components/top-menu/top-menu.component.ts
@@ -36,7 +36,8 @@ export class TopMenuComponent {
           label: 'Options'
         },
         {
-          label: 'Logout'
+          label: 'authorization.logout',
+          action: 'logout'
         }
       ]
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/mock-data.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/mock-data.ts b/ambari-logsearch/ambari-logsearch-web/src/app/mock-data.ts
index 4325f5b..147efef 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/mock-data.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/mock-data.ts
@@ -20,6 +20,7 @@ import * as moment from 'moment';
 
 export const mockData = {
   login: {},
+  logout: {},
   api: {
     v1: {
       audit: {
@@ -1064,4 +1065,4 @@ export const mockData = {
       }
     }
   }
-};
\ No newline at end of file
+};

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
new file mode 100644
index 0000000..a465c10
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.spec.ts
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {TestBed, inject} from '@angular/core/testing';
+import {HttpModule} from '@angular/http';
+import {Observable} from 'rxjs/Observable';
+import {StoreModule} from '@ngrx/store';
+import {AppStateService, appState} from '@app/services/storage/app-state.service';
+import {AuthService} from '@app/services/auth.service';
+import {HttpClientService} from '@app/services/http-client.service';
+
+describe('AuthService', () => {
+
+  let successResponse = {
+    type: 'default',
+    ok: true,
+    url: '/',
+    status: 200,
+    statusText: 'OK',
+    bytesLoaded: 100,
+    totalBytes: 100,
+    headers: null
+  };
+  let errorResponse = {
+    type: 'error',
+    ok: false,
+    url: '/',
+    status: 401,
+    statusText: 'ERROR',
+    bytesLoaded: 100,
+    totalBytes: 100,
+    headers: null
+  };
+  let currentResponse = successResponse;
+  let httpServiceStub;
+  let authService: AuthService;
+
+  beforeEach(() => {
+    // Note: We add delay to help the isLoginInProgress test case.
+    httpServiceStub = {
+      postFormData: function () {
+        return Observable.create(observer => {
+          observer.next(currentResponse);
+        }).delay(1000);
+      },
+      post: function () {
+        return Observable.create(observer => {
+          observer.next(currentResponse);
+        }).delay(1000);
+      },
+      get: function () {
+        return Observable.create(observer => {
+          observer.next(currentResponse);
+        }).delay(1000);
+      }
+    };
+    TestBed.configureTestingModule({
+      imports: [
+        HttpModule,
+        StoreModule.provideStore({
+          appState
+        })
+      ],
+      providers: [
+        AuthService,
+        AppStateService,
+        {provide: HttpClientService, useValue: httpServiceStub}
+      ]
+    });
+    authService = TestBed.get(AuthService);
+  });
+
+  it('should create service', inject([AuthService], (service: AuthService) => {
+    expect(service).toBeTruthy();
+  }));
+
+  it('should set the isAuthorized state to true in appState when the login is success', inject(
+    [AppStateService],
+    (appStateService: AppStateService) => {
+      currentResponse = successResponse;
+      authService.login('test', 'test')
+        .subscribe(() => {
+          appStateService.getParameter('isAuthorized').subscribe((value) => {
+            expect(value).toBe(true);
+          });
+        }, (value) => {
+          throw value;
+        });
+    }
+  ));
+
+
+  it('should set the isAuthorized state to false in appState when the login is failed', inject(
+    [AppStateService],
+    (appStateService: AppStateService) => {
+      currentResponse = errorResponse;
+      authService.login('test', 'test')
+        .subscribe(() => {
+          appStateService.getParameter('isAuthorized').subscribe((value) => {
+            expect(value).toBe(false);
+          });
+        });
+    }
+  ));
+
+  it('should set the isLoginInProgress state to true when the login started.', inject(
+    [AppStateService],
+    (appStateService: AppStateService) => {
+      currentResponse = successResponse;
+      authService.login('test', 'test');
+      appStateService.getParameter('isLoginInProgress').subscribe((value) => {
+        expect(value).toBe(true);
+      });
+    }
+  ));
+
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
new file mode 100644
index 0000000..8785ce2
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/services/auth.service.ts
@@ -0,0 +1,123 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {Injectable} from '@angular/core';
+import {Response} from '@angular/http';
+
+import {Observable} from 'rxjs/Observable';
+
+import {HttpClientService} from '@app/services/http-client.service';
+import {AppStateService} from '@app/services/storage/app-state.service';
+
+/**
+ * This service meant to be a single place where the authorization should happen.
+ */
+@Injectable()
+export class AuthService {
+
+  constructor(private httpClient: HttpClientService, private appState: AppStateService) {}
+
+  /**
+   * The single entry point to request a login action.
+   * @param {string} username
+   * @param {string} password
+   * @returns {Observable<Response>}
+   */
+  login(username: string, password: string): Observable<Response> {
+    this.setLoginInProgressAppState(true);
+    let obs = this.httpClient.postFormData('login', {
+      username: username,
+      password: password
+    });
+    obs.subscribe(
+      (resp: Response) => this.onLoginResponse(resp),
+      (resp: Response) => this.onLoginError(resp)
+    );
+    return obs;
+  }
+
+  /**
+   * The single unique entry point to request a logout action
+   * @returns {Observable<boolean | Error>}
+   */
+  logout(): Observable<Response> {
+    let obs = this.httpClient.get('logout');
+    obs.subscribe(
+      (resp: Response) => this.onLogoutResponse(resp),
+      (resp: Response) => this.onLogoutError(resp)
+    );
+    return obs;
+  }
+
+  /**
+   * Set the isLoginInProgress state in AppState. The reason behind create a function for
this is that we set this app
+   * state from two different places so let's do always the same way.
+   * @param {boolean} state the new value of the isLoginInProgress app state.
+   */
+  private setLoginInProgressAppState(state: boolean) {
+    this.appState.setParameter('isLoginInProgress', state);
+  }
+
+  /**
+   * Set the isAuthorized state in AppState. The reason behind create a function for this
is that we set this app
+   * state from two different places so let's do always the same way.
+   * @param {boolean} state The new value of the isAuthorized app state.
+   */
+  private setAuthorizedAppState(state: boolean) {
+    this.appState.setParameter('isAuthorized', state);
+  }
+
+  /**
+   * Handling the login success response. The goal is to set the authorized property of the
appState.
+   * @param resp
+   */
+  private onLoginResponse(resp: Response): void {
+    if (resp && resp.ok) {
+      this.setLoginInProgressAppState(false);
+      this.setAuthorizedAppState(resp.ok);
+    }
+  }
+
+  /**
+   * Handling the login error response. The goal is to set the authorized property correctly
of the appState.
+   * @ToDo decide if we should have a loginError app state.
+   * @param {Reponse} resp
+   */
+  private onLoginError(resp: Response): void {
+    this.setLoginInProgressAppState(false);
+    this.setAuthorizedAppState(false);
+  }
+
+  /**
+   * Handling the logout success response. The goal is to set the authorized property of
the appState.
+   * @param {Response} resp
+   */
+  private onLogoutResponse(resp: Response): void {
+    if (resp && resp.ok) {
+      this.setAuthorizedAppState(false);
+    }
+  }
+
+  /**
+   * Handling the logout error response.
+   * @ToDo decide if we should create a logoutError app state or not
+   * @param {Response} resp
+   */
+  private onLogoutError(resp: Response): void {}
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.spec.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.spec.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.spec.ts
index 6f54e65..6d43ff1 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.spec.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.spec.ts
@@ -32,6 +32,7 @@ import {ServiceLogsTruncatedService, serviceLogsTruncated} from '@app/services/s
 import {TabsService, tabs} from '@app/services/storage/tabs.service';
 import {HttpClientService} from '@app/services/http-client.service';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 
 import {ComponentActionsService} from './component-actions.service';
 
@@ -81,7 +82,8 @@ describe('ComponentActionsService', () => {
           provide: HttpClientService,
           useValue: httpClient
         },
-        LogsContainerService
+        LogsContainerService,
+        AuthService
       ]
     });
   });

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.ts
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.ts
b/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.ts
index 73fc94c..e796183 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.ts
+++ b/ambari-logsearch/ambari-logsearch-web/src/app/services/component-actions.service.ts
@@ -21,6 +21,7 @@ import {AppSettingsService} from '@app/services/storage/app-settings.service';
 import {TabsService} from '@app/services/storage/tabs.service';
 import {CollectionModelService} from '@app/classes/models/store';
 import {LogsContainerService} from '@app/services/logs-container.service';
+import {AuthService} from '@app/services/auth.service';
 import {ServiceLog} from '@app/classes/models/service-log';
 import {ListItem} from '@app/classes/list-item';
 
@@ -29,7 +30,8 @@ export class ComponentActionsService {
 
   constructor(
     private appSettings: AppSettingsService, private tabsStorage: TabsService,
-    private logsContainer: LogsContainerService
+    private logsContainer: LogsContainerService,
+    private authService: AuthService
   ) {
   }
 
@@ -134,4 +136,20 @@ export class ComponentActionsService {
     isExclude: true
   });
 
+  /**
+   * Request a login action from the AuthService
+   * @param {string} username
+   * @param {string} password
+   */
+  login(username: string, password: string): void {
+    this.authService.login(username, password);
+  }
+
+  /**
+   * Request a logout action from AuthService
+   */
+  logout(): void {
+    this.authService.logout();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7428e51d/ambari-logsearch/ambari-logsearch-web/src/assets/i18n/en.json
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-web/src/assets/i18n/en.json b/ambari-logsearch/ambari-logsearch-web/src/assets/i18n/en.json
index 16b4b32..b214a4f 100644
--- a/ambari-logsearch/ambari-logsearch-web/src/assets/i18n/en.json
+++ b/ambari-logsearch/ambari-logsearch-web/src/assets/i18n/en.json
@@ -10,6 +10,7 @@
   "modal.apply": "Apply",
   "modal.close": "Close",
 
+  "authorization.logout": "Logout",
   "authorization.name": "Username",
   "authorization.password": "Password",
   "authorization.signIn": "Sign In",


Mime
View raw message