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: [email protected] 
[mailto:[email protected]] On Behalf Of abhinav mishra
Sent: Thursday, May 16, 2013 9:12 AM
To: [email protected]
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>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to