cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic login ADF

saul79
Champ on-the-rise
Champ on-the-rise

Hi,

I have have an application (angular 7 and adf 3.2.1 libraries). I use the login component and prevent the default code from executing in the validate form.

My problem is that i have to log in users when i don't know where they have access to and redirect them based on that .

I reach the point were i have the tickets in my instance and i tried to redirect the user based on that but it doesn`t work. I tried to show the state from the auth service and i saw that the user is not logued in on the service . 

validateForm($event) {
let username = $event.values.controls.username.value;
let password = $event.values.controls.username.parent.value.password;
this.alfrescoApi.getInstance().config.provider = 'ECM';
this.alfrescoApi.getInstance().contentAuth.config.provider = 'ECM';
let promesaContentAuth = this.alfrescoApi.getInstance().login(username,password).then( success => {
this.loginECM = true;
console.log(success);
return success;
}, error => {
this.loginECM = false;
})
/* let promesaContentAuth = this.alfrescoApi.getInstance().contentAuth.login(username,password).then( success => {
this.loginECM = true;
}, error => {
this.loginECM = false;
}) */

this.alfrescoApi.getInstance().processAuth.config.provider = 'BPM';
this.alfrescoApi.getInstance().config.provider = 'BPM';
let promesaProcessAuth = this.alfrescoApi.getInstance().login(username,password).then( success => {
console.log(success);
this.loginBPM = true;
return success;
}, error => {
this.loginBPM = false;
});
/* let promesaProcessAuth = this.alfrescoApi.getInstance().processAuth.login(username,password).then( success => {
this.loginBPM = true;
}, error => {
this.loginBPM = false;
}); */
this.login(promiseContentAuth,promiseProcessAuth);

$event.preventDefault();
}
login(promesaContentAuth,promesaProcessAuth){
Promise.all( [promiseContentAuth,promiseProcessAuth] ).then( success =>{
this.storage.setItem("ticket-ECM",success[0]);
this.storage.setItem("ticket-BPM",success[1]);
if( this.loginECM && this.loginBPM ){
console.log("all");
this.alfrescoApi.getInstance().contentAuth.config.provider = 'ALL';
this.alfrescoApi.getInstance().processAuth.config.provider = 'ALL';
this.alfrescoApi.getInstance().config.provider = 'ALL';
this.alfrescoApi.lastConfig.provider= 'ALL';
this.router.navigate(['content/documentlist']);
}else if( this.loginECM ){
console.log("ecm");
this.alfrescoApi.getInstance().contentAuth.config.provider = 'ECM';
this.alfrescoApi.getInstance().processAuth.config.provider = 'ECM';
this.alfrescoApi.getInstance().config.provider = 'ECM';
this.alfrescoApi.lastConfig.provider= 'ECM';
this.router.navigate(['content/documentlist']);
}else if( this.loginBPM ) {
console.log("bpm");
this.alfrescoApi.getInstance().contentAuth.config.provider = 'BPM';
this.alfrescoApi.getInstance().processAuth.config.provider = 'BPM';
this.alfrescoApi.getInstance().config.provider = 'BPM';
this.alfrescoApi.lastConfig.provider= 'BPM';
this.router.navigate(['apps']);
}
},error => {
console.error("promiseErr ="+error);
})

}
1 ACCEPTED ANSWER

saul79
Champ on-the-rise
Champ on-the-rise
validateForm($event) {
let username = $event.values.controls.username.value;
let password = $event.values.controls.username.parent.value.password;
this.login(username,password);
$event.preventDefault();
}

login(username,password){
let promise1 = this.logUser("ECM",username, password).then( success => {
this.loginECM = true;
}, error => {
console.log(error);
}
)
let promise2 = this.logUser("BPM",username, password).then( success => {
this.loginBPM = true;
}, error => {
}
);
Promise.all( [promise1 ,promise2 ] ).then( success =>{
this.authService.alfrescoApi.getInstance().setAuthenticationClientECMBPM(this.authService.alfrescoApi.getInstance().contentAuth.getAuthentication(), this.authService.alfrescoApi.getInstance().processAuth.getAuthentication());
if(this.loginECM && this.loginBPM ){
this.authService.setRedirect({provider:'ALL',url:'/content/documentlist'});
this.changeProvider("ALL");
this.storage.setItem("providers","ALL");
}
else if(this.loginECM){
this.authService.setRedirect({provider:'ECM',url:'/content/documentlist'});
this.changeProvider("ECM");
this.storage.setItem("providers","ECM");
}else if(this.loginBPM){
this.authService.setRedirect({provider:'BPM',url:'/apps'});
this.changeProvider("BPM");
this.storage.setItem("providers","BPM");
}else {
this.alfrescologin.errorMsg = "No se han reconocido los datos de autenticación o el servicio no esta disponible ";
this.alfrescologin.isError = true;
}
let redirectUrl = this.authService.getRedirect();
if (redirectUrl) {
this.authService.setRedirect(null);
this.router.navigateByUrl(redirectUrl);
}else{
}
}
,error => {
}
)
}

logUser(provider,username, password) {
this.changeProvider(provider);
this.changeDetector.detectChanges();
return this.authService
.login(username, password, true).toPromise();
}

changeProvider(provider){
this.alfrescoApi.getInstance().contentAuth.config.provider = provider;
this.alfrescoApi.getInstance().processAuth.config.provider = provider;
this.alfrescoApi.getInstance().config.provider = provider;
this.alfrescoApi.lastConfig.provider = provider;
this.appConfig.config.providers = provider;
}

I was able to find a solution to the problem, i modified the authservice  and set alfrescoApi public so i can get access to ithe instance in the service and coud use the next method, without this method the login succeed but it gives you an error of a cookie when you try to access to the bpm.

Method necesary:

this.authService.alfrescoApi.getInstance().setAuthenticationClientECMBPM()

View answer in original post

1 REPLY 1

saul79
Champ on-the-rise
Champ on-the-rise
validateForm($event) {
let username = $event.values.controls.username.value;
let password = $event.values.controls.username.parent.value.password;
this.login(username,password);
$event.preventDefault();
}

login(username,password){
let promise1 = this.logUser("ECM",username, password).then( success => {
this.loginECM = true;
}, error => {
console.log(error);
}
)
let promise2 = this.logUser("BPM",username, password).then( success => {
this.loginBPM = true;
}, error => {
}
);
Promise.all( [promise1 ,promise2 ] ).then( success =>{
this.authService.alfrescoApi.getInstance().setAuthenticationClientECMBPM(this.authService.alfrescoApi.getInstance().contentAuth.getAuthentication(), this.authService.alfrescoApi.getInstance().processAuth.getAuthentication());
if(this.loginECM && this.loginBPM ){
this.authService.setRedirect({provider:'ALL',url:'/content/documentlist'});
this.changeProvider("ALL");
this.storage.setItem("providers","ALL");
}
else if(this.loginECM){
this.authService.setRedirect({provider:'ECM',url:'/content/documentlist'});
this.changeProvider("ECM");
this.storage.setItem("providers","ECM");
}else if(this.loginBPM){
this.authService.setRedirect({provider:'BPM',url:'/apps'});
this.changeProvider("BPM");
this.storage.setItem("providers","BPM");
}else {
this.alfrescologin.errorMsg = "No se han reconocido los datos de autenticación o el servicio no esta disponible ";
this.alfrescologin.isError = true;
}
let redirectUrl = this.authService.getRedirect();
if (redirectUrl) {
this.authService.setRedirect(null);
this.router.navigateByUrl(redirectUrl);
}else{
}
}
,error => {
}
)
}

logUser(provider,username, password) {
this.changeProvider(provider);
this.changeDetector.detectChanges();
return this.authService
.login(username, password, true).toPromise();
}

changeProvider(provider){
this.alfrescoApi.getInstance().contentAuth.config.provider = provider;
this.alfrescoApi.getInstance().processAuth.config.provider = provider;
this.alfrescoApi.getInstance().config.provider = provider;
this.alfrescoApi.lastConfig.provider = provider;
this.appConfig.config.providers = provider;
}

I was able to find a solution to the problem, i modified the authservice  and set alfrescoApi public so i can get access to ithe instance in the service and coud use the next method, without this method the login succeed but it gives you an error of a cookie when you try to access to the bpm.

Method necesary:

this.authService.alfrescoApi.getInstance().setAuthenticationClientECMBPM()