Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticator plugin #1034

Closed
ahennar opened this issue Feb 13, 2017 · 7 comments
Closed

Authenticator plugin #1034

ahennar opened this issue Feb 13, 2017 · 7 comments

Comments

@ahennar
Copy link

ahennar commented Feb 13, 2017

Hello

I tried to write my own Authenticator class in scala to use it further. Here is the code:

package fitnesse.mod

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import fitnesse.authentication. { PasswordFile, PasswordCipher }

class MUAuthenticator(passwdFile: String) extends fitnesse.authentication.MultiUserAuthenticator(passwdFile) {
  private val passwords = new PasswordFile(passwdFile);
  private val users: Map[String, String] = passwords.getPasswordMap()
  private val cipher: PasswordCipher = passwords.getCipher()

  override def isAuthenticated(username: String, password: String): Boolean = {
    if (username == null || password == null)
      return false;

    val foundPassword = users.get(username);
    if (foundPassword == null)
      return false;

    val encryptedPassword = cipher.encrypt(password);
    val ret = encryptedPassword.equals(foundPassword)
    if (ret)
      System.setProperty("AuthUser", username) // added this line
    return ret;
  }
}

And then I added line to plugins.properties:
Authenticator=fitnesse.mod.MUAuthenticator

It fails on start:


Configured verbose logging
SEVERE: Error while starting the FitNesse [Unable to look up component for type 'Authenticator' with classname 'fitnesse.mod.MUAuthenticator']
fitnesse.components.ComponentInstantiationException: Unable to look up component for type 'Authenticator' with classname 'fitnesse.mod.MUAuthenticator'
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:47)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:80)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:84)
        at fitnesse.plugins.PropertyBasedPluginFeatureFactory.getAuthenticator(PropertyBasedPluginFeatureFactory.java:70)
        at fitnesse.plugins.PluginsLoader.getAuthenticator(PluginsLoader.java:77)
        at fitnesse.plugins.PluginsLoader.makeAuthenticator(PluginsLoader.java:71)
        at fitnesse.ContextConfigurator.makeFitNesseContext(ContextConfigurator.java:115)
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:69)
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:58)
        at fitnesseMain.FitNesseMain.main(FitNesseMain.java:38)
Caused by: java.lang.ClassNotFoundException: fitnesse.mod.MUAuthenticator
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:43)
        ... 9 more

As for WritingPlugins

Previously, to install a plugin you had to download the plugin and load it alongside FitNesse (either from the plugins folder or by using a build tool such as Ant or Maven to launch FitNesse) and you had to configure the plugin in the Configuration File. When a plugin has a service provider it is no longer needed to also define it in the configuration file. Just put the plugin jar on the FitNesse class path or in the plugins folder and it will be configured automatically.

Where is the plugins folder or how can I setup Fitnesse classpath correctly?
Classpath is defined and is working well with my tests but It can't find the class in the same jar where my tests are.
Could you help me with it?

@JeremyCarlsten
Copy link

In our project Plugins is located next to FitnesseRoot and the fitnesse-standalone.jar. I believe you just drop the plugin in and restart the jar.

@six42
Copy link
Contributor

six42 commented Feb 13, 2017 via email

@ahennar
Copy link
Author

ahennar commented Feb 14, 2017

@JeremyCarlsten
I put my jar as you said and I still have an error:

java -cp "/opt/fitnesse/*" fitnesseMain.FitNesseMain  -p 9090 -d /opt/fitnesse -a /etc/fitnesse/passwords.txt -v -l /var/log/fitnesse
Configured verbose logging
SEVERE: Error while starting the FitNesse [Unable to instantiate component for type fitnesse.mod.MUAuthenticator]
fitnesse.components.ComponentInstantiationException: Unable to instantiate component for type fitnesse.mod.MUAuthenticator
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:75)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:51)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:80)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:84)
        at fitnesse.plugins.PropertyBasedPluginFeatureFactory.getAuthenticator(PropertyBasedPluginFeatureFactory.java:70)
        at fitnesse.plugins.PluginsLoader.getAuthenticator(PluginsLoader.java:77)
        at fitnesse.plugins.PluginsLoader.makeAuthenticator(PluginsLoader.java:71)
        at fitnesse.ContextConfigurator.makeFitNesseContext(ContextConfigurator.java:115)
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:69)
        at fitnesseMain.FitNesseMain.launchFitNesse(FitNesseMain.java:58)
        at fitnesseMain.FitNesseMain.main(FitNesseMain.java:38)
Caused by: java.lang.NoSuchMethodException: fitnesse.mod.MUAuthenticator.<init>()
        at java.lang.Class.getConstructor0(Class.java:3082)
        at java.lang.Class.getConstructor(Class.java:1825)
        at fitnesse.components.ComponentFactory.createComponent(ComponentFactory.java:71)
        ... 10 more

@six42
It is quite odd, I have updated the code, please, could you check this:

package fitnesse.mod

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import fitnesse.authentication. { PasswordFile, PasswordCipher }

class MUAuthenticator(passwdFile: String) extends fitnesse.authentication.MultiUserAuthenticator(passwdFile) {
  private val passwords = new PasswordFile(passwdFile);
  private val users: Map[String, String] = passwords.getPasswordMap()
  private val cipher: PasswordCipher = passwords.getCipher()

  override def isAuthenticated(username: String, password: String): Boolean = {
    if (username == null || password == null)
      return false;

    val foundPassword = users.get(username);
    if (foundPassword == null)
      return false;

    val encryptedPassword = cipher.encrypt(password);
    val ret = encryptedPassword.equals(foundPassword)
    if (ret)
      System.setProperty("AuthUser", username)
    return ret;
  }
}

@JeremyCarlsten
Copy link

It seems to be looking for an init method in the MUAuthenticator class?
Sorry I'm not more help I've not built one yet.

perhaps compare your code to a working plugin like the hsac plugin?
https://github.com/fhoeben/hsac-fitnesse-plugin

@six42
Copy link
Contributor

six42 commented Feb 15, 2017 via email

@ahennar
Copy link
Author

ahennar commented Feb 15, 2017

Hi six42, thanks

It was fixed by creating default constructor(). Is it correct? Because it seems MUAuthenticator(file: String) won't be invoked and file location is hardcoded now.

@six42
Copy link
Contributor

six42 commented Feb 16, 2017 via email

@ahennar ahennar closed this as completed Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants