0

我正在处理 LDAP 身份验证。我从 IBM Worklight Foundation 入门站点下载了示例。(http://www.ibm.com/developerworks/mobile/worklight/getting-started.html

在完成所有配置等之后,我看到 LDAP 无法正常工作。

根据示例,方法 getSecretData 应在登录表单成功验证后执行。

但即使我提供了错误的凭据,它也会带我使用 getSecretData 方法

请帮忙!!

在那里找到代码

HTML页面:

    <div id="AppDiv">
        <div class="header">
            <h1>LDAPApp</h1>
        </div>  
        <div class="wrapper">
            <input type="button" value="Call protected adapter proc" onclick="getSecretData()" />
            <input type="button" value="Logout" onclick="WL.Client.logout('LDAPRealm',{onSuccess: WL.Client.reloadApp})" />
        </div>
        <div id="resultDiv"></div>
    </div>

    <div id="AuthDiv" style="display:none">
        <div id="loginForm">
            Username:<br/>
            <input type="text" id="usernameInputField" value=""/><br />
            Password:<br/>
            <input type="password" id="passwordInputField" value=""/><br/>      
            <input type="button" id="loginButton" value="Login" />
            <input type="button" id="cancelButton" value="Cancel" />
        </div>
    </div>

    <script src="js/initOptions.js"></script>
    <script src="js/LDAPApp.js"></script>
    <script src="js/messages.js"></script>
    <script src="js/LDAPRealmChallengeHandler.js"></script>
</body>

LDAPRealmChallengeHandler.js

var LDAPRealmChallengeHandler = WL.Client.createChallengeHandler("LDAPRealm");

LDAPRealmChallengeHandler.isCustomResponse = function(response) {
if (!response || !response.responseText) {
    return false;
}

var idx = response.responseText.indexOf("j_security_check");

if (idx >= 0){ 
    return true;
}
return false;

};

LDAPRealmChallengeHandler.handleChallenge = function(response){
    $('#AppDiv').hide();
    $('#AuthDiv').show();
    $('#passwordInputField').val('');
}; 

$('#loginButton').bind('click', function () {
var reqURL = '/j_security_check';
var options = {};
options.parameters = {
        j_username : $('#usernameInputField').val(),
        j_password : $('#passwordInputField').val()
};
options.headers = {};
LDAPRealmChallengeHandler.submitLoginForm(reqURL, options,    LDAPRealmChallengeHandler.submitLoginFormCallback);
});

$('#cancelButton').bind('click', function () {
$('#AppDiv').show();
$('#AuthDiv').hide();
LDAPRealmChallengeHandler.submitFailure();
});

 LDAPRealmChallengeHandler.submitLoginFormCallback = function(response) {
var isLoginFormResponse = LDAPRealmChallengeHandler.isCustomResponse(response);
if (isLoginFormResponse){
    LDAPRealmChallengeHandler.handleChallenge(response);
} else {
    $('#AppDiv').show();
    $('#AuthDiv').hide();
    LDAPRealmChallengeHandler.submitSuccess();
}
};

LDAPApp.js 

 function wlCommonInit(){
// Common initialization code goes here
}

 function getSecretData(){
 var invocationData = {
        adapter: "DummyAdapter",
        procedure: "getSecretData",
        parameters: []
 };

 WL.Client.invokeProcedure(invocationData, {
    onSuccess: getSecretData_Callback,
    onFailure: getSecretData_Callback,
    timeout: 2000
 });
 }

 function getSecretData_Callback(response){
  $("#resultDiv").html(new Date() + "<hr/>");
  $("#resultDiv").append("Secret data :: " + response.invocationResult.secretData);
 }

  DummyAdaptor.xml 

 <displayName>DummyAdapter</displayName>
  <description>DummyAdapter</description>

 <connectivity>
 <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
  <protocol>http</protocol>
  <domain>none</domain>
  <port>80</port>     
 </connectionPolicy>
 <loadConstraints maxConcurrentConnectionsPerNode="2" />
 </connectivity>

 <procedure name="getSecretData"  securityTest="LDAPSecurityTest" />
 </wl:adapter>

DummyAdaptor-impl.js

  function getSecretData(){
    return {secretData: 1234};
  }

   authenticationConfig.xml 

   <securityTests>
    <customSecurityTest name="LDAPSecurityTest">
        <test realm="wl_directUpdateRealm" step="1"/>
        <test isInternalUserID="true" realm="LDAPRealm"/>
    </customSecurityTest>

 </securityTests>
 <realms>
    <realm loginModule="LDAPLoginModule" name="LDAPRealm">
        <className>com.worklight.core.auth.ext.FormBasedAuthenticator</className>
        <onLoginUrl>/console</onLoginUrl>
    </realm>
 </realms>
 <loginModules>
    <loginModule name="rejectAll">
        <className>com.worklight.core.auth.ext.RejectingLoginModule</className>
    </loginModule>
    <loginModule name="LDAPLoginModule">
        <className>com.worklight.core.auth.ext.LdapLoginModule</className>
        <parameter name="ldapProviderUrl" value="ldap://xyz"/>
        <parameter name="ldapTimeoutMs" value="120000"/>
        <parameter name="ldapSecurityAuthentication" value="none"/>
        <parameter name="validationType" value="exists"/>
        <parameter name="ldapSecurityPrincipalPattern" value="{username}@in.ibm.com"/>
        <parameter name="ldapSearchFilterPattern" value="(&amp;(mail=%v)(|(objectclass=ibmPerson)(objectclass=eperson)))"/>
        <parameter name="ldapSearchBase" value="c=in,ou=bluepages,o=ibm.com"/>
    </loginModule>
</loginModules>
</tns:loginConfiguration>

不知道哪里错了。在控制台中出现以下错误。但它允许我访问 getSecretData,即使我提供了错误的凭据。

[错误] FWLSE0048E:捕获到未处理的异常:SRVE0190E:找不到文件:/console java.io.FileNotFoundException:SRVE0190E:找不到文件:com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor.handleRequest(DefaultExtensionProcessor.java: 528) 在 com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:127) 在 com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:88) 在 com.worklight.core .auth.impl.AuthenticationFilter$1.execute(AuthenticationFilter.java:205) 在 com.worklight.core.auth.impl.AuthenticationServiceBean.accessResource(AuthenticationServiceBean.java:76) 在 com.worklight.core.auth.impl.AuthenticationFilter。 com.ibm.ws.webcontainer.filter.FilterInstanceWrapper 上的 doFilter(AuthenticationFilter.java:209)。doFilter(FilterInstanceWrapper.java:194) 在 com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:85) 在 com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:968)在 com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1056) 在 com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4510) 在 com.ibm.ws.webcontainer .osgi.DynamicVirtualHost$2.handleRequest(DynamicVirtualHost.java:282) 在 com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:954) 在 com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost .java:252) 在 com.ibm.ws.threading.internal.Worker 的 com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:584)。executeWork(Worker.java:439) at com.ibm.ws.threading.internal.Worker.run(Worker.java:421) at java.lang.Thread.run(Unknown Source) [project module_23_2_LDAPLoginModule] SRVE0190E: 找不到文件: /安慰

4

1 回答 1

0

您无需在领域定义中指定 onLoginUrl,只需将其删除即可。它用于在成功登录后将客户端转发到特定位置,这与移动应用程序无关。

于 2014-11-10T22:11:39.950 回答