mirror of https://github.com/apache/jclouds.git
Issue 926: cleaned up usage of authentication client
This commit is contained in:
parent
8c2cc935b8
commit
f1c02d092f
|
@ -46,18 +46,29 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
public interface AuthenticationAsyncClient {
|
||||
|
||||
/**
|
||||
* @see AuthenticationClient#authenticateTenantWithCredentials(String,PasswordCredentials)
|
||||
* @see AuthenticationClient#authenticateWithTenantNameAndCredentials(String,PasswordCredentials)
|
||||
*/
|
||||
@POST
|
||||
@SelectJson("access")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/tokens")
|
||||
@MapBinder(BindAuthToJsonPayload.class)
|
||||
ListenableFuture<Access> authenticateTenantWithCredentials(@PayloadParam("tenantName") String tenantId,
|
||||
ListenableFuture<Access> authenticateWithTenantNameAndCredentials(@PayloadParam("tenantName") String tenantName,
|
||||
PasswordCredentials passwordCredentials);
|
||||
|
||||
/**
|
||||
* @see AuthenticationClient#authenticateWithTenantIdAndCredentials(String,PasswordCredentials)
|
||||
*/
|
||||
@POST
|
||||
@SelectJson("access")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/tokens")
|
||||
@MapBinder(BindAuthToJsonPayload.class)
|
||||
ListenableFuture<Access> authenticateWithTenantIdAndCredentials(@PayloadParam("tenantId") String tenantId,
|
||||
PasswordCredentials passwordCredentials);
|
||||
|
||||
/**
|
||||
* @see AuthenticationClient#authenticateTenantWithCredentials(String,ApiAccessKeyCredentials)
|
||||
* @see AuthenticationClient#authenticateWithTenantNameAndCredentials(String,ApiAccessKeyCredentials)
|
||||
*/
|
||||
@POST
|
||||
@SelectJson("access")
|
||||
|
@ -66,17 +77,17 @@ public interface AuthenticationAsyncClient {
|
|||
@MapBinder(BindAuthToJsonPayload.class)
|
||||
// TODO: is tenantName permanent? or should we switch to tenantId at some point. seems most tools
|
||||
// still use tenantName
|
||||
ListenableFuture<Access> authenticateTenantWithCredentials(@PayloadParam("tenantName") String tenantId,
|
||||
ListenableFuture<Access> authenticateWithTenantNameAndCredentials(@PayloadParam("tenantName") String tenantName,
|
||||
ApiAccessKeyCredentials apiAccessKeyCredentials);
|
||||
|
||||
/**
|
||||
* @see AuthenticationClient#authenticateTenantWithCredentials(String,ApiAccessKeyCredentials)
|
||||
* @see AuthenticationClient#authenticateWithTenantIdAndCredentials(String,ApiAccessKeyCredentials)
|
||||
*/
|
||||
@POST
|
||||
@SelectJson("access")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Path("/tokens")
|
||||
@MapBinder(BindAuthToJsonPayload.class)
|
||||
ListenableFuture<Access> authenticateTenantWithTenantIdAndCredentials(@PayloadParam("tenantId") String tenantId,
|
||||
ListenableFuture<Access> authenticateWithTenantIdAndCredentials(@PayloadParam("tenantId") String tenantId,
|
||||
ApiAccessKeyCredentials apiAccessKeyCredentials);
|
||||
}
|
||||
|
|
|
@ -42,19 +42,26 @@ public interface AuthenticationClient {
|
|||
*
|
||||
* @return access with token
|
||||
*/
|
||||
Access authenticateTenantWithCredentials(String tenantId, PasswordCredentials passwordCredentials);
|
||||
Access authenticateWithTenantNameAndCredentials(String tenantId, PasswordCredentials passwordCredentials);
|
||||
|
||||
/**
|
||||
* Authenticate to generate a token.
|
||||
*
|
||||
* @return access with token
|
||||
*/
|
||||
Access authenticateTenantWithCredentials(String tenantId, ApiAccessKeyCredentials passwordCredentials);
|
||||
Access authenticateWithTenantIdAndCredentials(String tenantId, PasswordCredentials passwordCredentials);
|
||||
|
||||
/**
|
||||
* Authenticate to generate a token.
|
||||
*
|
||||
* @return access with token
|
||||
*/
|
||||
Access authenticateWithTenantNameAndCredentials(String tenantId, ApiAccessKeyCredentials passwordCredentials);
|
||||
|
||||
/**
|
||||
* Authenticate to generate a token.
|
||||
*
|
||||
* @return access with token
|
||||
*/
|
||||
Access authenticateTenantWithTenantIdAndCredentials(String tenantId, ApiAccessKeyCredentials passwordCredentials);
|
||||
Access authenticateWithTenantIdAndCredentials(String tenantId, ApiAccessKeyCredentials passwordCredentials);
|
||||
}
|
|
@ -42,7 +42,7 @@ public class AuthenticateApiAccessKeyCredentials implements Function<Credentials
|
|||
public Access apply(Credentials input) {
|
||||
if (input.identity.indexOf(':') == -1) {
|
||||
throw new AuthorizationException(String.format("Identity %s does not match format tenantName:accessKey",
|
||||
input.identity), null);
|
||||
input.identity), null);
|
||||
}
|
||||
|
||||
String tenantId = input.identity.substring(0, input.identity.indexOf(':'));
|
||||
|
@ -50,12 +50,12 @@ public class AuthenticateApiAccessKeyCredentials implements Function<Credentials
|
|||
String passwordOrSecretKey = input.credential;
|
||||
|
||||
ApiAccessKeyCredentials apiAccessKeyCredentials = ApiAccessKeyCredentials.createWithAccessKeyAndSecretKey(
|
||||
usernameOrAccessKey, passwordOrSecretKey);
|
||||
usernameOrAccessKey, passwordOrSecretKey);
|
||||
Access access;
|
||||
if(tenantId.matches("[0-9]*")) {
|
||||
access = client.authenticateTenantWithTenantIdAndCredentials(tenantId, apiAccessKeyCredentials);
|
||||
if (tenantId.matches("^[0-9]+$")) {
|
||||
access = client.authenticateWithTenantIdAndCredentials(tenantId, apiAccessKeyCredentials);
|
||||
} else {
|
||||
access = client.authenticateTenantWithCredentials(tenantId, apiAccessKeyCredentials);
|
||||
access = client.authenticateWithTenantNameAndCredentials(tenantId, apiAccessKeyCredentials);
|
||||
}
|
||||
return access;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.keystone.v2_0.functions;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.domain.Credentials;
|
||||
|
@ -39,16 +40,22 @@ public class AuthenticatePasswordCredentials implements Function<Credentials, Ac
|
|||
public Access apply(Credentials input) {
|
||||
if (input.identity.indexOf(':') == -1) {
|
||||
throw new AuthorizationException(String.format("Identity %s does not match format tenantId:username",
|
||||
input.identity), null);
|
||||
input.identity), null);
|
||||
}
|
||||
|
||||
|
||||
String tenantId = input.identity.substring(0, input.identity.indexOf(':'));
|
||||
String usernameOrAccessKey = input.identity.substring(input.identity.indexOf(':') + 1);
|
||||
String passwordOrSecretKey = input.credential;
|
||||
|
||||
PasswordCredentials passwordCredentials = PasswordCredentials.createWithUsernameAndPassword(usernameOrAccessKey,
|
||||
passwordOrSecretKey);
|
||||
return client.authenticateTenantWithCredentials(tenantId, passwordCredentials);
|
||||
passwordOrSecretKey);
|
||||
Access access;
|
||||
if (tenantId.matches("^[0-9]+$")) {
|
||||
access = client.authenticateWithTenantIdAndCredentials(tenantId, passwordCredentials);
|
||||
} else {
|
||||
access = client.authenticateWithTenantNameAndCredentials(tenantId, passwordCredentials);
|
||||
}
|
||||
return access;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue