All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.plugins.remoting.client.authentication.AuthenticationManagerProxy Maven / Gradle / Ivy

package org.nakedobjects.plugins.remoting.client.authentication;

import org.nakedobjects.metamodel.authentication.AuthenticationSession;
import org.nakedobjects.metamodel.commons.ensure.Assert;
import org.nakedobjects.plugins.remoting.shared.ServerFacade;
import org.nakedobjects.runtime.authentication.AuthenticationManager;
import org.nakedobjects.runtime.authentication.AuthenticationRequest;
import org.nakedobjects.runtime.authentication.PasswordAuthenticationRequest;
import org.nakedobjects.runtime.context.NakedObjectsContext;


public class AuthenticationManagerProxy implements AuthenticationManager {

    private final ServerFacade connection;
    private AuthenticationSession testSession;

    public AuthenticationManagerProxy(final ServerFacade connection) {
        Assert.assertNotNull("a connection must be set up", connection);
        this.connection = connection;
    }

    public void init() {}

    public void shutdown() {}


    public AuthenticationSession authenticate(final AuthenticationRequest request) {
        if (testSession != null) {
            return testSession;
        }
        final PasswordAuthenticationRequest passwordRequest = (PasswordAuthenticationRequest) request;
        final String username = passwordRequest.getName();
        if (username == null || username.equals("")) {
            return null;
        }
        final String password = passwordRequest.getPassword();
        if (password == null || password.equals("")) {
            return null;
        }

        return connection.authenticate(username + "::" + password);
    }

    public void closeSession(final AuthenticationSession session) {
        connection.closeSession(session);
        NakedObjectsContext.closeSession();
    }


    public boolean isSessionValid(AuthenticationSession session) {
        return true;
    }

    public void testSetSession(AuthenticationSession authenticationSession) {
        this.testSession = authenticationSession;
    }

}

// Copyright (c) Naked Objects Group Ltd.




© 2015 - 2025 Weber Informatics LLC | Privacy Policy