简体   繁体   English

从Java应用程序访问当前登录的Drupal用户

[英]Accessing currently logged-in Drupal user from Java application

I have Java application hosted on the same domain as Drupal website. 我将Java应用程序托管在与Drupal网站相同的域中。 This Java application gets client request form the browser (so I get access to all the cookies). 该Java应用程序从浏览器获取客户端请求(因此我可以访问所有cookie)。 Is it possible using cookies I get in Java application to check if client logged into Drupal from the same browser? 是否可以使用我在Java应用程序中获得的cookie来检查客户端是否从同一浏览器登录到Drupal?

I thought about using xmlrpc from Java application to perform request to Drupal services module, but I couldn't find a way to get information about currently logged in user providing cookie data. 我曾考虑过使用Java应用程序中的xmlrpc来执行对Drupal服务模块的请求,但是我无法找到一种方法来获取有关当前登录用户的Cookie信息。

Any ideas? 有任何想法吗?

Thanks a lot. 非常感谢。

PS: I'm using freshly installed Drupal 7. If you have Drupal 6 example it will do the job. PS:我使用的是新安装的Drupal7。如果您有Drupal 6示例,它将完成此工作。 Thanks. 谢谢。

Well, if you can get the SESSION id, you can hit the sessions table, and see if there is any row in the table that has the same sid (SESSION id = sid). 好吧,如果您可以获取SESSION ID,则可以访问会话表,并查看表中是否有任何具有相同sid的行(SESSION id = sid)。 If the uid isn't 0, the user is logged in, and you can then look up who they are from there. 如果uid不为0,则用户已登录,然后您可以从那里查找他们的身份。

A little late with my answer, but I'd recommend writing a module for Drupal which plugs into its XML-RPC capabilities and does the work for you. 我的回答有点晚了,但是我建议为Drupal编写一个模块,该模块插入其XML-RPC功能并为您完成工作。

In other words, you would make an XML-RPC request from your Java application (http://ws.apache.org/xmlrpc/client.html) to a path on your Drupal site controlled by the module (say 'example.com/user/is-logged-in'). 换句话说,您将从您的Java应用程序(http://ws.apache.org/xmlrpc/client.html)向该模块控制的Drupal网站上的路径发出XML-RPC请求(例如'example.com / user / is-logged-in')。 The Drupal module would 'control' that path, and receive all requests. Drupal模块将“控制”该路径,并接收所有请求。 From there it's a simple job for the Drupal module to make a query against the database to find out whether the session is associated with a logged in user (if associated user is 0, then the user is not logged in - otherwise the user is logged in). 从那里开始,Drupal模块的一项简单工作就是对数据库进行查询,以查找会话是否与已登录用户相关联(如果关联用户为0,则该用户未登录-否则该用户已登录)在)。 The Drupal module would then simply return true or false (if that's desirable, or a more detailed array of user details). 然后,Drupal模块将简单地返回true或false(如果需要的话,或者返回更详细的用户详细信息数组)。

I'll soon be working on a similar case, and will probably go down that path. 我将很快处理类似的案例,并且可能会走这条路。 In my case, I've got a Drupal site which offers file downloads. 就我而言,我有一个提供文件下载功能的Drupal网站。 The downloads needs to be done via a Java servlet, but only people who are logged in should be allowed to download. 下载需要通过Java Servlet完成,但是只有登录的人才能被允许下载。 Thus, the servlet will contact the Drupal site to check if a user with the session id provided in the cookie is logged in and then determine whether download should commence or not. 因此,该servlet将联系Drupal站点,以检查具有cookie中提供的会话ID的用户是否已登录,然后确定是否应该开始下载。

In other words: 换一种说法:

Java --> XML-RPC request --> Drupal Site --> XML-RPC response --> Java. Java-> XML-RPC请求-> Drupal站点-> XML-RPC响应-> Java。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM