Added delete operation
This commit is contained in:
parent
8fb3eb9a9d
commit
e7a98ef0aa
54
pom.xml
54
pom.xml
|
@ -17,12 +17,27 @@
|
||||||
<description>
|
<description>
|
||||||
Requesting Party Token Portlet
|
Requesting Party Token Portlet
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
|
||||||
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<name>Giancarlo Panichi</name>
|
||||||
|
<email>g.panichi@isti.cnr.it</email>
|
||||||
|
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
|
||||||
|
<roles>
|
||||||
|
<role>architect</role>
|
||||||
|
<role>developer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
@ -147,38 +162,22 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources.discovery</groupId>
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
<artifactId>ic-client</artifactId>
|
<artifactId>ic-client</artifactId>
|
||||||
<version>1.0.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope-maps</artifactId>
|
<artifactId>common-scope-maps</artifactId>
|
||||||
<version>1.1.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
<!-- <dependency> <groupId>org.gcube.resourcemanagement</groupId> <artifactId>resourcemanager-client</artifactId>
|
||||||
<dependency>
|
<version>[1.0.0, 2.0.0-SNAPSHOT)</version> <scope>compile</scope> </dependency> -->
|
||||||
<groupId>org.gcube.resourcemanagement</groupId>
|
|
||||||
<artifactId>resourcemanager-client</artifactId>
|
|
||||||
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency> -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources</groupId>
|
<groupId>org.gcube.resources</groupId>
|
||||||
<artifactId>registry-publisher</artifactId>
|
<artifactId>registry-publisher</artifactId>
|
||||||
<version>1.3.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
<!-- <dependency> <groupId>org.gcube.resourcemanagement</groupId> <artifactId>ghn-manager-client</artifactId>
|
||||||
<dependency>
|
<version>[1.1.0, 2.0.0-SNAPSHOT)</version> <scope>compile</scope> </dependency> -->
|
||||||
<groupId>org.gcube.resourcemanagement</groupId>
|
<!-- <dependency> <groupId>org.gcube.resources</groupId> <artifactId>common-gcore-resources</artifactId>
|
||||||
<artifactId>ghn-manager-client</artifactId>
|
</dependency> -->
|
||||||
<version>[1.1.0, 2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency> -->
|
|
||||||
<!--
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.gcube.resources</groupId>
|
|
||||||
<artifactId>common-gcore-resources</artifactId>
|
|
||||||
</dependency> -->
|
|
||||||
|
|
||||||
<!-- Common Encryption -->
|
<!-- Common Encryption -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -232,7 +231,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.liferay.maven.plugins</groupId>
|
<groupId>com.liferay.maven.plugins</groupId>
|
||||||
<artifactId>liferay-maven-plugin</artifactId>
|
<artifactId>liferay-maven-plugin</artifactId>
|
||||||
|
@ -254,7 +253,7 @@
|
||||||
<pluginType>portlet</pluginType>
|
<pluginType>portlet</pluginType>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
@ -263,13 +262,16 @@
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${maven.compiler.target}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<!--
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<encoding>${project.build.resources.encoding}</encoding>
|
<encoding>${project.build.resources.encoding}</encoding>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin> -->
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -20,7 +20,7 @@ import org.gcube.portlets.admin.systemservicedefinition.definition.DefClientIdCo
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefDescriptionComparator;
|
import org.gcube.portlets.admin.systemservicedefinition.definition.DefDescriptionComparator;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.event.CreateSSDEvent;
|
import org.gcube.portlets.admin.systemservicedefinition.event.CreateSSDEvent;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.event.CreateSSDEventPublisher;
|
import org.gcube.portlets.admin.systemservicedefinition.event.DeleteSSDEvent;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.is.InformationSystemUtils;
|
import org.gcube.portlets.admin.systemservicedefinition.is.InformationSystemUtils;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.shared.Constants;
|
import org.gcube.portlets.admin.systemservicedefinition.shared.Constants;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.util.UserCredentials;
|
import org.gcube.portlets.admin.systemservicedefinition.util.UserCredentials;
|
||||||
|
@ -209,7 +209,7 @@ public class SystemServiceDefinition extends MVCPortlet {
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
itemsList = InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY,
|
itemsList = InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY,
|
||||||
userCredentials.getCurrentScope(), userCredentials.getAccessToken());
|
userCredentials.getCurrentScope());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error retrieving System Services from IS. {}", e.getLocalizedMessage(), e);
|
logger.error("Error retrieving System Services from IS. {}", e.getLocalizedMessage(), e);
|
||||||
throw new PortletException("Error retrieving System Services from IS. " + e.getLocalizedMessage(), e);
|
throw new PortletException("Error retrieving System Services from IS. " + e.getLocalizedMessage(), e);
|
||||||
|
@ -364,8 +364,8 @@ public class SystemServiceDefinition extends MVCPortlet {
|
||||||
String secret = UUID.randomUUID().toString();
|
String secret = UUID.randomUUID().toString();
|
||||||
DefinitionItem definitionItem = new DefinitionItem(clientId, description, username, secret);
|
DefinitionItem definitionItem = new DefinitionItem(clientId, description, username, secret);
|
||||||
InformationSystemUtils.publishSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
InformationSystemUtils.publishSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||||
userCredentials.getCurrentScope(), userCredentials.getAccessToken());
|
userCredentials.getCurrentScope());
|
||||||
// publishCreateSSDEvent(definitionItem);
|
publishCreateSSDEvent(definitionItem);
|
||||||
SessionMessages.add(actionRequest, "success-definition-created");
|
SessionMessages.add(actionRequest, "success-definition-created");
|
||||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -393,17 +393,7 @@ public class SystemServiceDefinition extends MVCPortlet {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publishCreateSSDEvent(DefinitionItem definitionItem) {
|
|
||||||
logger.debug("Trying to send the event to create System Service");
|
|
||||||
CreateSSDEvent toSend = new CreateSSDEvent(definitionItem);
|
|
||||||
new CreateSSDEventPublisher().publish(toSend);
|
|
||||||
logger.info("Done send event " + toSend.getName() + " for " + toSend.getUser());
|
|
||||||
try {
|
|
||||||
Thread.sleep(2000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void editDefinition(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
|
public void editDefinition(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -465,33 +455,64 @@ public class SystemServiceDefinition extends MVCPortlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
paramsInfo(actionRequest);
|
paramsInfo(actionRequest);
|
||||||
|
|
||||||
|
|
||||||
|
logger.debug("Delete Request");
|
||||||
|
String clientId = ParamUtil.getString(actionRequest, "clientId");
|
||||||
|
if (clientId == null || clientId.isEmpty()) {
|
||||||
|
logger.error("Invalid client id: " + clientId);
|
||||||
|
SessionErrors.add(actionRequest, "error-invalid-clientId");
|
||||||
|
SessionMessages.add(actionRequest,
|
||||||
|
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
||||||
|
PortalUtil.copyRequestParameters(actionRequest, actionResponse);
|
||||||
|
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
DefinitionItem definitionItem=new DefinitionItem(clientId);
|
||||||
|
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||||
|
userCredentials.getCurrentScope());
|
||||||
|
publishDeleteSSDEvent(definitionItem);
|
||||||
|
SessionMessages.add(actionRequest, "success-definition-deleted");
|
||||||
|
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||||
|
|
||||||
SessionMessages.add(actionRequest, "success-definition-deleted");
|
} catch (Exception e) {
|
||||||
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
logger.error(e.getLocalizedMessage(),e);
|
||||||
|
SessionErrors.add(actionRequest, "error-delete-definition");
|
||||||
/*
|
SessionMessages.add(actionRequest,
|
||||||
* SessionErrors.add(actionRequest, "error-delete-definition");
|
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
||||||
* SessionMessages.add(actionRequest, PortalUtil.getPortletId(actionRequest) +
|
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
|
||||||
* SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
|
}
|
||||||
* actionResponse.setRenderParameter("jspPage",
|
|
||||||
* "/html/systemservicedefinition/view.jsp");
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
|
|
||||||
* ThemeDisplay themeDisplay =
|
|
||||||
* (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
|
|
||||||
*
|
|
||||||
* PortletURL redirectURL =
|
|
||||||
* PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
|
|
||||||
* portletName,themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
|
|
||||||
* redirectURL.setParameter("jspPage", "/registration.jsp");
|
|
||||||
* SessionErrors.add(actionRequest, "WRONG_FIRST_NAME_ERROR");
|
|
||||||
* actionResponse.sendRedirect(redirectURL.toString());
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void publishCreateSSDEvent(DefinitionItem definitionItem) {
|
||||||
|
logger.debug("Trying to send the event to create System Service");
|
||||||
|
CreateSSDEvent toCreate = new CreateSSDEvent(definitionItem);
|
||||||
|
toCreate.publisher.publish(toCreate);
|
||||||
|
logger.info("Done send create event " + toCreate.getName() + " for " + toCreate.getUser());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publishDeleteSSDEvent(DefinitionItem definitionItem) {
|
||||||
|
logger.debug("Trying to send the event to delete System Service");
|
||||||
|
DeleteSSDEvent toDelete = new DeleteSSDEvent(definitionItem);
|
||||||
|
toDelete.publisher.publish(toDelete);
|
||||||
|
logger.info("Done send delete event " + toDelete.getName() + " for " + toDelete.getUser());
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* private void createDefinition(ResourceRequest resourceRequest,
|
* private void createDefinition(ResourceRequest resourceRequest,
|
||||||
* ResourceResponse resourceResponse, UserCredentials userCredentials) throws
|
* ResourceResponse resourceResponse, UserCredentials userCredentials) throws
|
||||||
|
|
|
@ -16,6 +16,10 @@ public class DefinitionItem implements Serializable {
|
||||||
private String username;
|
private String username;
|
||||||
private String secret;
|
private String secret;
|
||||||
|
|
||||||
|
public DefinitionItem(String clientId) {
|
||||||
|
super();
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
public DefinitionItem(String clientId, String description, String username, String secret) {
|
public DefinitionItem(String clientId, String description, String username, String secret) {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.gcube.portlets.admin.systemservicedefinition.event;
|
package org.gcube.portlets.admin.systemservicedefinition.event;
|
||||||
|
|
||||||
|
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
||||||
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||||
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||||
|
|
||||||
|
@ -12,6 +13,14 @@ public class CreateSSDEvent extends PortalEvent {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1499288552188273747L;
|
private static final long serialVersionUID = 1499288552188273747L;
|
||||||
|
|
||||||
|
public class CreateSSDEventPublisher extends AbstractLR62EventPublisher {
|
||||||
|
public CreateSSDEventPublisher() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreateSSDEventPublisher publisher;
|
||||||
|
|
||||||
public static final String NAME = "create_system_service";
|
public static final String NAME = "create_system_service";
|
||||||
public static final String CLIENT_ID_ENTRY = "client_id";
|
public static final String CLIENT_ID_ENTRY = "client_id";
|
||||||
public static final String DESCRIPTION_ENTRY = "description";
|
public static final String DESCRIPTION_ENTRY = "description";
|
||||||
|
@ -19,6 +28,7 @@ public class CreateSSDEvent extends PortalEvent {
|
||||||
|
|
||||||
public CreateSSDEvent(DefinitionItem definitionItem) {
|
public CreateSSDEvent(DefinitionItem definitionItem) {
|
||||||
super(NAME);
|
super(NAME);
|
||||||
|
publisher = new CreateSSDEventPublisher();
|
||||||
setClientId(definitionItem.getClientId());
|
setClientId(definitionItem.getClientId());
|
||||||
setDescription(definitionItem.getDescription());
|
setDescription(definitionItem.getDescription());
|
||||||
setClientSecret(definitionItem.getSecret());
|
setClientSecret(definitionItem.getSecret());
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package org.gcube.portlets.admin.systemservicedefinition.event;
|
|
||||||
|
|
||||||
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
|
||||||
|
|
||||||
public class CreateSSDEventPublisher extends AbstractLR62EventPublisher {
|
|
||||||
public CreateSSDEventPublisher() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.gcube.portlets.admin.systemservicedefinition.event;
|
||||||
|
|
||||||
|
import org.gcube.portal.event.publisher.lr62.AbstractLR62EventPublisher;
|
||||||
|
import org.gcube.portal.event.publisher.lr62.PortalEvent;
|
||||||
|
import org.gcube.portlets.admin.systemservicedefinition.definition.DefinitionItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Giancarlo Panichi
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DeleteSSDEvent extends PortalEvent {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1499288552188273747L;
|
||||||
|
|
||||||
|
public class DeleteSSDEventPublisher extends AbstractLR62EventPublisher {
|
||||||
|
public DeleteSSDEventPublisher() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeleteSSDEventPublisher publisher;
|
||||||
|
|
||||||
|
public static final String NAME = "delete_system_service";
|
||||||
|
public static final String CLIENT_ID_ENTRY = "client_id";
|
||||||
|
|
||||||
|
public DeleteSSDEvent(DefinitionItem definitionItem) {
|
||||||
|
super(NAME);
|
||||||
|
publisher = new DeleteSSDEventPublisher();
|
||||||
|
setClientId(definitionItem.getClientId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientId(String clientId) {
|
||||||
|
set(CLIENT_ID_ENTRY, clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientId() {
|
||||||
|
return (String) get(CLIENT_ID_ENTRY);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,8 +26,7 @@ public class InformationSystemUtils {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
|
||||||
|
|
||||||
|
public static IAMService retrieveIAMService(String scope) throws Exception {
|
||||||
public static IAMService retrieveIAMService(String scope, String token) throws Exception {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.debug("Retrieve IAM Service on IS");
|
logger.debug("Retrieve IAM Service on IS");
|
||||||
|
@ -35,8 +34,10 @@ public class InformationSystemUtils {
|
||||||
if (scope == null || scope.isEmpty())
|
if (scope == null || scope.isEmpty())
|
||||||
throw new Exception("Invalid scope: " + scope);
|
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);
|
ScopeProvider.instance.set(scope);
|
||||||
// AccessTokenProvider.instance.set(token);
|
// AccessTokenProvider.instance.set(token);
|
||||||
|
@ -45,19 +46,19 @@ public class InformationSystemUtils {
|
||||||
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class);
|
||||||
query.addCondition("$resource/Profile/Category/text() eq '" + Constants.IAM_SERVICE_CATEGORY + "'")
|
query.addCondition("$resource/Profile/Category/text() eq '" + Constants.IAM_SERVICE_CATEGORY + "'")
|
||||||
.addCondition("$resource/Profile/Name/text() eq '" + Constants.IAM_SERVICE_NAME + "'");
|
.addCondition("$resource/Profile/Name/text() eq '" + Constants.IAM_SERVICE_NAME + "'");
|
||||||
|
|
||||||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
List<ServiceEndpoint> resources = client.submit(query);
|
List<ServiceEndpoint> resources = client.submit(query);
|
||||||
|
|
||||||
IAMService iamService=null;
|
IAMService iamService = null;
|
||||||
|
|
||||||
if(resources!=null&&!resources.isEmpty()) {
|
if (resources != null && !resources.isEmpty()) {
|
||||||
ServiceEndpoint iams=resources.get(0);
|
ServiceEndpoint iams = resources.get(0);
|
||||||
iamService=new IAMService(iams.profile().runtime().hostedOn());
|
iamService = new IAMService(iams.profile().runtime().hostedOn());
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("IAM Services retrieved: {}",iamService);
|
logger.debug("IAM Services retrieved: {}", iamService);
|
||||||
return iamService;
|
return iamService;
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} 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 {
|
try {
|
||||||
logger.debug("Retrieve System Services Definition on IS");
|
logger.debug("Retrieve System Services Definition on IS");
|
||||||
|
@ -75,8 +76,10 @@ public class InformationSystemUtils {
|
||||||
if (scope == null || scope.isEmpty())
|
if (scope == null || scope.isEmpty())
|
||||||
throw new Exception("Invalid scope: " + scope);
|
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);
|
ScopeProvider.instance.set(scope);
|
||||||
// AccessTokenProvider.instance.set(token);
|
// AccessTokenProvider.instance.set(token);
|
||||||
|
@ -116,8 +119,7 @@ public class InformationSystemUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void publishSSD(DefinitionItem definitionItem, String category, String scope, String token)
|
public static void publishSSD(DefinitionItem definitionItem, String category, String scope) throws Exception {
|
||||||
throws Exception {
|
|
||||||
if (definitionItem == null)
|
if (definitionItem == null)
|
||||||
throw new Exception("Invalid definition: " + definitionItem);
|
throw new Exception("Invalid definition: " + definitionItem);
|
||||||
|
|
||||||
|
@ -127,56 +129,56 @@ public class InformationSystemUtils {
|
||||||
if (scope == null || scope.isEmpty())
|
if (scope == null || scope.isEmpty())
|
||||||
throw new Exception("Invalid scope: " + scope);
|
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();
|
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);
|
* List<String> scopes = new ArrayList<String>(); scopes.add(scope);
|
||||||
* Collection<String> col = toPublish.scopes().asCollection();
|
* Collection<String> col = toPublish.scopes().asCollection();
|
||||||
* col.addAll(scopes);
|
* col.addAll(scopes);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
toPublish.newProfile();
|
toPublish.newProfile();
|
||||||
toPublish.profile().name(definitionItem.getClientId());
|
toPublish.profile().name(definitionItem.getClientId());
|
||||||
toPublish.profile().description(definitionItem.getDescription());
|
toPublish.profile().description(definitionItem.getDescription());
|
||||||
toPublish.profile().category(category);
|
toPublish.profile().category(category);
|
||||||
toPublish.profile().version("1.0.0");
|
toPublish.profile().version("1.0.0");
|
||||||
|
|
||||||
toPublish.profile().newRuntime();
|
toPublish.profile().newRuntime();
|
||||||
toPublish.profile().runtime().ghnId("");
|
toPublish.profile().runtime().ghnId("");
|
||||||
toPublish.profile().runtime().status("READY");
|
toPublish.profile().runtime().status("READY");
|
||||||
toPublish.profile().runtime().hostedOn("d4science.org");
|
toPublish.profile().runtime().hostedOn("d4science.org");
|
||||||
|
|
||||||
toPublish.profile().newPlatform();
|
toPublish.profile().newPlatform();
|
||||||
toPublish.profile().platform().name("d4science");
|
toPublish.profile().platform().name("d4science");
|
||||||
toPublish.profile().platform().version((short) 0);
|
toPublish.profile().platform().version((short) 0);
|
||||||
toPublish.profile().platform().minorVersion((short) 0);
|
toPublish.profile().platform().minorVersion((short) 0);
|
||||||
toPublish.profile().platform().revisionVersion((short) 0);
|
toPublish.profile().platform().revisionVersion((short) 0);
|
||||||
toPublish.profile().platform().buildVersion((short) 0);
|
toPublish.profile().platform().buildVersion((short) 0);
|
||||||
|
|
||||||
|
|
||||||
AccessPoint accessPoint = new AccessPoint();
|
AccessPoint accessPoint = new AccessPoint();
|
||||||
|
|
||||||
// String encryptedPassword =
|
String encryptedPassword = StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
||||||
// StringEncrypter.getEncrypter().encrypt(definitionItem.getSecret());
|
|
||||||
accessPoint.name(definitionItem.getClientId());
|
accessPoint.name(definitionItem.getClientId());
|
||||||
accessPoint.description("Keycloak client credentials");
|
accessPoint.description("Keycloak client credentials");
|
||||||
accessPoint.address(iamService.getAddress());
|
accessPoint.address(iamService.getAddress());
|
||||||
accessPoint.credentials(definitionItem.getSecret(), definitionItem.getUsername());
|
accessPoint.credentials(encryptedPassword, definitionItem.getUsername());
|
||||||
toPublish.profile().accessPoints().add(accessPoint);
|
toPublish.profile().accessPoints().add(accessPoint);
|
||||||
|
|
||||||
logger.debug("Request publish: {}", toPublish);
|
logger.debug("Request publish: {}", toPublish);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// AccessTokenProvider.instance.set(token);
|
// AccessTokenProvider.instance.set(token);
|
||||||
//SecurityTokenProvider.instance.set(token);
|
// SecurityTokenProvider.instance.set(token);
|
||||||
ScopeProvider.instance.set(scope);
|
ScopeProvider.instance.set(scope);
|
||||||
|
|
||||||
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
RegistryPublisher publisher = RegistryPublisherFactory.create();
|
||||||
|
|
||||||
String id = publisher.create(toPublish).id();
|
String id = publisher.create(toPublish).id();
|
||||||
|
@ -191,6 +193,49 @@ public class InformationSystemUtils {
|
||||||
logger.debug("Published on IS");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class Constants {
|
||||||
public static final String DEFAULT_SCOPE = "/gcube";
|
public static final String DEFAULT_SCOPE = "/gcube";
|
||||||
public static final String DEFAULT_TOKEN = "";
|
public static final String DEFAULT_TOKEN = "";
|
||||||
|
|
||||||
|
|
||||||
public static final String DEFAULT_ROLE = "OrganizationMember";
|
public static final String DEFAULT_ROLE = "OrganizationMember";
|
||||||
|
|
||||||
// Session
|
// Session
|
||||||
|
|
|
@ -24,8 +24,7 @@ public class ISTest {
|
||||||
public void findSSD() {
|
public void findSSD() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE,
|
InformationSystemUtils.retrieveSSD(Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE);
|
||||||
Constants.DEFAULT_TOKEN);
|
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -34,15 +33,15 @@ public class ISTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Ignore
|
||||||
public void publishSSD() {
|
public void publishSSD() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DefinitionItem definitionItem=new DefinitionItem("sample-client-name", "sample-client-description",
|
DefinitionItem definitionItem = new DefinitionItem("sample-client-name", "sample-client-description",
|
||||||
"sample-client-description", "xxxxx-xxxx-xxx-xxxx");
|
"sample-client-description", "xxxxx-xxxx-xxx-xxxx");
|
||||||
InformationSystemUtils.publishSSD(definitionItem,Constants.SYSTEM_SERVICE_CATEGORY, Constants.DEFAULT_SCOPE,
|
InformationSystemUtils.publishSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||||
Constants.DEFAULT_TOKEN);
|
Constants.DEFAULT_SCOPE);
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -52,4 +51,23 @@ public class ISTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
public void deleteSSD() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
DefinitionItem definitionItem = new DefinitionItem("sample-client-name", "sample-client-description",
|
||||||
|
"sample-client-description", "xxxxx-xxxx-xxx-xxxx");
|
||||||
|
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
|
||||||
|
Constants.DEFAULT_SCOPE);
|
||||||
|
assertTrue(true);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getLocalizedMessage(), e);
|
||||||
|
assertTrue("Error deleting the resource!", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,3 +7,4 @@
|
||||||
/howto.txt
|
/howto.txt
|
||||||
/log4j.properties
|
/log4j.properties
|
||||||
/symm.key
|
/symm.key
|
||||||
|
/.~lock.symm.key#
|
||||||
|
|
Loading…
Reference in New Issue