Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 48
Hi Danny,Brant
Got your point completly. I will use the same credentials to get the connection with xdbc server; if connection successful then its a valid user.
Brent, actually i am creating a webservice framework for authentication,exception handling,logging by framework. This framework will be used my Java RestWs; whrere in which i am trying authenticate user and then allowing to process request. Java webservice will load in memory xml (generated inside webservice) to marklogic.

Thank you very much for guiding me.
On May 17, 2013 3:07 AM, <
general-request-ld4jwAGwUXTgXEvjvSGRgBvyUsyucf76@public.gmane.orgc.com> wrote:
Send General mailing list submissions to
general <at> developer.marklogic.com
To subscribe or unsubscribe via the World Wide Web, visit
http://developer.marklogic.com/mailman/listinfo/general
or, via email, send a message with subject or body 'help' to
general-request-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org
You can reach the person managing the list at
general-owner-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of General digest..."
Today's Topics:
1. Re: General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER,
PASS), not working when using through XDBC] (Danny Sokolsky)
----------------------------------------------------------------------
Message: 1
Date: Thu, 16 May 2013 21:36:54 +0000
From: Danny Sokolsky <Danny.Sokolsky-efBvD/aTHCF8UrSeD/g0lQ@public.gmane.org>
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41
[XDMP:LOGIN(USER, PASS), not working when using through XDBC]
To: MarkLogic Developer Discussion <general-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org>
Message-ID:
<D4F697174C071D46B891B38BFC6EAFA6095824 <at> EXCHG10-BE01.marklogic.com>
Content-Type: text/plain; charset="us-ascii"
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-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org [mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org] 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-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org<mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org> [mailto:general-bounces-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org] On Behalf Of abhinav mishra
Sent: Thursday, May 16, 2013 9:12 AM
To: general-ld4jwAGwUXRXKVOp+u0EsQ@public.gmane.orgrklogic.com<mailto:general-ld4jwAGwUXTgXEvjvSGRgMKenhbt+owO@public.gmane.org>
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(" <at> ");
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.html
------------------------------
_______________________________________________
General mailing list
General-ld4jwAGwUXTgXEvjvSGRgA@public.gmane.orggic.com
http://developer.marklogic.com/mailman/listinfo/general
End of General Digest, Vol 107, Issue 48
****************************************
<div>
<p>Hi Danny,Brant</p>
<p>Got your point completly. I will use the same credentials to get the connection with xdbc server; if connection successful then its a valid user.
</p>
<p>Brent, actually i am creating a webservice framework for authentication,exception handling,logging by framework. This framework will be used my Java RestWs; whrere in which i am trying authenticate user and then allowing to process request. Java webservice will load in memory xml (generated inside webservice) to marklogic.
</p>
<p>Thank you very much for guiding me.</p>
<div class="gmail_quote">On May 17, 2013 3:07 AM, <<a href="mailto:general-request@...">general-request@...c.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote">
Send General mailing list submissions to<br>
<a href="mailto:general@...">general <at> developer.marklogic.com</a><br><br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://developer.marklogic.com/mailman/listinfo/general" target="_blank">http://developer.marklogic.com/mailman/listinfo/general</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:general-request@...">general-request@...</a><br><br>
You can reach the person managing the list at<br>
<a href="mailto:general-owner@...">general-owner@...</a><br><br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of General digest..."<br><br><br>
Today's Topics:<br><br>
1. Re: General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER,<br>
PASS), not working when using through XDBC] (Danny Sokolsky)<br><br><br>
----------------------------------------------------------------------<br><br>
Message: 1<br>
Date: Thu, 16 May 2013 21:36:54 +0000<br>
From: Danny Sokolsky <<a href="mailto:Danny.Sokolsky@...">Danny.Sokolsky@...</a>><br>
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41<br>
[XDMP:LOGIN(USER, PASS), not working when using through XDBC]<br>
To: MarkLogic Developer Discussion <<a href="mailto:general <at> developer.marklogic.com">general@...</a>><br>
Message-ID:<br>
<<a href="mailto:D4F697174C071D46B891B38BFC6EAFA6095824 <at> EXCHG10-BE01.marklogic.com">D4F697174C071D46B891B38BFC6EAFA6095824 <at> EXCHG10-BE01.marklogic.com</a>><br>
Content-Type: text/plain; charset="us-ascii"<br><br>
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.<br><br>
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.<br><br>
-Danny<br><br>
From: <a href="mailto:general-bounces@...">general-bounces@...</a> [mailto:<a href="mailto:general-bounces <at> developer.marklogic.com">general-bounces@...</a>] On Behalf Of Brent Hartwig<br>
Sent: Thursday, May 16, 2013 6:57 AM<br>
To: MarkLogic Developer Discussion<br>
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER, PASS), not working when using through XDBC]<br><br>
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())?<br><br>
-Brent<br><br>
From: <a href="mailto:general-bounces@...">general-bounces@...</a><mailto:<a href="mailto:general-bounces@...">general-bounces@...</a>> [mailto:<a href="mailto:general-bounces@...">general-bounces@...</a>] On Behalf Of abhinav mishra<br>
Sent: Thursday, May 16, 2013 9:12 AM<br>
To: <a href="mailto:general@...">general@...rklogic.com</a><mailto:<a href="mailto:general@...">general@...</a>><br>
Subject: Re: [MarkLogic Dev General] General Digest, Vol 107, Issue 41 [XDMP:LOGIN(USER, PASS), not working when using through XDBC]<br><br>
Hi Brent,<br><br><br>
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".<br>
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.<br><br>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br>
I have written an xquery file on file system module. i have following code inside .xqy file>><br><br>
//authHelper.xqy<br><br>
declare variable $userName as xs:string * external;<br>
declare variable $password as xs:string * external;<br><br><br>
xdmp:log(fn:concat("UserName: ",$userName,"|Password: ",$password))<br>
,<br>
xdmp:login($userName,$password)<br><br>
I have a java module where i receive the user name and password and i am sending that username and password to marklogic as:<br><br>
//AuthHelper.java<br><br>
private static final String userName = ResourceReader.getProperty("mladminuser"); //Reading username from property file<br>
private static final String password= ResourceReader.getProperty("mladminpass");//Reading password from property file<br>
private static final String url= ResourceReader.getProperty("mlurl"); //Reading url "localhost:8006/toolkit" from property file<br><br>
//To get the connection from marklogic.<br>
public static Session getConnection(String userName, String password,<br>
String url) {<br>
URI uri;<br>
Session session=null;<br>
try {<br>
uri = new URI(prepareConnectionUrl(userName,password,url));<br>
ContentSource contentSource = ContentSourceFactory<br>
.newContentSource(uri);<br>
session = contentSource.newSession();<br>
} catch (URISyntaxException e) {<br>
e.printStackTrace();<br>
} catch (XccConfigException e) {<br>
e.printStackTrace();<br>
}<br>
return session;<br>
}<br><br>
private static String prepareConnectionUrl(String userName,String password,String url){<br>
StringBuffer sb=new StringBuffer("xdbc://");<br>
sb.append(userName);<br>
sb.append(":");<br>
sb.append(password);<br>
sb.append(" <at> ");<br>
sb.append(url);<br>
return sb.toString();<br>
}<br><br>
public static void main(String[] args){<br>
// User name and password here is coming form outside some client, i have tajken here as hardcoded.<br>
String user= "abhinav"; //It will come from outside client<br>
String pass="abhinav"; //It will come from outside client<br><br>
authenticate(user,pass);<br>
}<br><br>
public static String authenticate(String user,String pass){<br>
try {<br>
Session session = getConnection(user, password,url);// admin user and password to get connection<br>
ModuleInvoke req = session.newModuleInvoke("authHelper.xqy");<br>
req.setNewStringVariable("userName", user);<br>
req.setNewStringVariable("password", pass);<br>
ResultSequence rs = session.submitRequest(req);<br>
while (rs.hasNext()) {<br>
ResultItem rsItem = rs.next();<br>
XdmItem item = rsItem.getItem();<br>
System.out.println(item); //Should be true, but getting false.<br>
}<br>
} catch (Exception e) {<br>
e.printStackTrace();<br>
}<br><br>
}<br>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br><br>
Executed the xdmp:login via QueryConsole:<br><br>
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"<br><br>
When i set the QConsole with authentication scheme as "application-level" then xdmp:login("abhinav", "abhinav") is returning true.<br><br><br>
Please guide me. Thanks a ton in advance.<br><br>
Regards,<br>
Abhinav Kumar Mishra<br>
</snip><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <a href="http://developer.marklogic.com/pipermail/general/attachments/20130516/335552f2/attachment.html" target="_blank">http://developer.marklogic.com/pipermail/general/attachments/20130516/335552f2/attachment.html</a><br><br>
------------------------------<br><br>
_______________________________________________<br>
General mailing list<br><a href="mailto:General@...">General@...gic.com</a><br><a href="http://developer.marklogic.com/mailman/listinfo/general" target="_blank">http://developer.marklogic.com/mailman/listinfo/general</a><br><br><br>
End of General Digest, Vol 107, Issue 48<br>
****************************************<br>
</blockquote>
</div>
</div>