Hello,

I’m currently trying to write a simple extension for guacamole that allows for 
push notifications through web hooks. The extension of course relies a lot on 
guacamole's event listeners. The documentation shows a very simple example 
(TutorialListener.java) of these event listeners which I have added to the 
`guacamole-client/extensions/` folder, compiled and then added the extension 
jar to the extensions folder of my guacamole instance. This example runs just 
fine and produces debugging output as expected. But when I try to extend the 
functionality, even just to store a copy of the `AuthenticationProvider` object 
from the event after including the `import 
org.apache.guacamole.net.auth.AuthenticationProvider;` line at the top of the 
file, I am able to compile the extension but then at runtime I get the 
following: `Unexpected internal error: 
'org.apache.guacamole.net.auth.AuthenticationProvider 
org.apache.guacamole.net.event.AuthenticationFailureEvent.getAuthenticationProvider()'`.
 

I started looking through the code and I have found that there is a 
`.getAuthenticationProvider()` function in the 
`AuthenticationFailureEvent.java` file so I know that I’m using the write 
function. I also found similar instances of the `AuthenticationFailureEvent` 
being used in the `EventLoggingListener.java` file and tried to replicate the 
imports and logic used for the guacamole-client. Do I need to do something 
special to get proper access to the object types? 

I have included the tutorial example with the problematic line notated. That 
line is the only one added from the off-the-shelf tutorial. If I comment it 
out, it runs perfectly fine. If I uncomment it, it throws the error mentioned 
above. 

Thanks!

Code:

package org.apache.guacamole.event;

import org.apache.guacamole.GuacamoleException;

import org.apache.guacamole.net.auth.AuthenticationProvider;
import org.apache.guacamole.net.event.AuthenticationFailureEvent;
import org.apache.guacamole.net.event.AuthenticationSuccessEvent;
import org.apache.guacamole.net.event.listener.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A Listener that logs authentication success and failure events.
 */
public class Notifier implements Listener {

    private static final Logger logger = 
LoggerFactory.getLogger(Notifier.class);

    @Override
    public void handleEvent(Object event) throws GuacamoleException {

        if (event instanceof AuthenticationSuccessEvent) {
            logger.info("successful authentication for user {}",
                    ((AuthenticationSuccessEvent) event)
                            .getCredentials().getUsername());
        } else if (event instanceof AuthenticationFailureEvent) {
            logger.info("failed authentication for user {}",
                    ((AuthenticationFailureEvent) event)
                            .getCredentials().getUsername());

            // Problematic line:
            AuthenticationProvider authProvider = ((AuthenticationFailureEvent) 
event).getAuthenticationProvider();
        }
    }
}

Reply via email to