java - JAVA 不能抛出 AuthenticationException 类型的异常

标签 java alfresco

我正在尝试使用 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/

相关文章:

java - 子字符串或替换是否更快以删除字符串中的最后一个字符?

java - 如何阅读GC详细信息

java - Android 应用程序在替换 fragment : 后崩溃

api - 可以创建自定义界面,利用由 Alfresco 管理的文件吗?

java - 如何在 If 语句中使用 JOptionPane?

java - 具有可选参数和不同业务逻辑的Web服务

java - 露天形式过滤器

通过 ftps 连接 alfresco 的 Java 代码

java - 如何在Alfresco中设置输出文件名?

java - 为什么Activiti中的流程在生命周期中会丢失boundaryEvent