Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding access key auth support for openstack V3 #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.jclouds.openstack.keystone.auth.domain.PasswordCredentials;
import org.jclouds.openstack.keystone.auth.domain.TenantOrDomainAndCredentials;
import org.jclouds.openstack.keystone.auth.domain.TokenCredentials;
import org.jclouds.openstack.keystone.auth.domain.ApiAccessKeyCredentials;
import org.jclouds.openstack.keystone.auth.domain.AuthInfo;
import org.jclouds.openstack.keystone.v3.binders.BindAccessKeyAuthToJsonPayload;
import org.jclouds.openstack.keystone.v3.binders.BindPasswordAuthToJsonPayload;
import org.jclouds.openstack.keystone.v3.binders.BindTokenAuthToJsonPayload;
import org.jclouds.openstack.keystone.v3.domain.Token;
Expand Down Expand Up @@ -57,4 +60,11 @@ public interface V3AuthenticationApi extends AuthenticationApi, Closeable {
@Override
Token authenticateToken(TenantOrDomainAndCredentials<TokenCredentials> credentials);

@Named("token:create")
@POST
@ResponseParser(ParseTokenFromHttpResponse.class)
@MapBinder(BindAccessKeyAuthToJsonPayload.class)
@Override
AuthInfo authenticateAccessKey(TenantOrDomainAndCredentials<ApiAccessKeyCredentials> credentials);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/
package org.jclouds.openstack.keystone.v3.binders;

import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.auth.domain.ApiAccessKeyCredentials;
import org.jclouds.openstack.keystone.auth.domain.TenantOrDomainAndCredentials;
import org.jclouds.openstack.keystone.v3.domain.Auth;

import javax.inject.Inject;
import javax.inject.Singleton;

import static java.util.Collections.singletonList;

@Singleton
public class BindAccessKeyAuthToJsonPayload extends BindAuthToJsonPayload<ApiAccessKeyCredentials> {

@Inject
protected BindAccessKeyAuthToJsonPayload(Json jsonBinder) {
super(jsonBinder);
}

@Override
protected Auth buildAuth(TenantOrDomainAndCredentials<ApiAccessKeyCredentials> credentials, Object scope) {
Auth.Identity.AccessKeyAuth accessKeyAuth = Auth.Identity.AccessKeyAuth.create(
credentials.credentials().accessKey(),
credentials.credentials().secretKey());
return Auth.create(Auth.Identity.create(singletonList("application_credential"), null, null, accessKeyAuth), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected Auth buildAuth(TenantOrDomainAndCredentials<PasswordCredentials> crede
DomainAuth domain = DomainAuth.create(credentials.tenantOrDomainName());
UserAuth user = UserAuth.create(creds.username(), domain, creds.password());

return Auth.create(Identity.create(singletonList("password"), null, PasswordAuth.create(user)), scope);
return Auth.create(Identity.create(singletonList("password"), null, PasswordAuth.create(user), null), scope);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BindTokenAuthToJsonPayload extends BindAuthToJsonPayload<TokenCrede
@Override
protected Auth buildAuth(TenantOrDomainAndCredentials<TokenCredentials> credentials, Object scope) {
Id token = Id.create(credentials.credentials().id());
return Auth.create(Identity.create(singletonList("token"), token, null), scope);
return Auth.create(Identity.create(singletonList("token"), token, null, null), scope);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ public abstract static class Identity {
@Nullable
public abstract PasswordAuth password();

@SerializedNames({ "methods", "token", "password" })
public static Identity create(List<String> methods, Id token, PasswordAuth password) {
return new AutoValue_Auth_Identity(methods, token, password);
@Nullable
public abstract AccessKeyAuth secret();

@SerializedNames({ "methods", "token", "password", "application_credential" })
public static Identity create(List<String> methods, Id token, PasswordAuth password, AccessKeyAuth accessKeyAuth) {
return new AutoValue_Auth_Identity(methods, token, password, accessKeyAuth);
}

@AutoValue
public abstract static class AccessKeyAuth {
public abstract String id();
public abstract String secret();

@SerializedNames({ "id", "secret" })
public static AccessKeyAuth create(String id, String secret) {
return new AutoValue_Auth_Identity_AccessKeyAuth(id, secret);
}
}

@AutoValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jclouds.openstack.keystone.auth.domain.PasswordCredentials;
import org.jclouds.openstack.keystone.auth.domain.TenantOrDomainAndCredentials;
import org.jclouds.openstack.keystone.auth.domain.TokenCredentials;
import org.jclouds.openstack.keystone.auth.domain.ApiAccessKeyCredentials;
import org.jclouds.openstack.keystone.v3.internal.BaseV3KeystoneApiLiveTest;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -54,4 +55,10 @@ public void testAuthenticateToken() {
.tenantOrDomainName(tenant).scope("unscoped")
.credentials(TokenCredentials.builder().id(token.get()).build()).build()));
}

public void testAuthenticateAccessKey() {
assertNotNull(authenticationApi.authenticateAccessKey(TenantOrDomainAndCredentials.<ApiAccessKeyCredentials> builder()
.tenantOrDomainName(tenant).scope("unscoped")
.credentials(ApiAccessKeyCredentials.builder().accessKey(identity).secretKey(credential).build()).build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,14 @@ private void checkTokenResult(TenantOrDomainAndCredentials<?> credentials, Strin
assertSent(server, "POST", "/auth/tokens", stringFromResource(json));
}

public void testAuthenticateAccessKey() throws InterruptedException {

TenantOrDomainAndCredentials<ApiAccessKeyCredentials> credentials = TenantOrDomainAndCredentials
.<ApiAccessKeyCredentials> builder().tenantOrDomainName("domain").scope("unscoped")
.credentials(ApiAccessKeyCredentials.builder().accessKey("identity").secretKey("credential").build()).build();


checkTokenResult(credentials, "/v3/auth-accesskey.json");
}

}
13 changes: 13 additions & 0 deletions apis/openstack-keystone/src/test/resources/v3/auth-accesskey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"auth": {
"identity": {
"methods": [
"application_credential"
],
"application_credential": {
"id": "identity",
"secret": "credential"
}
}
}
}
Loading