Skip to content

Commit

Permalink
Adding access key auth support for openstack V3
Browse files Browse the repository at this point in the history
  • Loading branch information
DImuthuUpe committed May 2, 2022
1 parent 4c18cac commit c0bdf26
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
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,10 @@ 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);
}
@@ -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);
}
}
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);
}

}
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);
}

}
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

0 comments on commit c0bdf26

Please sign in to comment.