Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Own Login-Service: ClassLoader-Problems in jetty 7.2.2

Hi,

I'm working on an own Login-Service to handle login and authentication in our webapp in jetty 7.2.2

I got a dummy-implementation working by placing the the implementation in a jar in the lib/ext-directory of jetty. This implementation doesn't have any relationship to the webapp.

But I need to access an started spring-context of my webapp which is accessible by a static method. Because of different classloaders i don't get the right class-instance.

To solve this issue I tried to set the loginService out of the ContextListener, but this is rejected with "IllegalStateException("Started") in setLoginService() of SecurityHandler.

I don't have any idea how to solve this problem. Can anybody help me? Here is my code. The getChecker() tries to resolve the bean named "acessChecker".

---------------------------------
package de.dig.ps.sys;

import de.dig.dfc.FrameworkManager;
import de.dig.dfc.security.AccessChecker;
import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.server.UserIdentity;

import javax.security.auth.Subject;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class JettyLoginService extends org.eclipse.jetty.util.component.AbstractLifeCycle implements org.eclipse.jetty.security.LoginService {
    private IdentityService identityService;
protected final ConcurrentMap<String, JettyUserIdentity> _users=new ConcurrentHashMap<String, JettyUserIdentity>();


    private AccessChecker getChecker() {
return (AccessChecker) FrameworkManager.getAppContext().getBean("accessChecker");
    }

    @Override
    public String getName() {
        return "DIG Verlagssystem";
    }

    @Override
    public UserIdentity login(String username, Object credentials) {
        JettyUserIdentity user = _users.get(username);
        if (user == null) {
            Subject subject = new Subject();
            user = new JettyUserIdentity(username, subject);
            _users.put(username, user);

        }
//        if (getChecker().authenticate(username, credentials.toString())) {
            return user;
//        }
//        return null;
    }

    @Override
    public boolean validate(UserIdentity user) {
        if (_users.containsKey(user.getUserPrincipal().getName()))
            return true;

        System.out.println("validate false");
        return false;

    }

    @Override
    public IdentityService getIdentityService() {
        return identityService;
    }

    @Override
    public void setIdentityService(IdentityService identityService) {
        this.identityService = identityService;
    }

    @Override
    public void logout(UserIdentity userIdentity) {
        System.out.println("logout");
    }
}
---------------------------------

Thanks in advance

Gerhard


Back to the top