[MarkLogic Dev General] General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER, PASS), not working when using through XDBC]

Danny Sokolsky Danny.Sokolsky at marklogic.com
Thu May 16 14:36:54 PDT 2013


xdmp:login only works on app servers that allow application-level authentication, which means it works on HTTP servers, not an XDBC servers (it will always return false on an XDBC server).  Also, note that XDBC servers do not have app-level authentication.

So as Brent suggests, your Java code can grab the credentials from the user and then pass them in with your xcc request with the server set to do digest authentication.

-Danny

From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Brent Hartwig
Sent: Thursday, May 16, 2013 6:57 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER, PASS), not working when using through XDBC]

It appears the same credentials are used for the XCC-XDBC connection and in the call to xdmp:login(), because "this." isn't in front of "userName" and "password" within getConnection().  That might clear things up for you.  What benefit are you after by using system credentials for the connection, versus using the user-provided credentials (and skipping the call to xdmp:login())?

-Brent

From: general-bounces at developer.marklogic.com<mailto:general-bounces at developer.marklogic.com> [mailto:general-bounces at developer.marklogic.com] On Behalf Of abhinav mishra
Sent: Thursday, May 16, 2013 9:12 AM
To: general at developer.marklogic.com<mailto:general at developer.marklogic.com>
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER, PASS), not working when using through XDBC]

Hi Brent,


Yes you are right, My XDBC app server has authentication scheme as "digest". XDBC app sever privilege section is also null (Also tried by mentioning "xdmp:login" as a value here) . Via XDBC i am always getting retrun as "false".
But via Queryconsole with authentication scheme as "application-level" i am getting "true". when i set authentication scheme as "digest" for QueryConsole then i am not able to execute xdmp:login. i have mentioned description below.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I have written an xquery file on file system module. i have following code inside .xqy file>>

//authHelper.xqy

declare variable $userName as xs:string * external;
declare variable $password as xs:string * external;


xdmp:log(fn:concat("UserName: ",$userName,"|Password: ",$password))
,
xdmp:login($userName,$password)

I have a java module where i receive the user name and password and i am sending that username and password to marklogic as:

//AuthHelper.java

        private static final String userName = ResourceReader.getProperty("mladminuser"); //Reading username from property file
        private static final String password= ResourceReader.getProperty("mladminpass");//Reading password from property file
        private static final String url= ResourceReader.getProperty("mlurl"); //Reading url "localhost:8006/toolkit" from property file

        //To get the connection from marklogic.
            public static Session getConnection(String userName, String password,
                        String url) {
                        URI uri;
                        Session session=null;
                        try {
                                    uri = new URI(prepareConnectionUrl(userName,password,url));
                                    ContentSource contentSource = ContentSourceFactory
                                                            .newContentSource(uri);
                                    session = contentSource.newSession();
                        } catch (URISyntaxException e) {
                                    e.printStackTrace();
                        } catch (XccConfigException e) {
                                    e.printStackTrace();
                        }
                        return session;
            }

      private static String prepareConnectionUrl(String userName,String password,String url){
               StringBuffer sb=new StringBuffer("xdbc://");
               sb.append(userName);
               sb.append(":");
               sb.append(password);
               sb.append("@");
               sb.append(url);
               return sb.toString();
            }

public static void main(String[] args){
// User name and password here is coming form outside some client, i have tajken here as hardcoded.
                String user= "abhinav";  //It will come from outside client
                String  pass="abhinav"; //It will come from outside client

                        authenticate(user,pass);
}

public static String authenticate(String user,String pass){
             try  {
                                    Session session = getConnection(user, password,url);// admin user and password to get connection
                                    ModuleInvoke req = session.newModuleInvoke("authHelper.xqy");
                                    req.setNewStringVariable("userName", user);
                                    req.setNewStringVariable("password", pass);
                                    ResultSequence rs = session.submitRequest(req);
                                    while (rs.hasNext()) {
                                                ResultItem rsItem = rs.next();
                                                XdmItem item = rsItem.getItem();
                                                System.out.println(item); //Should be true, but getting false.
                                    }
                        } catch (Exception e) {
                                    e.printStackTrace();
                        }

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Executed the xdmp:login via QueryConsole:

When i am executing xdmp:login("abhinav","abhinav") in QueryConsole i am getting error as "[1.0-ml] XDMP-APPREQ: xdmp:login("abhinav", "abhinav") -- Application level authentication required"

When i set the QConsole with authentication scheme as "application-level" then xdmp:login("abhinav", "abhinav")  is returning true.


Please guide me. Thanks a ton in advance.

Regards,
Abhinav Kumar Mishra
</snip>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20130516/335552f2/attachment-0001.html 


More information about the General mailing list