/** * This method determines the local time that the current token (held in the Access object) will expire. * * @param accessKey * The access to be checked * @return The local time the token expires */ private static long getLocalExpiration(Access accessKey) { Date now = Time.getCurrentUTCDate(); if (accessKey != null && accessKey.getToken() != null) { Calendar issued = accessKey.getToken().getIssued_at(); Calendar expires = accessKey.getToken().getExpires(); if (issued != null && expires != null) { long tokenLife = expires.getTimeInMillis() - issued.getTimeInMillis(); return now.getTime() + tokenLife; } } return now.getTime(); }
/** * This method is used to locate a service from the OpenStack service catalog if it is available. * * @param serviceType * The type of service requested (such as "image"). * @param access * The security access object to be used * @return A reference to the <code>Service</code> object, or null if not available. */ public Service locateService(String serviceType, Access access) { for (Service service : access.getServiceCatalog()) { if (service.getType().equals(serviceType)) { return service; } } getLogger().error(EELFResourceManager.format(OSMsg.PAL_OS_LOCATE_SERVICE_FAILED, serviceType)); return null; }
/** * @param args */ public static void main(String[] args) { Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); // access with unscoped token Access access = keystone.tokens().authenticate( new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) .execute(); // use the token in the following requests keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); Tenants tenants = keystone.tenants().list().execute(); // try to exchange token using the first tenant if (tenants.getList().size() > 0) { // access with tenant access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); Networks networks = quantum.networks().list().execute(); for (Network network : networks) { System.out.println(network); } } else { System.out.println("No tenants found!"); } } }
.execute(); keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); Quantum quantumClient = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); quantumClient.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));
@Override public String getToken() { return keystoneTokenProvider.getAccessByTenant(tenantName) .getToken().getId(); } @Override
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);
String endpointURL = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "orchestration", null, "public");
@Override public String getToken() { return keystoneTokenProvider.getAccessByTenant(tenantName) .getToken().getId(); } @Override
keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); Swift swift = new Swift(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "object-store", null, "public")); swift.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId()));
for (Service service : access.getServiceCatalog()) { if (service.getType().equals("image")) { glanceService = service;
/** * @see com.woorea.openstack.base.client.OpenStackTokenProvider#getToken() */ @Override public String getToken() throws OpenStackConnectException, OpenStackResponseException { return keystoneTokenProvider.getAccessByTenant(tenantName).getToken().getId(); }
.getToken().getId())); keystone.token(access.getToken().getId()); Tenants tenants = keystone.tenants().list().execute(); .tokens() .authenticate( new TokenAuthentication(access.getToken().getId())) .withTenantId("tenantId").execute(); Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL( access.getServiceCatalog(), "network", null, "public")); quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access .getToken().getId())); NetworkForCreate netcreate = new NetworkForCreate(); netcreate.setTenantId("tenantId");
/** * @param connector * The connector to be updated with the new token */ public synchronized void refreshIfStale(Connector connector) { String logId = "PAL-5558"; Logger appLogger = getLogger(); appLogger.info(new Date().toString()+ " " + logId+":OpenStackContext.refreshIfStale - in"); if (isStale()) { appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - Connection is stale"); try { logout(); relogin(); } catch (IllegalStateException | IllegalArgumentException | ZoneException e) { e.printStackTrace(); } } appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - old token -"+connector.getAccess().getToken().getId()); connector.updateToken(); appLogger.info(new Date().toString()+ " " +logId+":OpenStackContext.refreshIfStale - new token -"+connector.getAccess().getToken().getId()); }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); keystone.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); glance.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); heat.token(getAccess().getToken().getId()); }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); quantum.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); cinder.token(getAccess().getToken().getId()); } }
/** * Updates the expired token by re-authenticating, getting a new unexpired token (in the access object), and then * updating the token held by this client wrapped by this connector to use the new token. * * @see com.att.cdp.openstack.connectors.Connector#updateToken() */ @Override public void updateToken() { super.updateToken(); nova.token(getAccess().getToken().getId()); } }
this.token = access.getToken().getId(); keystone.token(this.token);