0

WorkLightAuthenticator를 사용하여 사용자 로그인의 유효성을 검사하고 있습니다. 하지만 userName, organozationID 등과 같은 매개 변수를 반환해야합니다. 이 데이터를 반환하는 올바른 방법은 무엇입니까? 나는 그게 아래로 예제로 createIdentity 방법이 될 것이라고 생각합니다. 그리고 클라이언트에서 데이터를 검색하려면?워크 라이트 보안 WorkLightAuthLoginModule

/*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); 
}); 

답변

0

VAR 클라이언트 측에서

/*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);  
} 
} 

그리고 AuthenticatorRealmChallengeHandler는 WL.Client.getUserInfo = ("AuthenticatorRealm", "특성") 속성;

관련 문제