mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
integrate new login bpm modify and change token to ticket
This commit is contained in:
parent
e57ff04e4f
commit
8c84bc9be5
@ -26,8 +26,7 @@ export interface AbstractAuthentication {
|
||||
|
||||
isLoggedIn(): boolean ;
|
||||
|
||||
getToken(): string;
|
||||
|
||||
saveToken(): void;
|
||||
getTicket(): string;
|
||||
|
||||
saveTicket(ticket: any): void;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
|
||||
export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
|
||||
|
||||
TYPE: string = 'BPM';
|
||||
private token: string;
|
||||
|
||||
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
|
||||
private http: Http) {
|
||||
@ -41,9 +40,8 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
|
||||
login(username: string, password: string): Observable<any> {
|
||||
return Observable.fromPromise(this.apiActivitiLogin(username, password))
|
||||
.map((response: any) => {
|
||||
this.token = response.status;
|
||||
return this.token;
|
||||
// return {name: this.TYPE, token: response.status};
|
||||
this.saveTicket(response.status);
|
||||
return response.status;
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
@ -57,7 +55,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
|
||||
return Observable.fromPromise(this.apiActivitiLogout())
|
||||
.map(res => <any> res)
|
||||
.do(response => {
|
||||
this.removeToken(this.TYPE);
|
||||
this.removeTicket(this.TYPE);
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
@ -67,7 +65,7 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoggedIn(): boolean {
|
||||
return !!this.getToken();
|
||||
return !!this.getTicket();
|
||||
}
|
||||
|
||||
private apiActivitiLogin(username: string, password: string) {
|
||||
@ -91,17 +89,17 @@ export class AlfrescoAuthenticationBPM extends AlfrescoAuthenticationBase implem
|
||||
return this.http.get(url).toPromise();
|
||||
}
|
||||
|
||||
public getToken (): string {
|
||||
return localStorage.getItem(`token-${this.TYPE}`);
|
||||
public getTicket(): string {
|
||||
return localStorage.getItem(`ticket-${this.TYPE}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method save the toke in the localStorage
|
||||
* @param token
|
||||
* The method save the ticket in the localStorage
|
||||
* @param ticket
|
||||
*/
|
||||
public saveToken(): void {
|
||||
if (this.token) {
|
||||
super.saveToken(this.TYPE, this.token);
|
||||
public saveTicket(ticket): void {
|
||||
if (ticket) {
|
||||
super.saveTicket(this.TYPE, ticket);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,19 +40,19 @@ export class AlfrescoAuthenticationBase {
|
||||
|
||||
/**
|
||||
* The method save the toke in the localStorage
|
||||
* @param token
|
||||
* @param ticket
|
||||
*/
|
||||
public saveToken(provider:string, token: string): void {
|
||||
if (token) {
|
||||
localStorage.setItem(`token-${provider}`, token);
|
||||
public saveTicket(provider:string, ticket: string): void {
|
||||
if (ticket) {
|
||||
localStorage.setItem(`ticket-${provider}`, ticket);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the login token from localStorage
|
||||
* Remove the login ticket from localStorage
|
||||
*/
|
||||
public removeToken(provider:string): void {
|
||||
localStorage.removeItem(`token-${provider}`);
|
||||
public removeTicket(provider:string): void {
|
||||
localStorage.removeItem(`ticket-${provider}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,84 +26,97 @@ declare let AlfrescoApi: any;
|
||||
export class AlfrescoAuthenticationECM extends AlfrescoAuthenticationBase implements AbstractAuthentication {
|
||||
|
||||
TYPE: string = 'ECM';
|
||||
private token: string;
|
||||
|
||||
alfrescoApi: any;
|
||||
/**
|
||||
* Constructor
|
||||
* @param alfrescoSettingsService
|
||||
*/
|
||||
constructor(private alfrescoSettingsService: AlfrescoSettingsService,
|
||||
private http: Http) {
|
||||
super(alfrescoSettingsService, http);
|
||||
|
||||
if (!this.isLoggedIn) {
|
||||
this.alfrescoApi = new AlfrescoApi({
|
||||
host: this.getBaseUrl()
|
||||
});
|
||||
} else {
|
||||
this.alfrescoApi = new AlfrescoApi({
|
||||
ticket: this.getTicket(),
|
||||
host: this.getBaseUrl()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getBaseUrl(): string {
|
||||
return this.alfrescoSettingsService.host;
|
||||
}
|
||||
|
||||
getAlfrescoApi(): any {
|
||||
return this.alfrescoApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a login on behalf of the user and store the ticket returned
|
||||
*
|
||||
* The method return tru if the user is logged in
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isLoggedIn(): boolean {
|
||||
return !!this.getTicket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delegate to POST login
|
||||
* @param username
|
||||
* @param password
|
||||
* @returns {Observable<R>|Observable<T>}
|
||||
*/
|
||||
login(username: string, password: string): Observable<any> {
|
||||
return Observable.fromPromise(this.getCreateTicketPromise(username, password))
|
||||
.map((response: any) => {
|
||||
this.token = response.entry.id;
|
||||
return this.token;
|
||||
// return {name: this.TYPE, token: response.entry.id};
|
||||
login(username: string, password: string) {
|
||||
this.alfrescoApi = new AlfrescoApi({
|
||||
username: username,
|
||||
password: password,
|
||||
host: this.getBaseUrl()
|
||||
});
|
||||
|
||||
return Observable.fromPromise(this.alfrescoApi.login())
|
||||
.map(res => <any> res)
|
||||
.do(response => {
|
||||
this.saveTicket(response);
|
||||
return response;
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the current login ticket from the server
|
||||
* The method remove the ticket from the local storage
|
||||
*
|
||||
* @returns {Observable<R>|Observable<T>}
|
||||
*/
|
||||
logout() {
|
||||
return Observable.fromPromise(this.getDeleteTicketPromise())
|
||||
public logout() {
|
||||
return Observable.fromPromise(this.alfrescoApi.logout())
|
||||
.map(res => <any> res)
|
||||
.do(response => {
|
||||
this.removeToken(this.TYPE);
|
||||
this.removeTicket(this.TYPE);
|
||||
return response;
|
||||
})
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The method return true if the user is logged in
|
||||
* @returns {boolean}
|
||||
* The method return the ticket stored in the localStorage
|
||||
* @returns ticket
|
||||
*/
|
||||
isLoggedIn(): boolean {
|
||||
return !!this.getToken();
|
||||
}
|
||||
|
||||
private getAlfrescoClient() {
|
||||
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getToken());
|
||||
}
|
||||
|
||||
private getCreateTicketPromise(username: string, password: string) {
|
||||
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
|
||||
let loginRequest = new AlfrescoApi.Auth.LoginRequest();
|
||||
loginRequest.userId = username;
|
||||
loginRequest.password = password;
|
||||
return apiInstance.createTicket(loginRequest);
|
||||
}
|
||||
|
||||
private getDeleteTicketPromise() {
|
||||
let apiInstance = new AlfrescoApi.Auth.AuthenticationApi(this.getAlfrescoClient());
|
||||
return apiInstance.deleteTicket();
|
||||
public getTicket(): string {
|
||||
return localStorage.getItem(`ticket-${this.TYPE}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method return the token stored in the localStorage
|
||||
* @param token
|
||||
* The method save the ticket in the localStorage
|
||||
* @param ticket
|
||||
*/
|
||||
public getToken (): string {
|
||||
return localStorage.getItem(`token-${this.TYPE}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method save the toke in the localStorage
|
||||
* @param token
|
||||
*/
|
||||
public saveToken(): void {
|
||||
if (this.token) {
|
||||
super.saveToken(this.TYPE, this.token);
|
||||
public saveTicket(ticket): void {
|
||||
if (ticket) {
|
||||
super.saveTicket(this.TYPE, ticket);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ describe('AlfrescoContentService', () => {
|
||||
AlfrescoSettingsService
|
||||
]);
|
||||
spyOn(localStorage, 'getItem').and.callFake(function (key) {
|
||||
return 'myToken';
|
||||
return 'myTicket';
|
||||
});
|
||||
service = injector.get(AlfrescoContentService);
|
||||
authService = injector.get(AlfrescoAuthenticationService);
|
||||
@ -49,7 +49,7 @@ describe('AlfrescoContentService', () => {
|
||||
})).toBe(
|
||||
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
|
||||
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
|
||||
'?attachment=false&alf_ticket=' + authService.getToken()
|
||||
'?attachment=false&alf_ticket=' + authService.getTicket()
|
||||
);
|
||||
});
|
||||
|
||||
@ -61,7 +61,7 @@ describe('AlfrescoContentService', () => {
|
||||
})).toBe(
|
||||
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH +
|
||||
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
|
||||
'?attachment=false&alf_ticket=' + authService.getToken()
|
||||
'?attachment=false&alf_ticket=' + authService.getTicket()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -28,18 +28,21 @@ import {
|
||||
|
||||
@Component({
|
||||
selector: 'my-app',
|
||||
template: `<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
||||
template: `
|
||||
<label for="token"><b>Insert the ip of your Alfresco instance:</b></label><br>
|
||||
<input id="token" type="text" size="48" (change)="updateHost()" [(ngModel)]="host"><br><br>
|
||||
<div style="border-radius: 8px; position: absolute; background-color: papayawhip; color: cadetblue; left: 10px; top: 120px; z-index: 1;">
|
||||
<p style="width:120px;margin: 20px;">
|
||||
<label for="switch1" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input type="checkbox" id="switch1" class="mdl-switch__input" checked (click)="toggleECM(ecm.checked)" #ecm>
|
||||
<input type="checkbox" id="switch1" class="mdl-switch__input" checked
|
||||
(click)="toggleECM(ecm.checked)" #ecm>
|
||||
<span class="mdl-switch__label">ECM</span>
|
||||
</label>
|
||||
</p>
|
||||
<p style="width:120px;margin: 20px;">
|
||||
<label for="switch2" class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
|
||||
<input type="checkbox" id="switch2" class="mdl-switch__input" (click)="toggleBPM(bpm.checked)" #bpm>
|
||||
<input type="checkbox" id="switch2" class="mdl-switch__input"
|
||||
(click)="toggleBPM(bpm.checked)" #bpm>
|
||||
<span class="mdl-switch__label">BPM</span>
|
||||
</label>
|
||||
</p>
|
||||
|
@ -26,7 +26,7 @@
|
||||
"label-undefined": true,
|
||||
"max-line-length": [
|
||||
true,
|
||||
140
|
||||
180
|
||||
],
|
||||
"member-ordering": [
|
||||
true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user