Ibm mobilefirst Worklight安全WorkLightAuthLoginModule

Ibm mobilefirst Worklight安全WorkLightAuthLoginModule,ibm-mobilefirst,worklight-adapters,worklight-security,Ibm Mobilefirst,Worklight Adapters,Worklight Security,我正在使用WorkLightAuthenticator验证用户登录。 但是我需要返回一些参数,比如用户名、ID等等。返回此数据的正确方法是什么? 我相信这将是createIdentity作为示例的方法。以及检索客户端上的数据 /*Worklight Adapter*/ public class LoginModule implements WorkLightAuthLoginModule { private String USERNAME; private String PASSWOR

我正在使用WorkLightAuthenticator验证用户登录。 但是我需要返回一些参数,比如用户名、ID等等。返回此数据的正确方法是什么? 我相信这将是createIdentity作为示例的方法。以及检索客户端上的数据

/*Worklight Adapter*/    
public class LoginModule implements WorkLightAuthLoginModule {

private String USERNAME;
private String PASSWORD;

public void init(Map<String, String> options) throws MissingConfigurationOptionException {
}

@SuppressWarnings("unchecked")
public boolean login(Map<String, Object> authenticationData) {
    USERNAME = (String) authenticationData.get("username");
    PASSWORD = (String) authenticationData.get("password");

    InvocationResult invocationResult = callLoginAdapter(USERNAME, PASSWORD);
    JSONObject jsonObject = invocationResult.toJSON();

    HashMap<String, String> result = (HashMap<String, String>) jsonObject.get("result");

    if(result != null){
        return true;
    } else {
        HashMap<String, String> fault = (HashMap<String, String>) jsonObject.get("Fault");
        String detail = fault.get("Detail");                        
        throw new RuntimeException(detail);
    }
}



public UserIdentity createIdentity(String loginModule) {
    HashMap<String, Object> customAttributes = new HashMap<String, Object>();
    customAttributes.put("AuthenticationDate", new Date());
    customAttributes.put("userName", userExample);
    customAttributes.put("organizationID", 1);

    UserIdentity identity = new UserIdentity(loginModule, USERNAME, null, null, customAttributes, PASSWORD);
    return identity;
}

public void logout() {
    USERNAME = null;
    PASSWORD = null;
}

public void abort() {
    USERNAME = null;
    PASSWORD = null;
}

@Override
public LoginModule clone() throws CloneNotSupportedException {
    return (LoginModule) super.clone();
}

public InvocationResult callLoginAdapter(String user, String password){
    DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
    String parameters = "['"+user+"','"+password+"']";
    ProcedureQName procedureQName = new ProcedureQName("LoginAdapter", "getUserByLogin");
    return service.invokeProcedure(procedureQName, parameters);     
}
}

var attributes=WL.Client.getUserInfo(“AuthenticatorRealm”、“attributes”)

/*AuthenticatorRealmChallengeHandler.js*/
var customAuthenticatorRealmChallengeHandler = WL.Client.createChallengeHandler("AuthenticatorRealm");

customAuthenticatorRealmChallengeHandler.isCustomResponse = function(response) {
console.log("**********************");
console.log(response.responseJSON);

if (!response || !response.responseJSON) {
    return false;
}

if (response.responseJSON.authStatus) 
    return true;
else 
    return false;
};

customAuthenticatorRealmChallengeHandler.handleChallenge = function(response){
var authStatus = response.responseJSON.authStatus;

if (authStatus == "required"){      
    if (response.responseJSON.errorMessage){
        currentPage.loginFail(response.responseJSON.errorMessage);
    }
} else if (authStatus == "complete"){       
    currentPage.loadMaster();
    customAuthenticatorRealmChallengeHandler.submitSuccess();

}
};

customAuthenticatorRealmChallengeHandler.submitLoginFormCallback = function(response) {
var isLoginFormResponse = customAuthenticatorRealmChallengeHandler.isCustomResponse(response);
if (isLoginFormResponse){
    customAuthenticatorRealmChallengeHandler.handleChallenge(response);
} 
};

$('#loginButton').bind('click', function () {
var reqURL = '/auth_request_url';
var options = {};
options.parameters = {
    username : $('#userTextField').val(),
    password : $('#passwordTextField').val()
};
options.headers = {};
customAuthenticatorRealmChallengeHandler.submitLoginForm(reqURL, options, customAuthenticatorRealmChallengeHandler.submitLoginFormCallback);
});