Liferay Thrift Servlet - 标准认证

Liferay Thrift Servlet - standard authentication

我有一个 Liferay 门户 6.2 ce ga4 jboss 捆绑和 运行 我为应用程序和服务器之间的通信编写的一个 thrift servlet。我只想将 Liferay 用于其用户管理,所以我只想通过 Liferay api.

使用他的凭据对用户进行身份验证

我首先尝试使用 UserLocalServiceUtil,但是当我调用该方法时,服务器抛出此错误:

08:07:13,962 SEVERE [com.liferay.portal.kernel.bean.PortalBeanLocatorUtil] (http--0.0.0.0-8080-1) BeanLocator is null
08:07:13,963 ERROR [stderr] (http--0.0.0.0-8080-1) java.lang.Exception: Stack trace
08:07:13,963 ERROR [stderr] (http--0.0.0.0-8080-1)  at java.lang.Thread.dumpStack(Thread.java:1365)
08:07:13,963 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:74)
08:07:13,964 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.service.UserLocalServiceUtil.getService(UserLocalServiceUtil.java:3417)
08:07:13,964 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.service.UserLocalServiceUtil.getBeanIdentifier(UserLocalServiceUtil.java:1004)
08:07:13,964 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.implemented.UserAuthenticationHandler.signIn(UserAuthenticationHandler.java:33)
08:07:13,965 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.generated.UserAuthenticationService$Processor$signIn.getResult(UserAuthenticationService.java:253)
08:07:13,965 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.generated.UserAuthenticationService$Processor$signIn.getResult(UserAuthenticationService.java:1)
08:07:13,966 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
08:07:13,966 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
08:07:13,966 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.server.TServlet.doPost(TServlet.java:83)
08:07:13,967 ERROR [stderr] (http--0.0.0.0-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
08:07:13,967 ERROR [stderr] (http--0.0.0.0-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
08:07:13,968 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
08:07:13,968 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
08:07:13,969 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
08:07:13,969 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
08:07:13,970 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
08:07:13,970 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
08:07:13,971 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
08:07:13,971 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
08:07:13,972 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
08:07:13,972 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
08:07:13,972 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
08:07:13,973 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
08:07:13,973 ERROR [stderr] (http--0.0.0.0-8080-1)  at java.lang.Thread.run(Thread.java:745)
08:07:13,974 ERROR [stderr] (http--0.0.0.0-8080-1) com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set
08:07:13,974 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.kernel.bean.PortalBeanLocatorUtil.locate(PortalBeanLocatorUtil.java:82)
08:07:13,974 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.service.UserLocalServiceUtil.getService(UserLocalServiceUtil.java:3417)
08:07:13,975 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.liferay.portal.service.UserLocalServiceUtil.getBeanIdentifier(UserLocalServiceUtil.java:1004)
08:07:13,975 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.implemented.UserAuthenticationHandler.signIn(UserAuthenticationHandler.java:33)
08:07:13,975 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.generated.UserAuthenticationService$Processor$signIn.getResult(UserAuthenticationService.java:253)
08:07:13,976 ERROR [stderr] (http--0.0.0.0-8080-1)  at com.fsu.unired.alarmapp.thrift.generated.UserAuthenticationService$Processor$signIn.getResult(UserAuthenticationService.java:1)
08:07:13,976 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
08:07:13,976 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
08:07:13,977 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.thrift.server.TServlet.doPost(TServlet.java:83)
08:07:13,977 ERROR [stderr] (http--0.0.0.0-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
08:07:13,977 ERROR [stderr] (http--0.0.0.0-8080-1)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
08:07:13,977 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
08:07:13,978 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
08:07:13,978 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
08:07:13,978 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
08:07:13,979 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
08:07:13,980 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
08:07:13,980 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
08:07:13,980 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
08:07:13,981 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
08:07:13,981 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
08:07:13,981 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
08:07:13,981 ERROR [stderr] (http--0.0.0.0-8080-1)  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
08:07:13,982 ERROR [stderr] (http--0.0.0.0-8080-1)  at java.lang.Thread.run(Thread.java:745)

我真的不来了。我还查看了 com.liferay.portal.security.auth,但找不到任何 类。我只想要一个我可以调用的方法来检查用户是否已注册。

这是我在 servlet 上 运行 的代码。

import org.apache.thrift.TException;

import com.fsu.unired.alarmapp.thrift.generated.User;
import com.fsu.unired.alarmapp.thrift.generated.UserAuthenticationService;
import com.liferay.portal.service.UserLocalServiceUtil;

    public class UserAuthenticationHandler implements UserAuthenticationService.Iface {

        @Override
        public User signIn(String forceMail, String password){
            System.out.println("signIn called...");

            User usr = new User();

            System.out.println("returning user:" + usr.toString());

            try {


                int status = com.liferay.portal.service.UserLocalServiceUtil.authenticateByEmailAddress(0, forceMail, password, null,null, null);
                System.out.println("Status : " +status);
                switch(status) {

                    case -1:    return null;

                    case  1:    System.out.println("case 1");
                                com.liferay.portal.model.User liferayUser = UserLocalServiceUtil.getUserByEmailAddress(0, forceMail);
                                System.out.println(liferayUser.toString());
                }
                return usr;
            }
            catch(Exception e) {
                e.printStackTrace();
            }
            return usr;
        }

我有 portal-service.jar 包括在内。这是我的 web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>alarm-thrift-servlet</display-name>
  <servlet>
    <description></description>
    <display-name>ThriftServlet</display-name>
    <servlet-name>ThriftServlet</servlet-name>
    <servlet-class>com.fsu.unired.alarmapp.servlet.ThriftServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ThriftServlet</servlet-name>
    <url-pattern>/ThriftServlet</url-pattern>
  </servlet-mapping>
</web-app>

我假设您正在部署一个纯 Web 应用程序 - 您可能想尝试 Liferay-web 插件。这非常相似,但知道 Liferay 存在并且可能会初始化 Liferay API 需要的基础设施。否则你将不得不自己进行初始化。