|
|
|
@ -26,8 +26,7 @@ public class InformationSystemUtils {
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IAMService retrieveIAMService(String scope, String token) throws Exception {
|
|
|
|
|
public static IAMService retrieveIAMService(String scope) throws Exception {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logger.debug("Retrieve IAM Service on IS");
|
|
|
|
@ -35,8 +34,10 @@ public class InformationSystemUtils {
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
|
throw new Exception("Invalid scope: " + scope);
|
|
|
|
|
|
|
|
|
|
if (token == null || token.isEmpty())
|
|
|
|
|
throw new Exception("Invalid token: " + scope);
|
|
|
|
|
/*
|
|
|
|
|
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
|
|
|
|
* scope);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
@ -45,19 +46,19 @@ public class InformationSystemUtils {
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
|
|
|
|
query.addCondition("$resource/Profile/Category/text() eq '" + Constants.IAM_SERVICE_CATEGORY + "'")
|
|
|
|
|
.addCondition("$resource/Profile/Name/text() eq '" + Constants.IAM_SERVICE_NAME + "'");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
|
|
|
|
|
|
|
|
|
List<ServiceEndpoint> resources = client.submit(query);
|
|
|
|
|
|
|
|
|
|
IAMService iamService=null;
|
|
|
|
|
|
|
|
|
|
if(resources!=null&&!resources.isEmpty()) {
|
|
|
|
|
ServiceEndpoint iams=resources.get(0);
|
|
|
|
|
iamService=new IAMService(iams.profile().runtime().hostedOn());
|
|
|
|
|
IAMService iamService = null;
|
|
|
|
|
|
|
|
|
|
if (resources != null && !resources.isEmpty()) {
|
|
|
|
|
ServiceEndpoint iams = resources.get(0);
|
|
|
|
|
iamService = new IAMService(iams.profile().runtime().hostedOn());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.debug("IAM Services retrieved: {}",iamService);
|
|
|
|
|
|
|
|
|
|
logger.debug("IAM Services retrieved: {}", iamService);
|
|
|
|
|
return iamService;
|
|
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
@ -67,7 +68,7 @@ public class InformationSystemUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope, String token) throws Exception {
|
|
|
|
|
public static ArrayList<DefinitionItem> retrieveSSD(String category, String scope) throws Exception {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
logger.debug("Retrieve System Services Definition on IS");
|
|
|
|
@ -75,8 +76,10 @@ public class InformationSystemUtils {
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
|
throw new Exception("Invalid scope: " + scope);
|
|
|
|
|
|
|
|
|
|
if (token == null || token.isEmpty())
|
|
|
|
|
throw new Exception("Invalid token: " + scope);
|
|
|
|
|
/*
|
|
|
|
|
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
|
|
|
|
* scope);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
@ -116,8 +119,7 @@ public class InformationSystemUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void publishSSD(DefinitionItem definitionItem, String category, String scope, String token)
|
|
|
|
|
throws Exception {
|
|
|
|
|
public static void publishSSD(DefinitionItem definitionItem, String category, String scope) throws Exception {
|
|
|
|
|
if (definitionItem == null)
|
|
|
|
|
throw new Exception("Invalid definition: " + definitionItem);
|
|
|
|
|
|
|
|
|
@ -127,56 +129,56 @@ public class InformationSystemUtils {
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
|
throw new Exception("Invalid scope: " + scope);
|
|
|
|
|
|
|
|
|
|
if (token == null || token.isEmpty())
|
|
|
|
|
throw new Exception("Invalid token: " + token);
|
|
|
|
|
/*
|
|
|
|
|
* if (token == null || token.isEmpty()) throw new Exception("Invalid token: " +
|
|
|
|
|
* token);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
IAMService iamService = retrieveIAMService(scope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IAMService iamService=retrieveIAMService(scope, token);
|
|
|
|
|
|
|
|
|
|
ServiceEndpoint toPublish = new ServiceEndpoint();
|
|
|
|
|
logger.debug("Resource Type: {}",toPublish.type());
|
|
|
|
|
logger.debug("Resource Type: {}", toPublish.type());
|
|
|
|
|
/*
|
|
|
|
|
* List<String> scopes = new ArrayList<String>(); scopes.add(scope);
|
|
|
|
|
* Collection<String> col = toPublish.scopes().asCollection();
|
|
|
|
|
* col.addAll(scopes);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toPublish.newProfile();
|
|
|
|
|
toPublish.profile().name(definitionItem.getClientId());
|
|
|
|
|
toPublish.profile().description(definitionItem.getDescription());
|
|
|
|
|
toPublish.profile().category(category);
|
|
|
|
|
toPublish.profile().version("1.0.0");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toPublish.profile().newRuntime();
|
|
|
|
|
toPublish.profile().runtime().ghnId("");
|
|
|
|
|
toPublish.profile().runtime().status("READY");
|
|
|
|
|
toPublish.profile().runtime().hostedOn("d4science.org");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toPublish.profile().newPlatform();
|
|
|
|
|
toPublish.profile().platform().name("d4science");
|
|
|
|
|
toPublish.profile().platform().version((short) 0);
|
|
|
|
|
toPublish.profile().platform().minorVersion((short) 0);
|
|
|
|
|
toPublish.profile().platform().revisionVersion((short) 0);
|
|
|
|
|
toPublish.profile().platform().buildVersion((short) 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AccessPoint accessPoint = new AccessPoint();
|
|
|
|
|
|
|
|
|
|
// String encryptedPassword =
|
|
|
|
|
// StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
|
|
|
|
String encryptedPassword = StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
|
|
|
|
accessPoint.name(definitionItem.getClientId());
|
|
|
|
|
accessPoint.description("Keycloak client credentials");
|
|
|
|
|
accessPoint.address(iamService.getAddress());
|
|
|
|
|
accessPoint.credentials(definitionItem.getSecret(), definitionItem.getUsername());
|
|
|
|
|
accessPoint.credentials(encryptedPassword, definitionItem.getUsername());
|
|
|
|
|
toPublish.profile().accessPoints().add(accessPoint);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Request publish: {}", toPublish);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
|
//SecurityTokenProvider.instance.set(token);
|
|
|
|
|
// SecurityTokenProvider.instance.set(token);
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
|
|
|
|
|
|
|
|
|
String id = publisher.create(toPublish).id();
|
|
|
|
@ -191,6 +193,49 @@ public class InformationSystemUtils {
|
|
|
|
|
logger.debug("Published on IS");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void deleteSSD(DefinitionItem definitionItem, String category, String scope) throws Exception {
|
|
|
|
|
if (definitionItem == null)
|
|
|
|
|
throw new Exception("Invalid definition: " + definitionItem);
|
|
|
|
|
|
|
|
|
|
if (category == null || category.isEmpty())
|
|
|
|
|
throw new Exception("Invalid category: " + category);
|
|
|
|
|
|
|
|
|
|
if (scope == null || scope.isEmpty())
|
|
|
|
|
throw new Exception("Invalid scope: " + scope);
|
|
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
// AccessTokenProvider.instance.set(token);
|
|
|
|
|
// SecurityTokenProvider.instance.set(token);
|
|
|
|
|
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
|
|
|
|
query.addCondition("$resource/Profile/Category/text() eq '" + category + "'")
|
|
|
|
|
.addCondition("$resource/Profile/Name/text() eq '" + definitionItem.getClientId() + "'");
|
|
|
|
|
|
|
|
|
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
|
|
|
|
|
|
|
|
|
List<ServiceEndpoint> resources = client.submit(query);
|
|
|
|
|
|
|
|
|
|
if (resources != null && !resources.isEmpty()) {
|
|
|
|
|
ServiceEndpoint toDelete=resources.get(0);
|
|
|
|
|
logger.debug("Requested delete: {}", toDelete);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
|
|
|
|
publisher.remove(toDelete);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("Error publishing the ssd on IS: {}", e.getLocalizedMessage(), e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logger.debug("Deleted on IS");
|
|
|
|
|
} else {
|
|
|
|
|
String error="No resources found with name: "+definitionItem.getClientId();
|
|
|
|
|
logger.error(error);
|
|
|
|
|
throw new Exception(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|