Search in sources :

Example 1 with Role

use of com.woorea.openstack.keystone.model.Role 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)

Aggregations

ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)1 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)1 ZoneException (com.att.cdp.exceptions.ZoneException)1 OpenStackContext (com.att.cdp.openstack.OpenStackContext)1 Context (com.att.cdp.zones.Context)1 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)1 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)1 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)1 Keystone (com.woorea.openstack.keystone.Keystone)1 Role (com.woorea.openstack.keystone.model.Role)1 Roles (com.woorea.openstack.keystone.model.Roles)1 ArrayList (java.util.ArrayList)1