Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit ae8a4b1

Browse files
committed
modify static instances auth
1 parent 44ce95f commit ae8a4b1

File tree

6 files changed

+97
-108
lines changed

6 files changed

+97
-108
lines changed

src/alfrescoApi.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class AlfrescoApi {
7070

7171
this.storage = new Storage();
7272
this.config = new AlfrescoApiConfig(config);
73+
7374
this.clientsFactory();
7475

7576
this.processClient = new ProcessClient(this.config);
@@ -82,8 +83,19 @@ export class AlfrescoApi {
8283

8384
this.setAuthenticationClientECMBPM(this.oauth2Auth.getAuthentication(), this.oauth2Auth.getAuthentication());
8485
} else {
85-
this.processAuth = ProcessAuth.getInstance(this.config);
86-
this.contentAuth = ContentAuth.getInstance(this.config, this);
86+
87+
if (!this.processAuth) {
88+
this.processAuth = new ProcessAuth(this.config);
89+
} else {
90+
this.processAuth.setConfig(this.config);
91+
}
92+
93+
if (!this.contentAuth) {
94+
this.contentAuth = new ContentAuth(this.config, this);
95+
} else {
96+
this.contentAuth.setConfig(config);
97+
}
98+
8799
this.setAuthenticationClientECMBPM(this.contentAuth.getAuthentication(), this.processAuth.getAuthentication());
88100
}
89101

src/authentication/contentAuth.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const Emitter = _Emitter;
2727

2828
export class ContentAuth extends AlfrescoApiClient {
2929

30-
private static instance: ContentAuth = null;
31-
3230
config: AlfrescoApiConfig;
3331
basePath: string;
3432
ticketStorageLabel: string;
@@ -45,18 +43,9 @@ export class ContentAuth extends AlfrescoApiClient {
4543

4644
this.setConfig(config);
4745

48-
Emitter.call(this);
49-
}
46+
this.authApi = new AuthenticationApi(alfrescoApi);
5047

51-
static getInstance(config: AlfrescoApiConfig, alfrescoApi: AlfrescoApi): ContentAuth {
52-
if (!ContentAuth.instance) {
53-
ContentAuth.instance = new ContentAuth(config, alfrescoApi);
54-
} else {
55-
ContentAuth.instance.setConfig(config);
56-
}
57-
ContentAuth.instance.authApi = new AuthenticationApi(alfrescoApi);
58-
59-
return ContentAuth.instance;
48+
Emitter.call(this);
6049
}
6150

6251
setConfig(config: AlfrescoApiConfig) {

src/authentication/processAuth.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const Emitter = _Emitter;
2525

2626
export class ProcessAuth extends AlfrescoApiClient {
2727

28-
private static instance: ProcessAuth = null;
29-
3028
config: AlfrescoApiConfig;
3129
basePath: string;
3230
storage: Storage;
@@ -35,16 +33,6 @@ export class ProcessAuth extends AlfrescoApiClient {
3533
'basicAuth': { ticket: '' }, type: 'activiti'
3634
});
3735

38-
static getInstance(config: AlfrescoApiConfig): ProcessAuth {
39-
if (!ProcessAuth.instance) {
40-
ProcessAuth.instance = new ProcessAuth(config);
41-
} else {
42-
ProcessAuth.instance.setConfig(config);
43-
}
44-
45-
return ProcessAuth.instance;
46-
}
47-
4836
constructor(config: AlfrescoApiConfig) {
4937
super();
5038
this.className = 'ProcessAuth';

test/auth.spec.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ describe('Auth', function () {
3131
});
3232

3333
this.alfrescoJsApi.login('admin', 'admin').then((data) => {
34-
expect(data).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
35-
done();
36-
});
34+
expect(data).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
35+
done();
36+
});
3737
});
3838

3939
it('should return an error if wrong credential are used 403 the login fails', function (done) {
@@ -44,7 +44,7 @@ describe('Auth', function () {
4444
});
4545

4646
this.alfrescoJsApi.login('wrong', 'name').then(() => {
47-
}, (error) => {
47+
}, (error) => {
4848
expect(error.status).to.be.equal(403);
4949
done();
5050
});
@@ -59,7 +59,7 @@ describe('Auth', function () {
5959

6060
this.alfrescoJsApi.login(null, null).then(function () {
6161

62-
}, (error) => {
62+
}, (error) => {
6363
expect(error.status).to.be.equal(400);
6464
done();
6565
});
@@ -196,7 +196,7 @@ describe('Auth', function () {
196196
});
197197

198198
this.alfrescoJsApi.loginTicket(ticket).then((data) => {
199-
}, () => {
199+
}, () => {
200200
done();
201201
});
202202
});
@@ -212,7 +212,7 @@ describe('Auth', function () {
212212

213213
this.alfrescoJsApi.login('admin', 'admin').then(() => {
214214
done();
215-
}, () => {
215+
}, () => {
216216
});
217217
});
218218

@@ -223,14 +223,14 @@ describe('Auth', function () {
223223
expect(this.alfrescoJsApi.config.ticket).to.be.equal(undefined);
224224
expect(data).to.be.equal('logout');
225225
done();
226-
}, () => {
226+
}, () => {
227227
});
228228
});
229229

230230
it('should Logout be rejected if the Ticket is already expired', function (done) {
231231
this.authResponseEcmMock.get404ResponseLogout();
232232
this.alfrescoJsApi.logout().then(() => {
233-
}, (error) => {
233+
}, (error) => {
234234
expect(error.error.toString()).to.be.equal('Error: Not Found');
235235
done();
236236
});
@@ -247,14 +247,14 @@ describe('Auth', function () {
247247

248248
this.alfrescoJsApi.login('admin', 'admin').then(() => {
249249
done();
250-
}, () => {
250+
}, () => {
251251
});
252252
});
253253

254254
it('should 401 invalidate the ticket', function (done) {
255255
this.nodeMock.get401CreationFolder();
256256
this.alfrescoJsApi.nodes.createFolder('newFolder').then(() => {
257-
}, () => {
257+
}, () => {
258258
expect(this.alfrescoJsApi.contentAuth.authentications.basicAuth.password).to.be.equal(null);
259259
done();
260260
});
@@ -265,7 +265,7 @@ describe('Auth', function () {
265265
this.nodeMock.get401CreationFolder();
266266

267267
this.alfrescoJsApi.nodes.createFolder('newFolder').then(() => {
268-
}, () => {
268+
}, () => {
269269
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(false);
270270
done();
271271
});
@@ -310,7 +310,7 @@ describe('Auth', function () {
310310
this.alfrescoJsApi.login('admin', 'admin').then((data) => {
311311
expect(data).to.be.equal('Basic YWRtaW46YWRtaW4=');
312312
done();
313-
}, function (error) {
313+
}, function (error) {
314314
console.log('error' + JSON.stringify(error));
315315
});
316316
});
@@ -325,7 +325,7 @@ describe('Auth', function () {
325325

326326
this.alfrescoJsApi.login('wrong', 'name').then(() => {
327327

328-
}, (error) => {
328+
}, (error) => {
329329
expect(error.status).to.be.equal(401);
330330
done();
331331
});
@@ -341,7 +341,7 @@ describe('Auth', function () {
341341

342342
this.alfrescoJsApi.login(null, null).then(function () {
343343

344-
}, function (error) {
344+
}, function (error) {
345345
expect(error.status).to.be.equal(400);
346346
done();
347347
});
@@ -362,7 +362,7 @@ describe('Auth', function () {
362362
this.alfrescoJsApi.login('admin', 'admin').then(() => {
363363
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(true);
364364
done();
365-
}, function () {
365+
}, function () {
366366
});
367367
});
368368

@@ -382,7 +382,7 @@ describe('Auth', function () {
382382
this.alfrescoJsApi.logout().then(() => {
383383
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(false);
384384
done();
385-
}, function () {
385+
}, function () {
386386
});
387387
});
388388
});
@@ -460,15 +460,15 @@ describe('Auth', function () {
460460

461461
this.alfrescoJsApi.login('admin', 'admin').then(() => {
462462
done();
463-
}, () => {
463+
}, () => {
464464
});
465465
});
466466

467467
it('should 401 invalidate the ticket', function (done) {
468468
this.profileMock.get401getProfile();
469469

470470
this.alfrescoJsApi.activiti.profileApi.getProfile().then((data) => {
471-
}, () => {
471+
}, () => {
472472
expect(this.alfrescoJsApi.processAuth.authentications.basicAuth.ticket).to.be.equal(null);
473473
done();
474474
});
@@ -479,7 +479,7 @@ describe('Auth', function () {
479479
this.profileMock.get401getProfile();
480480

481481
this.alfrescoJsApi.activiti.profileApi.getProfile().then((data) => {
482-
}, () => {
482+
}, () => {
483483
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(false);
484484
done();
485485
});
@@ -535,7 +535,7 @@ describe('Auth', function () {
535535
expect(data[0]).to.be.equal('TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1');
536536
expect(data[1]).to.be.equal('Basic YWRtaW46YWRtaW4=');
537537
done();
538-
}, function () {
538+
}, function () {
539539
});
540540
});
541541

@@ -551,7 +551,7 @@ describe('Auth', function () {
551551
});
552552

553553
this.alfrescoJsApi.login('admin', 'admin').then(function () {
554-
}, function () {
554+
}, function () {
555555
done();
556556
});
557557

@@ -570,7 +570,7 @@ describe('Auth', function () {
570570
});
571571

572572
this.alfrescoJsApi.login('admin', 'admin').then(function () {
573-
}, function () {
573+
}, function () {
574574
done();
575575
});
576576

@@ -599,7 +599,7 @@ describe('Auth', function () {
599599
this.alfrescoJsApi.logout().then(() => {
600600
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(false);
601601
done();
602-
}, function () {
602+
}, function () {
603603
});
604604
});
605605

@@ -616,7 +616,7 @@ describe('Auth', function () {
616616

617617
this.alfrescoJsApi.login('wrong', 'name').then(function () {
618618

619-
}, function (error) {
619+
}, function (error) {
620620
expect(error.status).to.be.equal(401);
621621
done();
622622
});
@@ -634,7 +634,7 @@ describe('Auth', function () {
634634

635635
this.alfrescoJsApi.login(null, null).then(function () {
636636

637-
}, function (error) {
637+
}, function (error) {
638638
expect(error.status).to.be.equal(400);
639639
done();
640640
});
@@ -656,7 +656,7 @@ describe('Auth', function () {
656656
this.alfrescoJsApi.login('admin', 'admin').then(() => {
657657
expect(this.alfrescoJsApi.isLoggedIn()).to.be.equal(true);
658658
done();
659-
}, function () {
659+
}, function () {
660660
});
661661
});
662662

0 commit comments

Comments
 (0)