0

我正在尝试为xwiki编写一个自定义身份验证类。

我有一个项目,其中编写了身份验证机制,如果有人试图访问 xwiki,我希望它使用 xwiki 自定义身份验证将他们重定向到我的项目的登录页面。

我正在尝试与我的项目分开编写一个类并与 xwiki 分开,将其打包为一个 jar 并将其放入 xwiki 项目的 xwiki WEB-INF/lib 文件夹中,因为这就是 xwiki 自定义的说明验证。

问题是,我需要编写的类导入了一些 xwiki 类。如果我用这些导入编写一个单独的类,它将无法正确编译。

如果它是一个需要进入 xwiki 的 WEB-INF/lib 文件夹的单独类,我应该如何创建一个扩展某些 xwiki 类的类?

这是某人发布的示例https://www.box.com/shared/9kamt5d9c5

简单的例子

package my.xwiki.custom.authentication;

import java.io.*;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.user.impl.xiki.XWikiAuthServiceImpl;


public class XWikiSSOImpl extends XWikiAuthServiceImpl {

    @Override
    public XWikiUser checkAuth(XWikiContext context) throws XWikiException {
        System.out.println("we actually in checkAuth?");
    }
}

当我将我的 jar 文件添加到我的 xwiki 并运行它时,我收到以下错误:

Detailed information:

    Error number 0 in 11: Uncaught exception
Wrapped Exception: Unresolved compilation problems: 
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    XWikiAuthServiceImpl cannot be resolved to a type
    XWikiUser cannot be resolved to a type
    XWikiContext cannot be resolved to a type
    XWikiException cannot be resolved to a type

com.xpn.xwiki.XWikiException: Error number 0 in 11: Uncaught exception
Wrapped Exception: Unresolved compilation problems: 
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    XWikiAuthServiceImpl cannot be resolved to a type
    XWikiUser cannot be resolved to a type
    XWikiContext cannot be resolved to a type
    XWikiException cannot be resolved to a type

    at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:254)
    at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:116)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:120)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.xwiki.wysiwyg.server.filter.ConversionFilter.doFilter(ConversionFilter.java:144)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.xpn.xwiki.plugin.webdav.XWikiDavFilter.doFilter(XWikiDavFilter.java:66)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:208)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.Error: Unresolved compilation problems: 
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    The import com.xpn cannot be resolved
    XWikiAuthServiceImpl cannot be resolved to a type
    XWikiUser cannot be resolved to a type
    XWikiContext cannot be resolved to a type
    XWikiException cannot be resolved to a type

    at my.xwiki.custom.authentication.XWikiSSOImpl <init>(XWikiSSOImpl.java:4)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.xpn.xwiki.XWiki.getAuthService(XWiki.java:5288)
    at com.xpn.xwiki.XWiki.checkAuth(XWiki.java:4090)
    at com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl.checkAccess(XWikiRightServiceImpl.java:205)
    at com.xpn.xwiki.XWiki.checkAccess(XWiki.java:4103)
    at com.xpn.xwiki.XWiki.prepareDocuments(XWiki.java:5128)
    at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:179)
    ... 34 more
4

2 回答 2

2

根据提供的链接,您似乎没有丢失任何导入并假设您没有任何明显的语法错误,那么它指向您的开发环境。一个典型的解决方案是使用包的路径设置 CLASSPATH 变量,但根据我的经验,这很容易出错。

如果您使用的是 Eclipse,请右键单击您的项目名称并选择属性。在属性对话框中,单击左侧的“Java Build Path”。在“Java 构建路径”属性中,单击库选项卡。您想单击“添加外部 Jar...”按钮,您将在其中指定 xwiki jar 的路径。

这就是我包含的 jar 在我的项目中的外观......

于 2012-09-14T20:08:56.993 回答
1

要编译一个类,编译器需要所有引用类(包括超类)的定义。它可以使用已经编译的类(作为 .class 文件或 JAR 文件),或者从源代码编译这些类。因为你不想编译 xwiki 类,你会想要做前者。

因此,您需要将包含这些类的 jar 文件添加到您的类路径中。如何做到这一点取决于您如何调用编译器或您使用的 IDE。使用 Eclipse,您可以右键单击项目 -> 构建路径 -> 添加外部档案。使用javac,您可以使用该-cp选项。

于 2012-09-14T19:59:58.850 回答