2016-06-15 5 views
0

私はアダプターの承認とチャレンジを受けたibmモバイルの最初のアプリケーションを開発しました。アンドロイド環境を追加し、プロダクションサーバーに対してテストしたいので、devのタブレットにapkをデプロイしました。クライアントの登録に失敗しました

私は、リモートアダプタを呼び出そうとすると、コードワイドメソッド "WLAuthorizationManagerPlugingetClientInstanceIdHeader"を実行してClientInstanceIdを取得しようとしています。このリクエストの結果は常にタイムアウトになり、コンソールでは1つの新しいentruを見ることができます:「キャッチされていない(アダプター通信エラー)」。このメソッドは "WL.Logger.debug( 'Client registration failed with error:' + JSON.stringify(error));"で終了します。

編集:ログインフロー:

ログインの実装:

import {UserModel} from 'app-user'; 
import {UserService} from 'app-user-service'; 
import {AppSettingsService} from 'app-settings'; 
import {AppMasterDataService} from "../master-data/app-master-data-service"; 
import jsSha from 'js-sha'; 
import {UserRepository} from "user-repository"; 
import {NetworkInformation} from  ../../infrastructure/phonegap/plugins/network-information'; 

export class LoggedInUser{ 
public static inject = [UserService, AppSettingsService,  AppMasterDataService, UserRepository]; 

public info: UserModel; 

public isLoggedIn: boolean; 

private singleStepAuthRealmChallengeHandler: any; 

private _getUserInfoPromise: Promise<UserModel>; 

private _listeners: Array<(success: boolean, error: string) => void> = []; 

private lastCredentials: any; 

constructor(private _userService: UserService, private _settingsService: AppSettingsService, private _masterDataService: AppMasterDataService, private _userRepo: UserRepository){ 
if(typeof WL != "undefined"){ 
    this.singleStepAuthRealmChallengeHandler = WL.Client.createChallengeHandler('GicarAuthRealm'); 
    this.singleStepAuthRealmChallengeHandler.isCustomResponse = this.isCustomResponse.bind(this); 
    this.singleStepAuthRealmChallengeHandler.handleChallenge = this.handleChallenge.bind(this); 
} 
} 

public async initializeUserInfo(): Promise<void>{ 
    return this.executeLogOut(null, null); 
} 

public addLoginEventListener(callback: (success: boolean, error: string) => void){ 
if(!this._listeners.some(x => x === callback)){ 
    this._listeners.push(callback); 
} 
} 
public removeLoginEventListener(callback: (success: boolean, error: string) => void){ 
let index = this._listeners.indexOf(callback); 
if(index >= 0){ 
    this._listeners.splice(index, 1); 
} 
} 

private raiseLoginEvent(success: boolean, error?: string){ 
for (var listener of this._listeners){ 
    try { 
    listener(success, error); 
    }catch (e){ 
    this.removeLoginEventListener(listener); 
    } 
} 
} 
public prepareLogin(){ 
    if(NetworkInformation.connected()) 
    this._getUserInfoPromise = this._userService.getUserInfo(); 
} 

public async executeLogIn(userName: string, password: string){//: Promise<boolean>{ 
await this.executeLogOut(userName, password); 
if(this.singleStepAuthRealmChallengeHandler){ 
    if(NetworkInformation.connected()){ 
    var userNameSha = new jsSha("SHA-512", "TEXT"); 
    userNameSha.update(userName); 
    var userNameHash = userNameSha.getHash("B64"); 

    var passwordSha = new jsSha("SHA-512", "TEXT"); 
    passwordSha.update(password); 
    var passwordHash = passwordSha.getHash("B64"); 

    this.lastCredentials = { 
     userName: userNameHash, 
     password: passwordHash 
    }; 
    var invocationData = { 
     adapter : "GicarAuthAdapter", 
     procedure : "submitAuthentication", 
     parameters : [ userName, window.btoa(userName + ':' + password) ] 
    }; 
    this.singleStepAuthRealmChallengeHandler.submitAdapterAuthentication(invocationData); 
    }else { 
    this.doDisconnectedLogin(userName, password); 
    } 

} 
else{ 
    this._userService.logIn(userName, password) 
    .then(info =>{ 
    this.info = info; 
    this.isLoggedIn = typeof info !== 'undefined' && info != null; 
    this.raiseLoginEvent(this.isLoggedIn); 
    }).catch(e =>{ 
    this.isLoggedIn = false; 
    this.info = null; 
    this.raiseLoginEvent(false, e.message ? e.message : e.toString()) 
    }); 
} 
} 

private async doDisconnectedLogin(userName: string, password: string){ 
var userNameSha = new jsSha("SHA-512", "TEXT"); 
userNameSha.update(userName); 
var userNameHash = userNameSha.getHash("B64"); 

var passwordSha = new jsSha("SHA-512", "TEXT"); 
passwordSha.update(password); 
var passwordHash = passwordSha.getHash("B64"); 

var persisted = await this._userRepo.findUserByUserName(userNameHash); 
let success = persisted && persisted.password == passwordHash; 
this.info = persisted; 
this.isLoggedIn = success; 
this.raiseLoginEvent(success, success ? null : 'user-invalid-credentials'); 
} 

public executeLogOut(userName: string, password: string): Promise<void>{ 
this.lastCredentials = null; 
if(NetworkInformation.connected()){ 
    return this._userService.logOut(this.info).then(() =>{ 
    this.isLoggedIn = false; 
    this.info = null; 
    }); 
} 
else 
    return Promise.resolve(); 

} 

private isCustomResponse(response: any): boolean{ 
if (!response || !response.responseJSON || response.responseText === null) { 
    return false; 
} 
if (typeof(response.responseJSON.authRequired) !== 'undefined'){ 
    return true; 
} else { 
    return false; 
} 
} 

private async handleChallenge(response: JQueryXHR){ 
var authRequired = response.responseJSON.authRequired; 
if(authRequired == true){ 
    this.info == null; 
    this.raiseLoginEvent(false, response.responseJSON.errorMessage); 
}else { 
    try { 
    if(this.info == null){ 
     this.singleStepAuthRealmChallengeHandler.submitSuccess(); 
     this.info = await this._getUserInfoPromise; 
     await this._masterDataService.initializeMasterData(false); 
     if(this.lastCredentials){ 
     await this._userRepo.saveUser({ 
      entityId: this.lastCredentials.userName, 
      firstName: this.info.firstName, 
      lastName: this.info.lastName, 
      fullName: this.info.fullName, 
      email: this.info.email, 
      nif: this.info.nif, 
      address: this.info.address, 
      userName: this.lastCredentials.userName, 
      password: this.lastCredentials.password 
     }); 
     } 
     this.isLoggedIn = true; 
     this.raiseLoginEvent(true); 
    } 

    }catch (error){ 
    this.raiseLoginEvent(false, error.message ? error.message : error.toString()); 
    } 
} 
} 
} 
+0

実装を追加する必要があると思います。 –

+0

どういう意味ですか? –

+0

認証フローで使用しているコード。 –

答えて

0

私は問題を発見したと思います。

desktopbrowserの1を含むいくつかの環境をサポートするために、私は "古い" 方法で使用してMFPアダプタを呼んでいる:

var resourceRequest = new WLResourceRequest("/adapters/UserServiceAdapter/getUserInfo", WLResourceRequest.GET, 30000); 
    resourceRequest.send().then(
    handleSuccess, 
    handleFailure 
); 

:私がして、コードの上に交換した場合、 `

WL.Client.invokeProcedure({ 
    adapter: "UserServiceAdapter", 
    procedure: 'getUserInfo' 
    parameters: [], 
    compressResponse: false 
    },{ 
    timeout:30000, 
    onSuccess: handleSuccess, 
    onFailure: handleFailure 
    }); 

をAndroid上で正常に動作しています。

アダプタの呼び出し方法を決定するために環境を確認する必要があるようです

関連する問題