我有一个项目,其中编写了身份验证机制,如果有人试图访问 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