我正在尝试使用 Java 类 AuthenticationService 进行露天身份验证。这是代码:
public void Authenticate() throws AuthenticationException {
authenticationService.authenticateAsGuest();
}
问题是我无法运行该函数,因为它说
No exception of type AuthenticationException can be thrown; an exception type must be a subclass of Throwable
我正在使用 Alfresco 4.2。
相关类导入自:
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.security.AuthenticationService;
最佳答案
反编译org.alfresco.repo.security.authentication.AuthenticationException
并检查。
如果您想要为 Java 类将抛出的异常指定一个有意义的名称,您可以编写自己的 Exception 类。 http://www.java2novice.com/java_exception_handling_examples/create_custom_exception/
如果您确实想使用该类,但怀疑您的 JVM 加载了错误的类,您可以将 JSP 代码部署到下面的某个位置(例如,将其部署在 Web 应用程序的根文件夹中,命名为“whereis.jsp”),启动您的 Alfresco 服务器,然后检查“whereis.jsp”页面的结果:
<%@ page import="java.security.*" %>
<%@ page import="java.net.URL" %>
<%
Class cls = org.alfresco.repo.security.authentication.AuthenticationException.class;
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation();
out.println(loc);
// it should print something like "c:/jars/MyJar.jar"
%>
这将告诉您 JVM 正在加载的确切 jar,它可能会帮助您了解发生了什么。
关于java - JAVA 不能抛出 AuthenticationException 类型的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22481226/