Question

I'm trying to authenticate to alfresco using from a Java Class AuthenticationService. Here is the code:

public void Authenticate() throws AuthenticationException {

authenticationService.authenticateAsGuest();

}

The problem is that I can't run the function because it says that

No exception of type AuthenticationException can be thrown; an exception type must be a subclass of Throwable

I'm using Alfresco 4.2.

The concerned classes are imported from:

import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.security.AuthenticationService;
Was it helpful?

Solution 3

I solved the problem. Thanks to theMarceloR's post. First I created a class where I tested this :

public class main {

/**
 * @param args
 * @throws AuthenticationFault
 */
public static void main(String[] args) throws AuthenticationFault {
  // TODO Auto-generated method stub
  Class cls = org.alfresco.repo.security.authentication.AuthenticationException.class;
  ProtectionDomain pDomain = cls.getProtectionDomain();
  CodeSource cSource = pDomain.getCodeSource();
  URL loc = cSource.getLocation();
  System.out.println(loc);
}

After running the program, you will get the missing class in your library. This class is used by AuthenticationException. I got the error :

 java.lang.ClassNotFoundException: org.alfresco.error.AlfrescoRuntimeException

Then I added the alfresco-core.jar that contains org.alfresco.error.AlfrescoRuntimeException into my classpath. I ran the Class again and everything worked fine.

I got that error many times and I've fixed it with this method.

Hope that Help !

OTHER TIPS

Decompile org.alfresco.repo.security.authentication.AuthenticationException and check.

If you want a meaningful name for the exception your Java class will be throwing, you can write your own Exception class. http://www.java2novice.com/java_exception_handling_examples/create_custom_exception/

If you really want to use that class but you're suspecting that your JVM is loading the wrong one, you can deploy the JSP code below somewhere (e.g., deploy it in the root folder of the web app as 'whereis.jsp'), start your Alfresco server and then check the results of your 'whereis.jsp' page:

<%@ 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"
%>

This will tell you the exact jar that is being loaded by your JVM, it might help you understand what's going on.

The exception says it all: you cannot throw such an exception just because the class name says so. It has to derive from Exception or at least implement Throwable.

Edit: concerning the framework, probably the class has not been designed to be thrown like a normal Java exception.

Do you have to put the throws-Statement on the Authenticate method?

Edit 2: According to http://dev.alfresco.com/resource/docs/java/datamodel/org/alfresco/repo/security/authentication/AuthenticationException.html it does implement Throwable. Are you sure that you are not in some sort of jar hell? E.g. maybe a different version running in your application container?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top