Search in sources :

Example 1 with Keystone

use of com.woorea.openstack.keystone.Keystone in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenants.

public Set<Tenant> getTenants() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Set<Tenant> tenants = new HashSet<Tenant>();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    try {
        Tenants tenantList = keystone.tenants().list().execute();
        for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
            tenants.add(new OpenStackTenant((OpenStackContext) context, t));
        }
    } catch (OpenStackConnectException e) {
        throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
    } catch (OpenStackResponseException e) {
        throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
    }
    return tenants;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Tenant(com.att.cdp.zones.model.Tenant) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) HashSet(java.util.HashSet)

Example 2 with Keystone

use of com.woorea.openstack.keystone.Keystone in project AJSC by att.

the class AbstractOpenStackIdentityService method authenticate.

/**
 * @see com.att.cdp.zones.IdentityService#authenticate(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void authenticate(String principal, String credential) throws IllegalArgumentException, ZoneException {
    OpenStackContext context = (OpenStackContext) getContext();
    checkPrincipal(principal);
    checkCredential(credential);
    if (!context.isLoggedIn()) {
        try {
            keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
            tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
            /*
                 * DH868g: Allow the specification of a client connector to override the default mechanism of the
                 * service loader. This is needed to support use within an OSGi container.
                 */
            keystone = new Keystone(keystoneUrl, context.getClientConnector());
            /*
                 * dh868g: configure the client object to set any defined proxy and trusted host list
                 */
            String proxyHost = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_HOST);
            String proxyPort = context.getProperties().getProperty(ContextFactory.PROPERTY_PROXY_PORT);
            String trustedHosts = context.getProperties().getProperty(ContextFactory.PROPERTY_TRUSTED_HOSTS, "");
            if (proxyHost != null && proxyHost.length() > 0) {
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_HOST, proxyHost);
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.PROXY_PORT, proxyPort);
            }
            if (trustedHosts != null) {
                getKeystone().getProperties().setProperty(com.woorea.openstack.common.client.Constants.TRUST_HOST_LIST, trustedHosts);
            }
            // access with unscoped token
            Authentication authentication = new UsernamePassword(principal, credential);
            TokensResource tokens = getKeystone().tokens();
            TokensResource.Authenticate authenticate = tokens.authenticate(authentication);
            authenticate = authenticate.withTenantName(tenantName);
            access = authenticate.execute();
            expiresLocal = getLocalExpiration(access);
            tenant = new OpenStackTenant(context, access.getToken().getTenant());
            context.setTenant(tenant);
            tokenProvider = new OpenStackSimpleTokenProvider(access.getToken().getId());
            getKeystone().setTokenProvider(tokenProvider);
            List<Access.Service> services = access.getServiceCatalog();
            OpenStackContext osContext = context;
            osContext.registerServices(services);
            // Testing that we can access tenants already
            Tenants tenantList = getKeystone().tenants().list().execute();
            for (com.woorea.openstack.keystone.model.Tenant t : tenantList.getList()) {
                System.out.println(t);
            }
        } catch (OpenStackResponseException e) {
            throw new AuthenticationException(EELFResourceManager.format(OSMsg.PAL_OS_FAILED_PROVIDER_AUTHENTICATION, e, principal, tenantName));
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        }
    }
}
Also used : OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) AuthenticationException(com.att.cdp.exceptions.AuthenticationException) CommonIdentityService(com.att.cdp.openstack.CommonIdentityService) Tenants(com.woorea.openstack.keystone.model.Tenants) TokensResource(com.woorea.openstack.keystone.api.TokensResource) UsernamePassword(com.woorea.openstack.keystone.model.authentication.UsernamePassword) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) OpenStackSimpleTokenProvider(com.woorea.openstack.base.client.OpenStackSimpleTokenProvider) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Authentication(com.woorea.openstack.keystone.model.Authentication) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 3 with Keystone

use of com.woorea.openstack.keystone.Keystone in project AJSC by att.

the class AbstractOpenStackIdentityService method getRoles.

/**
 * @see com.att.cdp.zones.IdentityService#getRoles()
 */
@SuppressWarnings("nls")
@Override
public List<String> getRoles() throws ZoneException {
    trackRequest();
    Context context = getContext();
    ArrayList<String> list = new ArrayList<>();
    if (context.isLoggedIn()) {
        try {
            keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
            // tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
            Keystone keystone = new Keystone(keystoneUrl);
            OpenStackRequest<Roles> request = new OpenStackRequest<>(keystone, HttpMethod.GET, "/users/" + context.getPrincipal() + "/roles", null, Roles.class);
            Roles roles;
            try {
                roles = keystone.execute(request);
            } catch (OpenStackConnectException e) {
                throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
            }
            for (Role role : roles.getList()) {
                list.add(role.getName());
            }
        } catch (OpenStackResponseException e) {
            if (e.getStatus() == 404) {
                throw new ResourceNotFoundException("Attempt to get roles for user " + context.getPrincipal(), e);
            }
            throw new ZoneException("Attempt to get roles for user " + context.getPrincipal(), e);
        }
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) ArrayList(java.util.ArrayList) OpenStackRequest(com.woorea.openstack.base.client.OpenStackRequest) Roles(com.woorea.openstack.keystone.model.Roles) Role(com.woorea.openstack.keystone.model.Role) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 4 with Keystone

use of com.woorea.openstack.keystone.Keystone in project ovirt-engine by oVirt.

the class ExternalNetworkTokenProvider method getToken.

@Override
public String getToken() {
    if (access == null) {
        Keystone keystone = createKeystone(provider.getAuthUrl());
        UsernamePassword usernamePassword = new UsernamePassword(provider.getUsername(), provider.getPassword());
        access = executeKeystoneQuery(keystone, usernamePassword);
    }
    return getTokenIdFromAccess(access);
}
Also used : Keystone(com.woorea.openstack.keystone.Keystone) UsernamePassword(com.woorea.openstack.keystone.model.authentication.UsernamePassword)

Example 5 with Keystone

use of com.woorea.openstack.keystone.Keystone in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenant.

/**
 * All services must be able to return the tenant object that the user has connected to.
 *
 * @return The tenant object
 * @throws ZoneException
 *             If the user has not logged in
 * @see com.att.cdp.zones.Service#getTenant()
 */
@Override
public Tenant getTenant() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    if (tenant == null) {
        com.woorea.openstack.keystone.model.Tenants tenants;
        try {
            tenants = keystone.tenants().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
        }
        for (com.woorea.openstack.keystone.model.Tenant t : tenants) {
            if (t.getName().equals(tenantName)) {
                tenant = new OpenStackTenant((OpenStackContext) context, t);
                break;
            }
        }
    }
    return tenant;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Aggregations

Keystone (com.woorea.openstack.keystone.Keystone)5 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)4 OpenStackContext (com.att.cdp.openstack.OpenStackContext)4 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)4 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)4 ZoneException (com.att.cdp.exceptions.ZoneException)3 OpenStackTenant (com.att.cdp.openstack.model.OpenStackTenant)3 Context (com.att.cdp.zones.Context)3 Tenants (com.woorea.openstack.keystone.model.Tenants)3 UsernamePassword (com.woorea.openstack.keystone.model.authentication.UsernamePassword)2 AuthenticationException (com.att.cdp.exceptions.AuthenticationException)1 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)1 CommonIdentityService (com.att.cdp.openstack.CommonIdentityService)1 Tenant (com.att.cdp.zones.model.Tenant)1 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)1 OpenStackSimpleTokenProvider (com.woorea.openstack.base.client.OpenStackSimpleTokenProvider)1 TokensResource (com.woorea.openstack.keystone.api.TokensResource)1 Authentication (com.woorea.openstack.keystone.model.Authentication)1 Role (com.woorea.openstack.keystone.model.Role)1 Roles (com.woorea.openstack.keystone.model.Roles)1