Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » jetty authentication in Eclipse Luna(org.eclipse.equinox.http.jetty can't find my JettyCustomizer)
jetty authentication in Eclipse Luna [message #1700153] Tue, 30 June 2015 12:44 Go to next message
Peter Richards is currently offline Peter RichardsFriend
Messages: 10
Registered: June 2015
Junior Member
Hello,
I am trying to set up basic authentication for a RAP application. I derive from JettyCustomizer the class shown below and add
-Dorg.eclipse.equinox.http.jetty.customizer.class=rapauth.auth.BasicAuthCustomizer
to the run configuration arguments.

I include this in the simple "RAP Hello World" application, which comes with Eclipse Luna.

However, when I run this RAP application inside Eclipse, I get this error:
java.lang.ClassNotFoundException: rapauth.auth.BasicAuthCustomizer cannot be found by org.eclipse.equinox.http.jetty_3.0.200.v20131021-1843
  [...]


How do I configure an application so that org.eclipse.equinox.http.jetty will find my BasicAuthCustomizer?
The page http://wiki.eclipse.org/RAP/FAQ#How_can_I_use_Jetty_basic_authentication_in_my_application.3F says "In order for this class to be loaded correctly by the Eclipse code that customizes Jetty, you will need to put this class into a fragment that attaches to the org.eclipse.equinox.http.jetty bundle." I haven't worked with fragments before.

To add another question, other solutions explain how to set up authentication in an WEB-INF/web.xml or WEB-INF/jetty-web.xml. These two files seem to be ignored when I run my application inside eclipse. What needs to be changed so that it works?

Regards,
Peter

BasicAuthCustomizer.java:
package rapauth.auth;

import java.util.Dictionary;

import org.eclipse.equinox.http.jetty.JettyCustomizer;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.security.Constraint;

public class BasicAuthCustomizer extends JettyCustomizer {

    @Override
    public Object customizeContext(Object o, Dictionary<String, ?> settings) {
    	System.err.println("AUTHENTICATION");
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);
        constraint.setRoles(new String[] { "admin" });
        constraint.setAuthenticate(true);

        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setConstraint(constraint);
        mapping.setPathSpec("/*");

        HashLoginService loginService = new HashLoginService("MyRealm");
        loginService.setConfig("/tmp/users.properties");

        ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
        securityHandler.setLoginService(loginService);
        securityHandler
                .setConstraintMappings(new ConstraintMapping[] { mapping });

        ServletContextHandler context = (ServletContextHandler) o;
        context.setSecurityHandler(securityHandler);

        return o;
    }
}


MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Rapauth
Bundle-SymbolicName: rapauth;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: rapauth.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.rap.ui;bundle-version="[2.0.0,3.0.0)",
 org.eclipse.equinox.http.jetty;bundle-version="3.0.200",
 org.eclipse.jetty.security;bundle-version="8.1.16",
 org.eclipse.jetty.util;bundle-version="8.1.16",
 org.eclipse.jetty.http;bundle-version="8.1.16",
 org.eclipse.jetty.server;bundle-version="8.1.16",
 org.eclipse.jetty.servlet;bundle-version="8.1.16"

Re: jetty authentication in Eclipse Luna [message #1700428 is a reply to message #1700153] Thu, 02 July 2015 14:28 Go to previous messageGo to next message
Peter Richards is currently offline Peter RichardsFriend
Messages: 10
Registered: June 2015
Junior Member
Hello again,
is there anybody who can describe how to make authentication work as outlined in http://wiki.eclipse.org/RAP/FAQ#How_can_I_use_Jetty_basic_authentication_in_my_application.3F ?

If needed, I could as well attach my complete project, although implementing the BasicAuthCustomizer class and adding one run configuration argument as shown in my previous post is everything that is needed to reproduce the problem.

Thanks
Peter
Re: jetty authentication in Eclipse Luna [message #1700514 is a reply to message #1700428] Fri, 03 July 2015 07:49 Go to previous messageGo to next message
Aleksander   is currently offline Aleksander Friend
Messages: 44
Registered: May 2014
Location: France
Member
Hi, the link you followed is for Jetty6 I believe. You'll need to follow this one : https://wiki.eclipse.org/Jetty/Tutorial/JAAS

But I'd recommend using the Equinox authentication which is in my opinion easier: http://random-eclipse-tips.blogspot.fr/2009/02/equinox-how-to-authenticate-with.html
With the equinox JAAS auth I will be able to help you if you need.

Re: jetty authentication in Eclipse Luna [message #1700920 is a reply to message #1700514] Wed, 08 July 2015 07:46 Go to previous messageGo to next message
Peter Richards is currently offline Peter RichardsFriend
Messages: 10
Registered: June 2015
Junior Member
Hello Aleksander,
I am now trying to implement the Equinox authentication as you recommended.

I fail at the point, where I should declare a LoginModule with the org.eclipse.equinox.security.loginModule extension point:
<extension  
       id="com.sample.login.RdbmsLoginModule"  
       point="org.eclipse.equinox.security.loginModule">
...

The error shown in plugin.xml is:
Unknown extension point: 'org.eclipse.equinox.security.loginModule'


I guess the reason is that my RAP target doesn't include the Equinox Core SDK. There is another explanation at https://wiki.eclipse.org/RAP/Equinox_Security_Integration , which suggests to add this SDK from http://downloads.eclipse.org/releases/helios. But I can't find it neither there nor from http://downloads.eclipse.org/releases/luna. (I am running Luna.)

How do I get the reuired org.eclipse.equinox.security bundle into my target platform together with RAP?

Thank you
Peter
Re: jetty authentication in Eclipse Luna [message #1700946 is a reply to message #1700920] Wed, 08 July 2015 11:20 Go to previous messageGo to next message
Aleksander   is currently offline Aleksander Friend
Messages: 44
Registered: May 2014
Location: France
Member
Hi, you could've started from the Eclipse for RCP & RAP devs, it contains all the useful components.

For now you can just download the SDK archive from here : http://download.eclipse.org/equinox/drops/R-LunaSR2-201502041700/index.php and integrate it to your target trough a directory.
Re: jetty authentication in Eclipse Luna [message #1700969 is a reply to message #1700946] Wed, 08 July 2015 12:54 Go to previous messageGo to next message
Peter Richards is currently offline Peter RichardsFriend
Messages: 10
Registered: June 2015
Junior Member
Well, I am using http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-rcp-luna-SR2-win32-x86_64.zip, but I couldn't find how to include the org.eclipse.equinox.security bundle in the RAP target. Anyway, I was able to import the bundle from the link you mentioned, and some simple authentication is fine. Thank you!

Two more questions:
1) I get the Subject in my Application.start() method as suggested in the "Random Eclipse Tips" article. When I access the application url a second time (in the same browser), I would like to continue with the already logged in Subject rather than asking for the credentials again. Is this possible?

2) How do I access the authenticated Subject later in my application? Do I have to save it in a session singleton class? Or does something like SecurityServices.getSubject() exist?

Thank you
Peter
Re: jetty authentication in Eclipse Luna [message #1700975 is a reply to message #1700969] Wed, 08 July 2015 13:20 Go to previous messageGo to next message
Aleksander   is currently offline Aleksander Friend
Messages: 44
Registered: May 2014
Location: France
Member

  1. Please read : https://eclipse.org/rap/developers-guide/devguide.php?topic=data-stores.html&version=2.3 , more particularly Persistent User Settings, you will have to rely on cookies as any website out there.
  2. Basically yes, there is a method in ILoginContext.getSubject() which returns a javax Subject.

Re: jetty authentication in Eclipse Luna [message #1700978 is a reply to message #1700975] Wed, 08 July 2015 13:35 Go to previous message
Peter Richards is currently offline Peter RichardsFriend
Messages: 10
Registered: June 2015
Junior Member
Excellent!
Previous Topic:RWT.BADGE support for CTabItem
Next Topic:[Incubator][Draw2d] Wrong Path translation in SWTGraphics
Goto Forum:
  


Current Time: Tue Mar 19 11:01:19 GMT 2024

Powered by FUDForum. Page generated in 0.04212 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top