Commit 943aea91 authored by Francesco Chicchiricco's avatar Francesco Chicchiricco
Browse files

[CRV-19] Now also saving the SF endpoint on choreography create

parent 4886de18
......@@ -106,6 +106,35 @@ limitations under the License.
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sftrafficinformation</name>
<role>SF Traffic Information</role>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_TrafficInformation.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
<url>http://192.168.150.142/sftrafficinformation</url>
<deploymentInfo>
<endpoint>http://192.168.150.130:8080/sftrafficinformation</endpoint>
<node>
<cpus>2</cpus>
<hostname>chornode1</hostname>
<image>af036b89-0ef4-48e9-99ac-51b0cf9c314e</image>
<ip>192.168.150.130</ip>
<os>Ubuntu</os>
<privateKeyFile>/etc/enactment-engine/eekey.pem</privateKeyFile>
<ram>1024</ram>
<state>1</state>
<storage>10000</storage>
<user>ubuntu</user>
<zone>RegionOne</zone>
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>cdtripplanner</name>
<role>Trip Planner</role>
......@@ -114,7 +143,7 @@ limitations under the License.
<serviceSpecRole>Consumer Trip Planner</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecName>sftrafficinformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<dependency>
......@@ -159,6 +188,35 @@ limitations under the License.
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sfpoi</name>
<role>SF Poi</role>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_Poi.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
<url>http://192.168.150.142/sfpoi</url>
<deploymentInfo>
<endpoint>http://192.168.150.130:8080/sfpoi</endpoint>
<node>
<cpus>2</cpus>
<hostname>chornode1</hostname>
<image>af036b89-0ef4-48e9-99ac-51b0cf9c314e</image>
<ip>192.168.150.130</ip>
<os>Ubuntu</os>
<privateKeyFile>/etc/enactment-engine/eekey.pem</privateKeyFile>
<ram>1024</ram>
<state>1</state>
<storage>10000</storage>
<user>ubuntu</user>
<zone>RegionOne</zone>
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>cdtouristagent</name>
<role>Tourist Agent</role>
......@@ -167,7 +225,7 @@ limitations under the License.
<serviceSpecRole>Consumer Tourist Agent</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecName>sfpoi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<dependency>
......
......@@ -18,6 +18,7 @@ package org.apache.syncope.core.logic;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import eu.chorevolution.chors.ChorSpecUtils;
import eu.chorevolution.datamodel.Choreography;
import eu.chorevolution.datamodel.ExistingService;
import eu.chorevolution.datamodel.ServiceGroup;
......@@ -44,6 +45,7 @@ import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.syncope.common.lib.AbstractBaseBean;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.patch.AnyObjectPatch;
import org.apache.syncope.common.lib.patch.AttrPatch;
import org.apache.syncope.common.lib.patch.GroupPatch;
import org.apache.syncope.common.lib.patch.MembershipPatch;
import org.apache.syncope.common.lib.to.AnyObjectTO;
......@@ -240,19 +242,20 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
operation, id, name, message);
byte[] chorSpecXML = null;
Choreography chorSpec = null;
Choreography parsed = null;
if (enactedChorSpec != null) {
try {
chorSpecXML = IOUtils.readBytesFromStream(enactedChorSpec);
chorSpec = Choreography.fromXML(new ByteArrayInputStream(chorSpecXML));
parsed = Choreography.fromXML(new ByteArrayInputStream(chorSpecXML));
} catch (Exception e) {
throw new BadRequestException("While reading enacted chorSpec for choreography " + id, e);
}
}
if (chorSpec == null) {
if (parsed == null) {
throw new BadRequestException("Cloud not parse enacted chorSpec for choreography " + id);
}
final Choreography chorSpec = parsed;
switch (operation) {
case CREATE:
// 1. create the choreography group
......@@ -265,11 +268,16 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
choreography.getPlainAttrs().add(
new AttrTO.Builder().schema("chorSpec").value(Base64Utility.encode(chorSpecXML)).build());
TypeExtensionTO serviceTE = new TypeExtensionTO();
serviceTE.setAnyType(SERVICE_TYPE);
serviceTE.getAuxClasses().add("Deployed");
choreography.getTypeExtensions().add(serviceTE);
choreography = groupLogic.create(choreography, false).getEntity();
final String key = choreography.getKey();
AnyTypeClassTO anyTypeClassTO = new AnyTypeClassTO();
anyTypeClassTO.setKey(name + " Type Extension");
AnyTypeClassTO classForUserTE = new AnyTypeClassTO();
classForUserTE.setKey(name + " USER Type Extension");
for (ServiceGroup serviceGroup : chorSpec.getServiceGroups()) {
serviceGroup.getServices().stream().
......@@ -284,8 +292,18 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
// and save the security filter URL
AnyObjectPatch servicePatch = new AnyObjectPatch();
servicePatch.setKey(serviceTO.getKey());
servicePatch.getMemberships().add(
new MembershipPatch.Builder().group(key).build());
MembershipPatch membershipPatch = new MembershipPatch.Builder().group(key).build();
String securityFilterURL = ChorSpecUtils.findSecurityFilterURL(chorSpec, service);
if (securityFilterURL != null) {
membershipPatch.getPlainAttrs().add(new AttrPatch.Builder().
attrTO(new AttrTO.Builder().
schema("Endpoint").value(securityFilterURL).build()).
build());
}
servicePatch.getMemberships().add(membershipPatch);
anyObjectLogic.update(servicePatch, false);
// 3. for each service requiring per-user authentication, create the
......@@ -299,7 +317,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
username.setType(AttrSchemaType.String);
username.setMandatoryCondition("true");
schemaLogic.create(SchemaType.PLAIN, username);
anyTypeClassTO.getPlainSchemas().add(username.getKey());
classForUserTE.getPlainSchemas().add(username.getKey());
PlainSchemaTO password = new PlainSchemaTO();
password.setKey(service.getName() + " Password");
......@@ -308,7 +326,7 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
password.setSecretKey(SECRET_KEY);
password.setMandatoryCondition("true");
schemaLogic.create(SchemaType.PLAIN, password);
anyTypeClassTO.getPlainSchemas().add(password.getKey());
classForUserTE.getPlainSchemas().add(password.getKey());
}
} catch (NotFoundException e) {
LOG.error("Could not find service {} in the inventory, ignoring", service.getName(), e);
......@@ -316,16 +334,17 @@ public class ChoreographyLogic extends AbstractLogic<AbstractBaseBean> {
});
}
if (!anyTypeClassTO.getPlainSchemas().isEmpty()) {
anyTypeClassLogic.create(anyTypeClassTO);
if (!classForUserTE.getPlainSchemas().isEmpty()) {
anyTypeClassLogic.create(classForUserTE);
TypeExtensionTO typeExtension = new TypeExtensionTO();
typeExtension.setAnyType(AnyTypeKind.USER.name());
typeExtension.getAuxClasses().add(anyTypeClassTO.getKey());
TypeExtensionTO userTE = new TypeExtensionTO();
userTE.setAnyType(AnyTypeKind.USER.name());
userTE.getAuxClasses().add(classForUserTE.getKey());
GroupPatch groupPatch = new GroupPatch();
groupPatch.setKey(key);
groupPatch.getTypeExtensions().add(typeExtension);
groupPatch.getTypeExtensions().addAll(choreography.getTypeExtensions());
groupPatch.getTypeExtensions().add(userTE);
groupLogic.update(groupPatch, false);
}
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment