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

Support dynamic client providers #31

Merged
merged 8 commits into from
Feb 26, 2021
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
46 changes: 46 additions & 0 deletions core/src/main/java/org/apache/airavata/mft/core/AuthZToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.apache.airavata.mft.core;

public class AuthZToken {

private String mftAuthorizationToken;
private String agentId;
private String agentSecret;

public AuthZToken(String mftAuthorizationToken, String agentId, String agentSecret) {
this.mftAuthorizationToken = mftAuthorizationToken;
this.agentId = agentId;
this.agentSecret = agentSecret;
}

public AuthZToken(String mftAuthorizationToken) {
this.mftAuthorizationToken = mftAuthorizationToken;
}

public AuthZToken(){

}

public String getMftAuthorizationToken() {
return mftAuthorizationToken;
}

public void setMftAuthorizationToken(String mftAuthorizationToken) {
this.mftAuthorizationToken = mftAuthorizationToken;
}

public String getAgentId() {
return agentId;
}

public void setAgentId(String agentId) {
this.agentId = agentId;
}

public String getAgentSecret() {
return agentSecret;
}

public void setAgentSecret(String agentSecret) {
this.agentSecret = agentSecret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.airavata.mft.secret.server;

import org.apache.airavata.mft.secret.server.backend.custos.CustosClientsFactory;
import org.apache.airavata.mft.secret.server.backend.custos.auth.AgentAuthenticationHandler;
import org.apache.custos.clients.CustosClientProvider;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -42,16 +43,13 @@ public class AppConfig {
private String custosSecret;

@Bean
public CustosClientProvider custosClientProvider() {
return new CustosClientProvider.Builder().setServerHost(custosHost)
.setServerPort(custosPort)
.setClientId(custosId)
.setClientSec(custosSecret).build();
public CustosClientsFactory custosClientsFactory() {
return new CustosClientsFactory(custosHost, custosPort, custosId, custosSecret);
}

@Bean
public AgentAuthenticationHandler agentAuthenticationHandler() throws IOException {
return new AgentAuthenticationHandler(custosId, custosClientProvider());
return new AgentAuthenticationHandler(custosId, custosSecret, custosClientsFactory());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.apache.airavata.mft.secret.server.backend.custos;

import org.apache.custos.clients.CustosClientProvider;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class CustosClientsFactory {

private String custosHost;

private int custosPort;

private Map<String, CustosClientProvider> custosClientProviderMap = new ConcurrentHashMap<>();

public CustosClientsFactory(String custosHost, int custosPort, String custosId, String custosSecret) {
this.custosHost = custosHost;
this.custosPort = custosPort;
CustosClientProvider custosClientProvider = new CustosClientProvider.Builder().setServerHost(custosHost)
.setServerPort(custosPort)
.setClientId(custosId)
.setClientSec(custosSecret).build();
custosClientProviderMap.put(custosId, custosClientProvider);

}


public CustosClientProvider getCustosClientProvider(String custosId, String custosSecret) {

if (custosClientProviderMap.containsKey(custosId)) {
return custosClientProviderMap.get(custosId);
}

CustosClientProvider custosClientProvider = new CustosClientProvider.Builder().setServerHost(custosHost)
.setServerPort(custosPort)
.setClientId(custosId)
.setClientSec(custosSecret).build();
custosClientProviderMap.put(custosId, custosClientProvider);
return custosClientProvider;

}

public Optional<CustosClientProvider> getCustosClientProvider(String custosId) {

if (custosClientProviderMap.containsKey(custosId)) {
return Optional.of(custosClientProviderMap.get(custosId));
}
return Optional.empty();

}


}
Loading