Skip to content

Commit

Permalink
Added AAMClient in AbstractSymbIoTeClientFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
vthglyk committed Jul 13, 2018
1 parent 30bc939 commit 7bc288c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import eu.h2020.symbiote.client.feign.SymbIoTeFeignClientFactory;
import eu.h2020.symbiote.client.interfaces.*;
import eu.h2020.symbiote.security.commons.exceptions.custom.SecurityHandlerException;
import eu.h2020.symbiote.security.communication.IAAMClient;

import java.security.NoSuchAlgorithmException;

Expand Down Expand Up @@ -45,6 +46,8 @@ public static AbstractSymbIoTeClientFactory getFactory(Config config)

public abstract PRClient getPRClient();

public abstract IAAMClient getAAMClient();

/**
* The type of factory. For now there is just one type but we followed the abstract factory pattern to facilitate
* future extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
import eu.h2020.symbiote.client.interfaces.*;
import eu.h2020.symbiote.security.ClientSecurityHandlerFactory;
import eu.h2020.symbiote.security.commons.exceptions.custom.SecurityHandlerException;
import eu.h2020.symbiote.security.communication.AAMClient;
import eu.h2020.symbiote.security.communication.IAAMClient;
import eu.h2020.symbiote.security.communication.payloads.AAM;
import eu.h2020.symbiote.security.handler.ISecurityHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

/**
* Factory for creating Feign symbIoTe clients
Expand All @@ -20,6 +26,8 @@
*/
public class SymbIoTeFeignClientFactory extends AbstractSymbIoTeClientFactory {

private static final Log logger = LogFactory.getLog(SymbIoTeFeignClientFactory.class);

private final ISecurityHandler securityHandler;
private final String coreAddress;
private final String homePlatformId;
Expand Down Expand Up @@ -99,4 +107,15 @@ public RAPClient getRapClient() {
public PRClient getPRClient() {
return new FeignPRClient(securityHandler, homePlatformId, username, password, clientId);
}

@Override
public IAAMClient getAAMClient() {
try {
Map<String, AAM> availableAAMs = securityHandler.getAvailableAAMs();
return new AAMClient(availableAAMs.get(homePlatformId).getAamAddress());
} catch (SecurityHandlerException e) {
logger.error("Could not create AAMClient", e);
}
return null;
}
}

0 comments on commit 7bc288c

Please sign in to comment.