Fix login errors with the BASIC authentication

This commit is contained in:
Amedeo Lepore
2023-07-10 18:22:09 +02:00
committed by eromano
parent cbb501155f
commit 4232d04c2e
6 changed files with 14 additions and 13 deletions

View File

@@ -22,7 +22,7 @@ import { Authentication } from '../authentication';
import { AuthenticationInterceptor, SHOULD_ADD_AUTH_TOKEN } from './authentication.interceptor'; import { AuthenticationInterceptor, SHOULD_ADD_AUTH_TOKEN } from './authentication.interceptor';
class MockAuthentication extends Authentication { class MockAuthentication extends Authentication {
addTokenToHeader(httpHeaders: HttpHeaders): Observable<HttpHeaders> { addTokenToHeader(_: string, httpHeaders: HttpHeaders): Observable<HttpHeaders> {
return of(httpHeaders); return of(httpHeaders);
} }
} }

View File

@@ -43,7 +43,7 @@ export class AuthenticationInterceptor implements HttpInterceptor {
Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> { Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> {
if (req.context.get(SHOULD_ADD_AUTH_TOKEN)) { if (req.context.get(SHOULD_ADD_AUTH_TOKEN)) {
return this.authService.addTokenToHeader(req.headers).pipe( return this.authService.addTokenToHeader(req.url, req.headers).pipe(
mergeMap((headersWithBearer) => { mergeMap((headersWithBearer) => {
const headerWithContentType = this.appendJsonContentType(headersWithBearer); const headerWithContentType = this.appendJsonContentType(headersWithBearer);
const kcReq = req.clone({ headers: headerWithContentType}); const kcReq = req.clone({ headers: headerWithContentType});

View File

@@ -19,5 +19,5 @@ import { HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
export abstract class Authentication { export abstract class Authentication {
public abstract addTokenToHeader(headers: HttpHeaders): Observable<HttpHeaders>; public abstract addTokenToHeader(requestUrl: string, headers: HttpHeaders): Observable<HttpHeaders>;
} }

View File

@@ -21,7 +21,7 @@ import { Authentication } from '../interfaces/authentication.interface';
import { CookieService } from '../../common/services/cookie.service'; import { CookieService } from '../../common/services/cookie.service';
import { ContentAuth } from './content-auth'; import { ContentAuth } from './content-auth';
import { ProcessAuth } from './process-auth'; import { ProcessAuth } from './process-auth';
import { map } from 'rxjs/operators'; import { catchError, map } from 'rxjs/operators';
import { from, Observable } from 'rxjs'; import { from, Observable } from 'rxjs';
import { RedirectionModel } from '../models/redirection.model'; import { RedirectionModel } from '../models/redirection.model';
import { BaseAuthenticationService } from '../services/base-authentication.service'; import { BaseAuthenticationService } from '../services/base-authentication.service';
@@ -97,7 +97,8 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
type: this.appConfig.get(AppConfigValues.PROVIDERS), type: this.appConfig.get(AppConfigValues.PROVIDERS),
ticket: response ticket: response
}; };
}) }),
catchError((err) => this.handleError(err))
); );
} }
@@ -337,8 +338,8 @@ export class BasicAlfrescoAuthService extends BaseAuthenticationService {
private getTicketEcmBase64(requestUrl: string): string | null { private getTicketEcmBase64(requestUrl: string): string | null {
let ticket = null; let ticket = null;
const contextRootBpm = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM); const contextRootBpm = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTBPM) || 'activiti-app';
const contextRoot = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM); const contextRoot = this.appConfig.get<string>(AppConfigValues.CONTEXTROOTECM) || 'alfresco';
if (contextRoot && requestUrl.indexOf(contextRoot) !== -1) { if (contextRoot && requestUrl.indexOf(contextRoot) !== -1) {
ticket = 'Basic ' + btoa(this.contentAuth.getToken()); ticket = 'Basic ' + btoa(this.contentAuth.getToken());

View File

@@ -109,13 +109,13 @@ export class ContentAuth {
.catch((error) => { .catch((error) => {
this.saveUsername(''); this.saveUsername('');
if (error.status === 401) { if (error.status === 401) {
this.adfHttpClient.emit('unauthorized'); this.adfHttpClient.emit('unauthorized', error);
this.onError.next('unauthorized'); this.onError.next('unauthorized');
} else if (error.status === 403) { } else if (error.status === 403) {
this.adfHttpClient.emit('forbidden'); this.adfHttpClient.emit('forbidden', error);
this.onError.next('forbidden'); this.onError.next('forbidden');
} else { } else {
this.adfHttpClient.emit('error'); this.adfHttpClient.emit('error', error);
this.onError.next('error'); this.onError.next('error');
} }
reject(error); reject(error);

View File

@@ -105,13 +105,13 @@ export class ProcessAuth {
(error) => { (error) => {
this.saveUsername(''); this.saveUsername('');
if (error.status === 401) { if (error.status === 401) {
this.adfHttpClient.emit('unauthorized'); this.adfHttpClient.emit('unauthorized', error);
this.onError.next('unauthorized'); this.onError.next('unauthorized');
} else if (error.status === 403) { } else if (error.status === 403) {
this.adfHttpClient.emit('forbidden'); this.adfHttpClient.emit('forbidden', error);
this.onError.next('forbidden'); this.onError.next('forbidden');
} else { } else {
this.adfHttpClient.emit('error'); this.adfHttpClient.emit('error', error);
this.onError.next('error'); this.onError.next('error');
} }
reject(error); reject(error);