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

nl.tweeenveertig.openstack.client.factory.AccountFactory Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
package nl.tweeenveertig.openstack.client.factory;

import nl.tweeenveertig.openstack.model.Account;
import nl.tweeenveertig.openstack.model.Client;
import nl.tweeenveertig.openstack.client.impl.ClientImpl;
import nl.tweeenveertig.openstack.client.mock.ClientMock;
import org.apache.http.client.HttpClient;

public class AccountFactory {

    private AccountConfig config;

    private HttpClient httpClient;

    private boolean allowReauthenticate = true; // Default behaviour is to allow re-authentication

    public void setConfig(AccountConfig config) {
        this.config = config;
    }

    public void setHttpClient(HttpClient httpClient) {
        this.httpClient = httpClient;
    }

    public void setAllowReauthenticate(boolean allowReauthenticate) {
        this.allowReauthenticate = allowReauthenticate;
    }

    public Account createAccount() {
        Client client;
        if (config.isMock()) {
            client = new ClientMock().setAllowEveryone(true);
        } else {
            client = createClientImpl();
        }
        return client
                .authenticate(config.getTenant(), config.getUsername(), config.getPassword(), config.getAuthUrl())
                .setAllowReauthenticate(this.allowReauthenticate);
    }

    protected ClientImpl createClientImpl() {
        ClientImpl client = new ClientImpl();
        if (this.httpClient != null) {
            client.setHttpClient(this.httpClient);
        }
        return client;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy