diff --git a/dev/cosbench-keystone/META-INF/MANIFEST.MF b/dev/cosbench-keystone/META-INF/MANIFEST.MF
index e91744ef..d956d2af 100644
--- a/dev/cosbench-keystone/META-INF/MANIFEST.MF
+++ b/dev/cosbench-keystone/META-INF/MANIFEST.MF
@@ -18,5 +18,6 @@ Import-Package: com.intel.cosbench.api.auth,
org.apache.http.message;version="[4.1.4,5.0.0)",
org.apache.http.util;version="[4.1.4,5.0.0)",
org.codehaus.jackson;version="[1.4.2,2.0.0)",
+ org.codehaus.jackson.annotate;version="1.4.2",
org.codehaus.jackson.map;version="[1.4.2,2.0.0)",
org.codehaus.jackson.map.annotate;version="[1.4.2,2.0.0)"
diff --git a/dev/cosbench-keystone/src/com/intel/cosbench/api/keystone/KeystoneAuth.java b/dev/cosbench-keystone/src/com/intel/cosbench/api/keystone/KeystoneAuth.java
index 96f20389..bba41e3c 100644
--- a/dev/cosbench-keystone/src/com/intel/cosbench/api/keystone/KeystoneAuth.java
+++ b/dev/cosbench-keystone/src/com/intel/cosbench/api/keystone/KeystoneAuth.java
@@ -32,7 +32,7 @@
* This class encapsulates an Openstack Keystone implementation for the
* Auth-API.
*
- * @author ywang19, qzheng7
+ * @author ywang19, qzheng7, osmboy, digvijay2040
*
*/
class KeystoneAuth extends NoneAuth {
@@ -43,22 +43,18 @@ class KeystoneAuth extends NoneAuth {
private String url;
private String username;
private String password;
- private String userToken;
/* tenant info */
- private String tenantId;
private String tenantName;
-
- /*keystone region*/
- private String region;
+ /* domain info */
+ private String userdomain;
+ private String projectdomain;
/* service info */
private String service;
/* connection setting */
private int timeout;
-
- Logger logger = null;
public KeystoneAuth() {
/* empty */
@@ -67,33 +63,31 @@ public KeystoneAuth() {
@Override
public void init(Config config, Logger logger) {
super.init(config, logger);
- this.logger = logger;
+
url = config.get(AUTH_URL_KEY, config.get(AUTH_URL_ALTKEY, URL_DEFAULT));
username = config.get(AUTH_USERNAME_KEY, AUTH_USERNAME_DEFAULT);
password = config.get(AUTH_PASSWORD_KEY, AUTH_PASSWORD_DEFAULT);
- userToken = config.get(AUTH_USERTOKEN_KEY, AUTH_USERTOKEN_DEFAULT);
- tenantId = config.get(AUTH_TENANT_ID_KEY, AUTH_TENANT_ID_DEFAULT);
tenantName = config.get(AUTH_TENANT_NAME_KEY, config.get(AUTH_TENANT_NAME_ALTKEY, AUTH_TENANT_NAME_DEFAULT));
+ userdomain = config.get(AUTH_USER_DOMAIN_KEY, AUTH_USER_DOMAIN_DEFAULT);
+ projectdomain = config.get(AUTH_PROJECT_DOMAIN_KEY, AUTH_PROJECT_DOMAIN_DEFAULT);
service = config.get(AUTH_SERVICE_KEY, AUTH_SERVICE_DEFAULT);
timeout = config.getInt(CONN_TIMEOUT_KEY, CONN_TIMEOUT_DEFAULT);
- region = config.get(AUTH_REGION_KEY, AUTH_REGION_DEFAULT);
parms.put(AUTH_URL_KEY, url);
parms.put(AUTH_USERNAME_KEY, username);
parms.put(AUTH_PASSWORD_KEY, password);
- parms.put(AUTH_USERTOKEN_KEY, userToken);
- parms.put(AUTH_TENANT_ID_KEY, tenantId);
+ parms.put(AUTH_USER_DOMAIN_KEY, userdomain);
+ parms.put(AUTH_PROJECT_DOMAIN_KEY, projectdomain);
+
parms.put(AUTH_TENANT_NAME_KEY, tenantName);
parms.put(AUTH_SERVICE_KEY, service);
parms.put(CONN_TIMEOUT_KEY, timeout);
- parms.put(AUTH_REGION_KEY, AUTH_REGION_DEFAULT);
-
logger.debug("using auth config: {}", parms);
HttpClient httpClient = HttpClientUtil.createHttpClient(timeout);
- client = new KeystoneClient(logger, httpClient, url, username, password,
- tenantName, timeout);
+ client = new KeystoneClient(httpClient, url, username, password,
+ tenantName, userdomain,projectdomain, timeout);
logger.debug("keystone client has been initialized");
}
@@ -125,7 +119,7 @@ private AuthContext createContext() {
// context.put(AUTH_TOKEN_KEY, client.getKeystoneTokenId());
// context.put(STORAGE_URL_KEY, client.getServiceUrl(service));
// return context;
- KeystoneAuthContext context = new KeystoneAuthContext(url, username, password, service, client.getKeystoneTokenId(), client.getServiceUrl(service,region));
+ KeystoneAuthContext context = new KeystoneAuthContext(url, username, password, service, client.getKeystoneTokenId(), client.getServiceUrl(service));
return context;
}
diff --git a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneClient.java b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneClient.java
index 5983cb14..ad3bf6c1 100644
--- a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneClient.java
+++ b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneClient.java
@@ -17,18 +17,15 @@
package com.intel.cosbench.client.keystone;
-import java.util.ArrayList;
import java.util.List;
import org.apache.http.client.HttpClient;
-import com.intel.cosbench.client.keystone.KeystoneResponse.AccessInfo;
-import com.intel.cosbench.client.keystone.KeystoneResponse.AccessInfo.ServiceInfo;
-import com.intel.cosbench.client.keystone.KeystoneResponse.AccessInfo.ServiceInfo.Endpoint;
-import com.intel.cosbench.client.keystone.KeystoneResponse.AccessInfo.Token;
-import com.intel.cosbench.client.keystone.KeystoneResponse.AccessInfo.User;
+import com.intel.cosbench.client.keystone.KeystoneResponse.ServiceInfo;
+import com.intel.cosbench.client.keystone.KeystoneResponse.ServiceInfo.Endpoint;
+import com.intel.cosbench.client.keystone.KeystoneResponse.TokenInfo;
+import com.intel.cosbench.client.keystone.KeystoneResponse.User;
import com.intel.cosbench.client.keystone.handler.*;
-import com.intel.cosbench.log.Logger;
/**
* A client for Openstack keystone authentication service.
@@ -55,36 +52,37 @@
* order to get a new token that will be scoped with the specified tenant.
*
- * {"auth": ... }
- *
- *
- * @author qzheng
- */
+import java.util.Collections;
+import java.util.List;
+
+import com.intel.cosbench.client.keystone.KeystoneRequest.AuthInfo.*;;
+
public class KeystoneRequest {
private AuthInfo auth;
@@ -51,26 +39,34 @@ public AuthInfo getAuth() {
public void setAuth(AuthInfo auth) {
this.auth = auth;
}
-
- public void addCredentials(String username, String password) {
- Credentials credentials = new Credentials();
- credentials.setUsername(username);
- credentials.setPassword(password);
- auth.setPasswordCredentials(credentials);
- }
-
- public void addUserToken(String id) {
- Token token = new Token();
- token.setId(id);
- auth.setToken(token);
- }
-
- public void addTenantId(String tenantId) {
- auth.setTenantId(tenantId);
+
+ public void addProjectScope(String tenantName, String id) {
+ // TODO Auto-generated method stub
+ Scope scope = new Scope();
+ Project project = new Project();
+ Domain domain = new Domain();
+ domain.setId(id);
+ project.setDomain(domain);
+ project.setName(tenantName);
+ scope.setProject(project);
+ auth.setScope(scope);
}
- public void addTenantName(String tenantName) {
- auth.setTenantName(tenantName);
+ public void addUserScope(String username, String password, String id) {
+ // TODO Auto-generated method stub
+ Identity identity = new Identity();
+ Password pwd = new Password();
+ User user = new User();
+ Domain domain = new Domain();
+ domain.setId(id);
+ user.setDomain(domain);
+ user.setName(username);
+ user.setPassword(password);
+ pwd.setUser(user);
+ identity.setPassword(pwd);
+ identity.setMethods(Collections.singletonList("password"));
+ auth.setIdentity(identity);
+
}
// --------------------------------------------------------------------------
@@ -83,122 +79,159 @@ public void addTenantName(String tenantName) {
* compatible with the interface provided by the keystone service.
- * {"passwordCredentials": ... , "token": ... ,
- * "tenantId": "?", "tenantName": "?"}
+ * { "auth": {
+ "identity": {
+ "methods": ["password"],
+ "password": {
+ "user": {
+ "name": "admin",
+ "domain": { "id": "default" },
+ "password": "adminpwd"
+ }
+ }
+ },
+ "scope": {
+ "project": {
+ "name": "demo",
+ "domain": { "id": "default" }
+ }
+ }
+ }
+ }
*
*
* @author qzheng
*/
public static class AuthInfo {
-
- private Credentials passwordCredentials;
- private Token token;
- private String tenantId;
- private String tenantName;
-
- public Credentials getPasswordCredentials() {
- return passwordCredentials;
+
+ private Identity identity;
+ private Scope scope;
+
+ public Identity getIdentity() {
+ return identity;
+ }
+
+ public void setIdentity(Identity identity) {
+ this.identity = identity;
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ public void setScope(Scope scope) {
+ this.scope = scope;
+ }
+
+ public static class Identity {
+ private List
- * {"username": "?", "password": "?"}
- *
- *
- * @author qzheng
- */
- public static class Credentials {
-
- private String username;
+ private String name;
+ private Domain domain;
private String password;
- public String getUsername() {
- return username;
+ public String getName() {
+ return name;
}
- public void setUsername(String username) {
- this.username = username;
+ public void setName(String name) {
+ this.name = name;
}
public String getPassword() {
return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- }
-
- // ----------------------------------------------------------------------
- // AuthInfo.Token
- // ----------------------------------------------------------------------
-
- /**
- * The token meta data identified by its id. This class is specially
- * structured in a way that is compatible with the interface provided by
- * the keystone service.
- * {"id": "?"}
- *
- *
- * @author qzheng
- */
- public static class Token {
-
- private String id;
+ }
+
+ public Domain getDomain() {
+ return domain;
+ }
- public String getId() {
- return id;
- }
+ public void setDomain(Domain domain) {
+ this.domain = domain;
+ }
- public void setId(String id) {
- this.id = id;
+ public void setPassword(String password) {
+ this.password = password;
}
- }
-
+ }
}
- // --------------------------------------------------------------------------
- // End
- // --------------------------------------------------------------------------
-
}
diff --git a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneResponse.java b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneResponse.java
index 958a85db..5be88417 100644
--- a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneResponse.java
+++ b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/KeystoneResponse.java
@@ -13,229 +13,128 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+@author osmboy (lei.lei@ostorage.com.cn)
*/
package com.intel.cosbench.client.keystone;
import java.util.List;
-/**
- *
- * { "access": ... }
- *
- */
+
public class KeystoneResponse {
- private AccessInfo access;
+ private TokenInfo token;
- public AccessInfo getAccess() {
- return access;
+ public TokenInfo getToken() {
+ return token;
}
- public void setAccess(AccessInfo access) {
- this.access = access;
+ public void setToken(TokenInfo token) {
+ this.token = token;
}
- // --------------------------------------------------------------------------
- // AccessInfo
- // --------------------------------------------------------------------------
-
- /**
- *
- * { "user": ... , "token": ... , "serviceCatalog": [ ... ] }
- *
- */
- public static class AccessInfo {
+ public static class TokenInfo {
+ private String id;
+ private String name;
private User user;
- private Token token;
- private List
- * { "id": "?", "name": "?" }
- *
- */
- public static class User {
-
- private String id;
- private String name;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
+ public void setType(String type) {
+ this.type = type;
}
- // ----------------------------------------------------------------------
- // AccessInfo.Token
- // ----------------------------------------------------------------------
-
- /**
- *
- * { "id": "?", "expires": "?" }
- *
- */
- public static class Token {
-
- private String id;
- private String expires;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getExpires() {
- return expires;
- }
-
- public void setExpires(String expires) {
- this.expires = expires;
- }
+ public List
- * {"name": "?", "type": "?", "endpoints": [ ... ] }
- *
- */
- public static class ServiceInfo {
-
- private String name;
- private String type;
- private List
- * { "adminURL": "?", "internalURL": "?", "publicURL": "?" }
- *
- */
- public static class Endpoint {
-
- private String adminURL;
- private String internalURL;
- private String publicURL;
- private String region;
-
- public String getAdminURL() {
- return adminURL;
- }
-
- public void setAdminURL(String adminURL) {
- this.adminURL = adminURL;
- }
-
- public String getInternalURL() {
- return internalURL;
- }
-
- public void setInternalURL(String internalURL) {
- this.internalURL = internalURL;
- }
-
- public String getPublicURL() {
- return publicURL;
- }
-
- public void setPublicURL(String publicURL) {
- this.publicURL = publicURL;
- }
-
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
-
- }
-
}
}
- // --------------------------------------------------------------------------
- // End
- // --------------------------------------------------------------------------
-
}
diff --git a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/handler/HttpAuthHandler.java b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/handler/HttpAuthHandler.java
index b69b9490..8c359c08 100644
--- a/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/handler/HttpAuthHandler.java
+++ b/dev/cosbench-keystone/src/com/intel/cosbench/client/keystone/handler/HttpAuthHandler.java
@@ -12,14 +12,14 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
-limitations under the License.
+limitations under the License.
+@author osmboy (lei.lei@ostorage.com.cn)
*/
package com.intel.cosbench.client.keystone.handler;
import java.io.*;
import java.net.SocketTimeoutException;
-
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
@@ -32,7 +32,7 @@
public class HttpAuthHandler implements AuthHandler {
- private static final String PATH = "/tokens";
+ private static final String PATH = "/auth/tokens";
private HttpClient client;
private String url;
@@ -64,7 +64,8 @@ public KeystoneResponse POST(KeystoneRequest request) {
String e = "error receiving response from the keystone";
throw new KeystoneServerException(e, ex);
}
- return parseResponse(response.getStatusLine(), response.getEntity());
+ String token = response.getFirstHeader("X-Subject-Token").getValue();
+ return parseResponse(response.getStatusLine(), response.getEntity(), token);
}
private void prepareRequest(HttpPost method, KeystoneRequest request) {
@@ -80,7 +81,7 @@ private void prepareRequest(HttpPost method, KeystoneRequest request) {
method.addHeader("Content-Type", "application/json"); // hard coded
}
- private KeystoneResponse parseResponse(StatusLine status, HttpEntity entity) {
+ private KeystoneResponse parseResponse(StatusLine status, HttpEntity entity, String token) {
String json = null;
int code = status.getStatusCode();
try {
@@ -96,7 +97,7 @@ private KeystoneResponse parseResponse(StatusLine status, HttpEntity entity) {
} finally {
clearResponse(entity);
}
- return mapper.fromJson(json, KeystoneResponse.class);
+ return mapper.fromJson(json, KeystoneResponse.class, token);
}
private void clearResponse(HttpEntity entity) {