From 3ce363510c15afa051454f64b8db303b0adcf053 Mon Sep 17 00:00:00 2001 From: "k.kazak" Date: Fri, 4 Oct 2019 16:58:14 +0200 Subject: Revert "basic auth for so-monitoring" This reverts commit 3cc4c5bf37b4ae20a9809c329ad8aa1889aadbdd. Change-Id: I66ae23f1ef82f28c78986d58ce3373b56e950c7b Issue-ID: OJSI-169 Signed-off-by: k.kazak --- .../so-monitoring-ui/src/main/frontend/README.md | 9 -- .../main/frontend/src/app/app-routing.module.ts | 12 +-- .../src/main/frontend/src/app/app.module.ts | 15 +-- .../src/main/frontend/src/app/auth.guard.ts | 46 --------- .../frontend/src/app/authentication.service.ts | 50 ---------- .../frontend/src/app/basic-auth.interceptor.ts | 43 -------- .../src/main/frontend/src/app/data.service.ts | 2 +- .../src/main/frontend/src/app/error.interceptor.ts | 45 --------- .../frontend/src/app/login/login.component.html | 43 -------- .../frontend/src/app/login/login.component.spec.ts | 108 --------------------- .../main/frontend/src/app/login/login.component.ts | 81 ---------------- .../src/app/sidebar/sidebar.component.html | 63 ++++++------ .../main/frontend/src/environments/environment.ts | 5 +- 13 files changed, 35 insertions(+), 487 deletions(-) delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/auth.guard.ts delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/authentication.service.ts delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/basic-auth.interceptor.ts delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/error.interceptor.ts delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.html delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.spec.ts delete mode 100644 so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.ts (limited to 'so-monitoring/so-monitoring-ui/src/main') diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/README.md b/so-monitoring/so-monitoring-ui/src/main/frontend/README.md index 65731cdc5d..329de0f833 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/README.md +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/README.md @@ -6,15 +6,6 @@ This project was generated with [Angular CLI](https://github.com/angular/angular Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. -FYI: You may need to change environments.ts to hit to your backend: not so-monitoring:30224 but localhost:8088 - -### Logging in - -Backend API for so-monitoring. Requires basic auth to access it. - -Default credentials: -- with role GUI-Client: gui/password1$ - ## Code scaffolding Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app-routing.module.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app-routing.module.ts index 03e77fc2d9..428998dc62 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app-routing.module.ts +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app-routing.module.ts @@ -1,8 +1,6 @@ /** ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. -================================================================================ - Modifications Copyright (c) 2019 Samsung ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,25 +24,17 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { DetailsComponent } from './details/details.component'; -import {AuthGuard} from "./auth.guard"; -import {LoginComponent} from "./login/login.component"; const routes: Routes = [ { // Route to home page path: '', - component: HomeComponent, - canActivate: [AuthGuard] + component: HomeComponent }, { // Route to page to show individual process based on ID path: 'details/:id', component: DetailsComponent - }, - { - // Route to login page - path: 'login', - component: LoginComponent } ]; diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app.module.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app.module.ts index 5adfc049af..75be395879 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app.module.ts +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/app.module.ts @@ -1,8 +1,6 @@ /** ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. -================================================================================ - Modifications Copyright (c) 2019 Samsung ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,7 +28,7 @@ import { AppComponent } from './app.component'; import { SidebarComponent } from './sidebar/sidebar.component'; import { TopbarComponent } from './topbar/topbar.component'; import { HomeComponent } from './home/home.component'; -import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { HttpClientModule } from '@angular/common/http'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { DetailsComponent } from './details/details.component'; import { ToastrNotificationService } from './toastr-notification-service.service'; @@ -39,9 +37,6 @@ import { MatFormFieldModule, MatInputModule, MatTableModule, MatTabsModule, MatS import { NgxSpinnerModule } from 'ngx-spinner'; import { RouterModule, Routes } from '@angular/router'; import { APP_BASE_HREF } from '@angular/common'; -import { LoginComponent } from './login/login.component'; -import { BasicAuthInterceptor } from "./basic-auth.interceptor"; -import { ErrorInterceptor } from "./error.interceptor"; @NgModule({ declarations: [ @@ -49,8 +44,7 @@ import { ErrorInterceptor } from "./error.interceptor"; SidebarComponent, TopbarComponent, HomeComponent, - DetailsComponent, - LoginComponent + DetailsComponent ], imports: [ BrowserModule, @@ -77,10 +71,7 @@ import { ErrorInterceptor } from "./error.interceptor"; schemas: [ CUSTOM_ELEMENTS_SCHEMA ], - providers: [ - { provide: HTTP_INTERCEPTORS, useClass: BasicAuthInterceptor, multi: true }, - { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true }, - ToastrNotificationService], + providers: [ToastrNotificationService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/auth.guard.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/auth.guard.ts deleted file mode 100644 index f437a21710..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/auth.guard.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import { Injectable } from '@angular/core'; -import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router} from '@angular/router'; -import { Observable } from 'rxjs'; - -@Injectable({ - providedIn: 'root' -}) -export class AuthGuard implements CanActivate { - - constructor(private router:Router) { } - - canActivate( - next: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable | Promise | boolean { - if (localStorage.getItem('authdata')) { - // logged in - return true; - } - - // not logged in - this.router.navigate(['/login'], { queryParams: {returnUrl: state.url}}); - return false; - } -} diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/authentication.service.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/authentication.service.ts deleted file mode 100644 index d7610eed0d..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/authentication.service.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import {Injectable} from '@angular/core'; -import {HttpClient} from "@angular/common/http"; -import {environment} from "../environments/environment"; - -@Injectable({ - providedIn: 'root' -}) -export class AuthenticationService { - - constructor(private http: HttpClient) { - } - - login(username: string, password: string) { - // remove old data from storage - localStorage.removeItem('authdata'); - // add to local storage - var authdata = window.btoa(username + ':' + password); - localStorage.setItem('authdata', authdata); - - // make request - return this.http.get(environment.authBackendURL); - } - - logout() { - // remove from local storage - localStorage.removeItem('authdata'); - } -} diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/basic-auth.interceptor.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/basic-auth.interceptor.ts deleted file mode 100644 index 4990d05ecb..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/basic-auth.interceptor.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import { Injectable } from '@angular/core'; -import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http'; -import { Observable } from 'rxjs'; - -@Injectable() -export class BasicAuthInterceptor implements HttpInterceptor { - intercept(request: HttpRequest, next: HttpHandler): Observable> { - //add authorization header with basic auth credentials if available - let auth = localStorage.getItem('authdata'); - if (auth) { - const authReq = request.clone({ - headers: request.headers.set('Authorization', 'Basic Z3VpOnBhc3N3b3JkMSQ=') - }); - - // send cloned request with header to the next handler. - return next.handle(authReq); - } - - return next.handle(request); - } -} diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/data.service.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/data.service.ts index 8dfae3da1e..b391672728 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/data.service.ts +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/data.service.ts @@ -21,7 +21,7 @@ SPDX-License-Identifier: Apache-2.0 */ import { Injectable } from '@angular/core'; -import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { BpmnInfraRequest } from './model/bpmnInfraRequest.model'; import { catchError } from 'rxjs/operators'; import { Observable } from 'rxjs'; diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/error.interceptor.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/error.interceptor.ts deleted file mode 100644 index afe792c80f..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/error.interceptor.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import { Injectable } from '@angular/core'; -import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } from '@angular/common/http'; -import { Observable, throwError } from 'rxjs'; -import { catchError } from 'rxjs/operators'; -import {AuthenticationService} from "./authentication.service"; - -@Injectable() -export class ErrorInterceptor implements HttpInterceptor { - constructor(private authenticationService: AuthenticationService) {} - - intercept(request: HttpRequest, next: HttpHandler): Observable> { - return next.handle(request).pipe(catchError(err => { - if (err.status === 401) { - // auto logout if 401 response returned from api - this.authenticationService.logout(); - location.reload(true); - } - - const error = err.error.message || err.statusText; - return throwError(error); - })) - } -} diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.html b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.html deleted file mode 100644 index 107e1da04a..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.html +++ /dev/null @@ -1,43 +0,0 @@ - -

Login

-
-
- - -
-
Username is required
-
-
-
- - -
-
Password is required
-
-
-
- - -
-
{{error}}
-
diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.spec.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.spec.ts deleted file mode 100644 index 8cf379d04f..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.spec.ts +++ /dev/null @@ -1,108 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import {async, ComponentFixture, inject, TestBed} from '@angular/core/testing'; - -import {LoginComponent} from './login.component'; -import {AuthenticationService} from "../authentication.service"; -import {CUSTOM_ELEMENTS_SCHEMA} from "@angular/core"; -import {FormsModule, ReactiveFormsModule} from '@angular/forms'; -import {RouterTestingModule} from "@angular/router/testing"; -import {ActivatedRoute, Router, RouterModule} from "@angular/router"; - -describe('LoginComponent', () => { - // Create SPY Object for Jasmine tests to mock DataService - let spyDataService: jasmine.SpyObj; - let component: LoginComponent; - let fixture: ComponentFixture; - let router: Router; - - beforeEach(async(() => { - spyDataService = jasmine.createSpyObj('AuthenticationService', ['login', 'logout']); - - TestBed.configureTestingModule({ - providers: [LoginComponent, - {provide: AuthenticationService, useValue: spyDataService}, - {provide: ActivatedRoute, useValue: { snapshot: {queryParams: { returnUrl: 'test'}}}} - ], - imports: [RouterTestingModule, ReactiveFormsModule, FormsModule, RouterModule.forRoot([])], - declarations: [LoginComponent], - schemas: [ - CUSTOM_ELEMENTS_SCHEMA - ] - }); - - fixture = TestBed.createComponent(LoginComponent); - component = fixture.componentInstance; - router = TestBed.get(Router); - })); - - - it('should create', inject([LoginComponent], - (component: LoginComponent) => { - expect(component).toBeTruthy(); - })); - - it('should logout and route to test directory', inject([LoginComponent], - (component: LoginComponent) => { - component.ngOnInit(); - expect(component.returnUrl).toBe('test'); - })); - - it('should logout and route to root directory', inject([LoginComponent], - (component: LoginComponent) => { - router.initialNavigation(); - component.ngOnInit(); - expect(component.returnUrl).toBe('test'); - })); - - it('should submit without success', inject([LoginComponent], - (component: LoginComponent) => { - component.ngOnInit(); - expect(component.loginForm.valid).toBe(false); - component.onSubmit(); - expect(component.submitted).toBe(true); - })); - - it('should submit without success', inject([LoginComponent], - (component: LoginComponent) => { - component.ngOnInit(); - expect(component.loginForm.valid).toBe(false); - spyDataService.login.and.returnValue(Promise.resolve()); - - let compiled = fixture.debugElement.nativeElement; - let username = compiled.querySelector('input[type="text"]'); - let password = compiled.querySelector('input[type="password"]'); - - fixture.detectChanges(); - - // Change value - username.value = 'test'; - password.value = 'password'; - - // dispatch input event - dispatchEvent(new Event('input')); - - component.onSubmit(); - expect(component.submitted).toBe(true); - })); -}); diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.ts deleted file mode 100644 index 4a3f4e6b0f..0000000000 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/login/login.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -/** - ============LICENSE_START======================================================= - Copyright (C) 2019 Samsung. All rights reserved. - ================================================================================ - Licensed 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. - - SPDX-License-Identifier: Apache-2.0 - ============LICENSE_END========================================================= - - @authors: k.kazak@samsung.com - **/ - -import { Component, OnInit } from '@angular/core'; -import {FormBuilder, FormGroup, Validators, ReactiveFormsModule} from "@angular/forms"; -import {ActivatedRoute, Router} from "@angular/router"; -import {AuthenticationService} from "../authentication.service"; -import {first} from "rxjs/internal/operators"; - -@Component({ - selector: 'app-login', - templateUrl: './login.component.html', - styleUrls: [] -}) -export class LoginComponent implements OnInit { - - loginForm: FormGroup; - loading = false; - submitted = false; - returnUrl: string; - error = ''; - - constructor(private formBuilder: FormBuilder, - private route: ActivatedRoute, - private router: Router, - private authenticationService: AuthenticationService) { } - - ngOnInit() { - this.loginForm = this.formBuilder.group({ - username: ['', Validators.required], - password: ['', Validators.required] - }); - - // logout - this.authenticationService.logout(); - - this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; - } - - // convenience getter for easy access to form fields - get f() { return this.loginForm.controls; } - - onSubmit() { - this.submitted = true; - - // stop here if form is invalid - if (this.loginForm.invalid) { - return; - } - - this.loading = true; - this.authenticationService.login(this.f.username.value, this.f.password.value) - .subscribe( - next => { - this.router.navigate([this.returnUrl]); - }, - error => { - this.error = error; - this.loading = false; - }); - } -} diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/sidebar/sidebar.component.html b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/sidebar/sidebar.component.html index 1c623518c7..e8b54d7ae3 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/sidebar/sidebar.component.html +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/src/app/sidebar/sidebar.component.html @@ -1,34 +1,29 @@ - - - + + + diff --git a/so-monitoring/so-monitoring-ui/src/main/frontend/src/environments/environment.ts b/so-monitoring/so-monitoring-ui/src/main/frontend/src/environments/environment.ts index 484a156fa9..f0c63fe582 100644 --- a/so-monitoring/so-monitoring-ui/src/main/frontend/src/environments/environment.ts +++ b/so-monitoring/so-monitoring-ui/src/main/frontend/src/environments/environment.ts @@ -1,8 +1,6 @@ /** ============LICENSE_START======================================================= Copyright (C) 2018 Ericsson. All rights reserved. -================================================================================ - Modifications Copyright (c) 2019 Samsung ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,6 +24,5 @@ SPDX-License-Identifier: Apache-2.0 export const environment = { production: false, - soMonitoringBackendURL: 'http://so-monitoring:30224/so/monitoring/', - authBackendURL: 'http://so-monitoring:30224/user' + soMonitoringBackendURL: 'http://so-monitoring:30224/so/monitoring/' }; -- cgit 1.2.3-korg