summaryrefslogtreecommitdiffstats
path: root/policy-listener
diff options
context:
space:
mode:
authorpikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
committer pikusa <pikusa@man.poznan.pl>2013-04-03 13:18:17 (GMT)
commit2f2a3a129c91de540e66c3bfbe30b0df1942cd4b (patch)
tree2d313cdf0068af368d4de6067d676be16f6a6464 /policy-listener
parentff8aa232b071a9b54dff833714a870fd0aec0b30 (diff)
downloadnovi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.zip
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.gz
novi-public-2f2a3a129c91de540e66c3bfbe30b0df1942cd4b.tar.bz2
project commit and dir tree change
Diffstat (limited to 'policy-listener')
-rw-r--r--policy-listener/pom.xml107
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/authentication/Basic.java102
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForAPI.java39
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForMonitoring.java38
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForRIS.java53
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/interfaces/PolicyManagerIF.java41
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/monitoringInteractions/MonitoringEvents.java90
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/ponder2comms/TelnetClient.java174
-rw-r--r--policy-listener/src/main/java/eu/novi/policylistener/synchWithRIS/AuthorizationSearch.java611
-rw-r--r--policy-listener/src/main/resources/OSGI-INF/blueprint/config.xml46
-rw-r--r--policy-listener/src/main/test/eu/novi/SynchWithRIS/AuthorizationSearchTest.java25
-rw-r--r--policy-listener/src/main/test/eu/novi/policy/impl/PolicyManagerImplTest.java16
-rw-r--r--policy-listener/src/test/java/eu/novi/policylistener/SynchWithRIS/AuthorizationSearchTest.java355
-rw-r--r--policy-listener/src/test/java/eu/novi/policylistener/authentication/BasicTest.java133
-rw-r--r--policy-listener/src/test/java/eu/novi/policylistener/ponder2comms/TelnetClientTest.java124
15 files changed, 1954 insertions, 0 deletions
diff --git a/policy-listener/pom.xml b/policy-listener/pom.xml
new file mode 100644
index 0000000..57edfe6
--- /dev/null
+++ b/policy-listener/pom.xml
@@ -0,0 +1,107 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>eu.novi</groupId>
+ <artifactId>parent</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>../parent/</relativePath>
+ </parent>
+ <packaging>bundle</packaging>
+ <artifactId>policy-listener</artifactId>
+ <name>Policy manager service for listening and answering to requests</name>
+
+ <developers>
+ <developer>
+ <id>blazej.pietrzak</id>
+ <name>Blazej Pietrzak</name>
+ <email>blazej.pietrzak@man.poznan.pl</email>
+ <organization>PSNC</organization>
+ <organizationUrl>http://www.man.poznan.pl/</organizationUrl>
+ <roles>
+ <role>architect</role>
+ <role>developer</role>
+ </roles>
+ <timezone>+1</timezone>
+ </developer>
+ </developers>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId};
+ blueprint.graceperiod:=true;
+ blueprint.timeout:= 480000
+ </Bundle-SymbolicName>
+ <Export-Package>
+ eu.novi.policylistener.interfaces,
+ eu.novi.policylistener.synchWithRIS,
+ eu.novi.policylistener.ponder2comms,
+ eu.novi.policylistener.authentication,
+ eu.novi.policylistener.monitoringInteractions,
+ eu.novi.policylistener.sliceExpiration,
+ eu.novi.policylistener.platformSpecific
+ </Export-Package>
+ <Private-Package></Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+<!-- <dependency>
+ <groupId>com.twicom</groupId>
+ <artifactId>qdparser</artifactId>
+ <version>1.1.0</version>
+ <scope>system</scope>
+ <systemPath>${basedir}/lib/qdparser.jar</systemPath>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>ponder2</artifactId>
+ <version>${project.version}</version>
+ </dependency> -->
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>feedback</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>communications</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>authentication</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>information-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>xmlrpc-client-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>eu.novi</groupId>
+ <artifactId>mail-osgi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ <optional>false</optional>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/authentication/Basic.java b/policy-listener/src/main/java/eu/novi/policylistener/authentication/Basic.java
new file mode 100644
index 0000000..88e4fb7
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/authentication/Basic.java
@@ -0,0 +1,102 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.authentication;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import eu.novi.feedback.event.ReportEvent;
+import eu.novi.im.policy.impl.NOVIUserImpl;
+import eu.novi.policylistener.interfaces.InterfaceForAPI;
+import eu.novi.authentication.InterfaceForPS;
+import eu.novi.policylistener.synchWithRIS.AuthorizationSearch;
+
+public class Basic implements InterfaceForAPI {
+ private static final transient Logger log =
+ LoggerFactory.getLogger(Basic.class);
+ private String testbed;
+ private static InterfaceForPS authenticationComp;
+ public String getTestbed() {
+ return testbed;
+ }
+ public void setTestbed(String testbed) {
+ this.testbed = testbed;
+ }
+ public static InterfaceForPS getauthenticationComp() {
+ return authenticationComp;
+ }
+ public static void setauthenticationComp(InterfaceForPS authc) {
+ Basic.authenticationComp = authc;
+ }
+
+ static ReportEvent userFeedback=null;
+
+ public NOVIUserImpl getAuth(String username, String password) throws Exception {
+ NOVIUserImpl theUser=null;
+ if (authenticationComp!=null)
+ {
+ theUser= authenticationComp.getAuth(username,password);
+ log.info("The User "+username + "returned the NOVIUser object with the session key "+ theUser.getHasSessionKey());
+ System.out.println("Finished.");
+ }
+ else {log.info("The authentication Component is null");}
+ return theUser;
+ }
+
+ /**
+ * @return the userFeedback
+ */
+ public ReportEvent getUserFeedback() {
+ return userFeedback;
+ }
+
+
+ /**
+ * @param userFeedback the userFeedback to set
+ */
+ public void setUserFeedback(ReportEvent userFeedback) {
+ this.userFeedback = userFeedback;
+ }
+
+ @Override
+ public int addPolicyFromFile(String fileURI) {
+ AuthorizationSearch au=new AuthorizationSearch();
+ return au.AddPolicyFile(null, fileURI);
+ }
+
+ public String mCallToPonder2(String thecall)
+ {
+ AuthorizationSearch au=new AuthorizationSearch();
+ return au.ManualCallToPonder(null, thecall);
+ }
+
+
+}
+
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForAPI.java b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForAPI.java
new file mode 100644
index 0000000..edd3bdf
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForAPI.java
@@ -0,0 +1,39 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.interfaces;
+
+import eu.novi.im.policy.impl.NOVIUserImpl;
+
+public interface InterfaceForAPI {
+ public NOVIUserImpl getAuth(String username, String password) throws Exception;
+ public int addPolicyFromFile(String fileURI);
+
+}
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForMonitoring.java b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForMonitoring.java
new file mode 100644
index 0000000..7457705
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForMonitoring.java
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.interfaces;
+
+import eu.novi.im.core.Topology;
+
+public interface InterfaceForMonitoring {
+ public int ResourceFailure(String topo,String vnodeID);
+
+}
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForRIS.java b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForRIS.java
new file mode 100644
index 0000000..9cb7bee
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/InterfaceForRIS.java
@@ -0,0 +1,53 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.interfaces;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.Set;
+
+import eu.novi.im.core.Group;
+import eu.novi.im.core.Reservation;
+import eu.novi.im.core.Topology;
+import eu.novi.im.policy.impl.NOVIUserImpl;
+
+public interface InterfaceForRIS {
+
+ public String AuthorizedForResourced(String sessionID, String s1, String s2);
+ public Map<String, Boolean> AuthorizedForResource(String sessionID, NOVIUserImpl User, Set<String> Resources,Integer NumberOfRequestedResources);
+ public int AddTopology(String sessionID, Group topo, String topoID);
+ public int RemoveTopology(String sessionID, Topology topo, String topoID);
+ public Boolean AuthorizedForDeletion(String sessionID, NOVIUserImpl caller, Set<NOVIUserImpl> owners);
+ public int AddAllTopologies(String sessionID, Set<Reservation> slices);
+ public int InformExpirationTime(NOVIUserImpl user, String topoID,Date date);
+ public int InformExpirationHappened(NOVIUserImpl user, String topoID, Date date);
+ public int UpdateExpirationTime(NOVIUserImpl user, String topoID, Date date);
+}
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/interfaces/PolicyManagerIF.java b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/PolicyManagerIF.java
new file mode 100644
index 0000000..486a671
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/interfaces/PolicyManagerIF.java
@@ -0,0 +1,41 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.interfaces;
+
+/**
+ * Policy manager service.
+ *
+ * @author <a href="mailto:blazej.pietrzak@man.poznan.pl">Blazej Pietrzak</a>
+ *
+ */
+public interface PolicyManagerIF {
+
+}
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/monitoringInteractions/MonitoringEvents.java b/policy-listener/src/main/java/eu/novi/policylistener/monitoringInteractions/MonitoringEvents.java
new file mode 100644
index 0000000..83a691d
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/monitoringInteractions/MonitoringEvents.java
@@ -0,0 +1,90 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.monitoringInteractions;
+
+import java.util.Iterator;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.feedback.event.ReportEvent;
+import eu.novi.im.core.Resource;
+import eu.novi.im.core.Topology;
+import eu.novi.im.core.VirtualNode;
+import eu.novi.im.core.impl.VirtualNodeImpl;
+import eu.novi.policylistener.interfaces.InterfaceForMonitoring;
+import eu.novi.policylistener.ponder2comms.TelnetClient;
+import eu.novi.policylistener.synchWithRIS.AuthorizationSearch;
+
+public class MonitoringEvents implements InterfaceForMonitoring{
+ String toforward;
+ private static final transient Logger log = LoggerFactory.getLogger(MonitoringEvents.class);
+ TelnetClient telclient= new TelnetClient();
+ // Will be initialized from blue print
+ ReportEvent userFeedback=null;
+
+ public void setTelnetClient(TelnetClient tel)
+ {
+ telclient=tel;
+ }
+
+
+ public int ResourceFailure(String topo,String vnodeID) {
+
+ String result="";
+ String vnodefailure="root/event/virtualnodefailure create: #(\""+vnodeID+"\").\r\n";
+ System.out.println(vnodefailure);
+ if(userFeedback != null)
+ userFeedback.instantInfo(userFeedback.getCurrentSessionID(), "Policy Manager AA", "Monitoring Event received :"+vnodefailure, " .");
+ result = telclient.TelnetPonder2(vnodefailure);
+ System.out.println(result);
+ return 0;
+ }
+
+ /**
+ * @return the userFeedback
+ */
+ public ReportEvent getUserFeedback() {
+ return userFeedback;
+ }
+
+
+ /**
+ * @param userFeedback the userFeedback to set
+ */
+ public void setUserFeedback(ReportEvent userFeedback) {
+ this.userFeedback = userFeedback;
+ }
+
+
+
+}
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/ponder2comms/TelnetClient.java b/policy-listener/src/main/java/eu/novi/policylistener/ponder2comms/TelnetClient.java
new file mode 100644
index 0000000..c711d13
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/ponder2comms/TelnetClient.java
@@ -0,0 +1,174 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.ponder2comms;
+
+import java.net.*;
+import java.io.*;
+
+
+public class TelnetClient
+{
+ Socket soc;
+ DataInputStream din;
+ DataOutputStream dout;
+
+ //@SuppressWarnings("deprecation")
+ public String TelnetPonder2(String arg)
+ {
+ init();
+ String resultb="true";
+ try {
+ System.out.println("< Telnet Prompt > "+ din.readLine()+" "+ din.readLine());
+ dout.flush();
+ dout.writeBytes(arg);
+ String result = din.readLine();
+ if (result.equals("/ $ false"))
+ resultb = "false";
+ else
+ if (result.equals("/ $ true"))
+ resultb = "true";
+ else
+ resultb = result;
+ soc.close(); //close port
+ din.close(); //close input stream
+ dout.close(); //close output stream
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // System.out.println(din.readLine());
+ //System.out.println(din.readLine());
+
+ return resultb;
+
+ }
+
+ public String TelnetPonder1(String arg)
+ {
+ init();
+ String resultb1="true";
+ try {
+ System.out.println("< Telnet Prompt > "+ din.readLine()+" "+ din.readLine());
+ dout.flush();
+ dout.writeBytes(arg);
+ soc.close(); //close port
+ din.close(); //close input stream
+ dout.close(); //close output stream
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return resultb1;
+
+ }
+
+ public String TelnetPonder3(String arg)
+ {
+ init();
+ String res="";
+ String text;
+ try {
+ System.out.println("< Telnet Prompt > "+ din.readLine()+" "+ din.readLine());
+ dout.flush();
+ dout.writeBytes(arg);
+ // while (din.readLine()!=null)
+ //{ res+=din.readLine();
+ //}
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ int available=din.available();
+ System.out.println(din.available());
+ while (din.available()>0)
+ {
+ int inp= din.read();
+ //System.out.println(inp);
+ // System.out.print(Character.valueOf((char) inp));
+ res+=Character.valueOf((char) inp);
+ //System.out.println(din.available());
+
+ }
+ /*while (din.available()>4)
+ {
+ text=din.readLine();
+ res+=text+"\n";
+ available-=text.length();
+ System.out.println(available);
+ System.out.println("System says: "+din.available());
+ }*/
+ soc.close(); //close port
+ din.close(); //close input stream
+ dout.close(); //close output stream
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ // System.out.println(res);
+ return res;
+
+ }
+
+ public void init()
+ {
+ try {
+ //Create object of Socket "150.254.160.28"
+ soc = new Socket("localhost",13570);
+ //Create object of Input Stream to read from socket
+ din = new DataInputStream(soc.getInputStream());
+ //Create object of Output Stream to write on socket
+ dout=new DataOutputStream(soc.getOutputStream());
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+/* public void setSocket(Socket socc)
+ {
+ soc=socc;
+ }
+ public void setDataInputStream(DataInputStream mockDin)
+ {
+ din=mockDin;
+ }
+ public void setDataOutputStream(DataOutputStream doutt)
+ {
+ dout=doutt;
+ }*/
+
+} \ No newline at end of file
diff --git a/policy-listener/src/main/java/eu/novi/policylistener/synchWithRIS/AuthorizationSearch.java b/policy-listener/src/main/java/eu/novi/policylistener/synchWithRIS/AuthorizationSearch.java
new file mode 100644
index 0000000..ea304e0
--- /dev/null
+++ b/policy-listener/src/main/java/eu/novi/policylistener/synchWithRIS/AuthorizationSearch.java
@@ -0,0 +1,611 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.synchWithRIS;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+
+import org.apache.commons.httpclient.HttpException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.authentication.InterfaceForPS;
+import eu.novi.connection.RESTCommunication;
+import eu.novi.feedback.event.ReportEvent;
+import eu.novi.im.core.Group;
+import eu.novi.im.core.Node;
+import eu.novi.im.core.Reservation;
+import eu.novi.im.core.Resource;
+import eu.novi.im.core.Topology;
+import eu.novi.im.core.VirtualNode;
+import eu.novi.im.core.impl.TopologyImpl;
+import eu.novi.im.policy.impl.NOVIUserImpl;
+import eu.novi.mail.mailclient.SSendEmail;
+import eu.novi.policylistener.authentication.Basic;
+import eu.novi.policylistener.interfaces.InterfaceForRIS;
+import eu.novi.policylistener.ponder2comms.TelnetClient;
+
+public class AuthorizationSearch implements InterfaceForRIS {
+ String toforward;
+ private static final transient Logger log =
+ LoggerFactory.getLogger(AuthorizationSearch.class);
+ TelnetClient telclient= new TelnetClient();
+ // Will be initialized from blue print
+ ReportEvent userFeedback=null;
+ private String testbed;
+
+ private static InterfaceForPS authenticationComp;
+ public static InterfaceForPS getauthenticationComp() {
+ return authenticationComp;
+ }
+ public static void setauthenticationComp(InterfaceForPS authc) {
+ AuthorizationSearch.authenticationComp = authc;
+ }
+
+
+ public String getTestbed() {
+ return testbed;
+ }
+
+ public void setTestbed(String testbed) {
+ this.testbed = testbed;
+ }
+
+ public void setTelnetClient(TelnetClient tel)
+ {
+ telclient=tel;
+ }
+
+ public void sentEmailWithREST(String receiver, String information){
+ //String address="";
+ //String failureEvent="Text for the User";
+ try {
+ HashMap<String, String> requestParameters = new HashMap<String, String>();
+ requestParameters.put("receiver", receiver);
+ requestParameters.put("information", information);
+ new RESTCommunication().executePostMethod("http://localhost:8080/forthemail/TempHandler/sentEmailEvent",requestParameters);
+ } catch (HttpException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String AuthorizedForResourced(String sessionID, String string1, String string2) {
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "Authorized for request from RIS", "http://www.fp7-novi.eu");
+ }
+ // TODO Auto-generated method stub
+ String result = "AUTH";
+ return result;
+ }
+
+ public int AddPolicyFile(String sessionID, String policyfile) {
+
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID,"Policy Manager AA", "Adding a new policy file (.p2) in the PolicyEngine", "http://www.fp7-novi.eu");
+ }
+
+ String tof="read "+ policyfile+"\r\n";
+ //String tof="roleassigned create:#(\"a\" \"b\" \"c\").\r\n";
+ log.info(tof);
+ String re= telclient.TelnetPonder1(tof);
+ return 0;
+ }
+
+ public String ManualCallToPonder(String sessionID, String thecall){
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID,"Policy Manager AA", "Making a manual call to the PolicyEngine:" + thecall, "http://www.fp7-novi.eu");
+ }
+ System.out.println("The call is:"+thecall);
+ String fcall=thecall+"\r\n";
+ String got= telclient.TelnetPonder3(fcall);
+ log.info(got);
+ return got;
+
+ }
+
+ @Override
+ public Map<String, Boolean> AuthorizedForResource(String sessionID, NOVIUserImpl noviUser, Set<String> Resources, Integer NumberOfRequestedResources) {
+ //String User="User1";
+ String UserRole="PlanetLabUser";
+ //String UserRole="";
+ String theRealUser=noviUser.toString();
+ log.info("The NOVI User is: "+theRealUser);
+ if (noviUser.getHasNoviRole() != null)
+ {
+ String UserRolecomplet=noviUser.getHasNoviRole().toString();
+ log.info("WE GOT the NOVIRolecomlet: "+UserRolecomplet);
+ UserRole= UserRolecomplet.substring(41);
+ log.info("WE GOT the NOVIRole: "+UserRole);
+ }
+ //log.info("User has NOVIRole: "+noviUser.getHasNoviRole().toString());
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID,"Policy Manager AA", "Check Authorized Resources for user "+theRealUser+". It has NOVI Role "+ UserRole +". Request is for "+NumberOfRequestedResources+" Resources.", "http://www.fp7-novi.eu");
+ }
+ log.info("I got testbed "+testbed);
+ if (testbed== null)
+ {
+ log.info("Testbed is null!!!");
+ // log.info("I will put PlanetLab");
+ // testbed="fake..PlanetLab";
+ }
+// if(testbed.contains("PlanetLab"))
+// {
+// forquota="root/PlanetLab getquota.\r\n";
+// }
+// if(testbed.contains("FEDERICA"))
+// {
+// forquota="root/Federica getquota.\r\n";
+// }
+ String forquota="root/"+testbed+" getquota.\r\n";
+ log.info(forquota);
+ String quota= telclient.TelnetPonder2(forquota);
+ log.info("The quota is:"+ quota);
+ log.info("The request was for " + NumberOfRequestedResources+ " and based on the agreement and the mission policies we can get up to : " + quota);
+
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "Mission Policies: The request was for "+NumberOfRequestedResources+" and the quota is " + quota , "http://www.fp7-novi.eu");
+ }
+
+ Map<String, Boolean> authRes=new HashMap<String, Boolean>();
+ Iterator it= Resources.iterator();
+ while (it.hasNext())
+ {
+ //authRes.put(Resources.iterator().toString(), true);
+ boolean result=true;
+ String current=(String) it.next();
+ String toforward="root/Rolesdomain/"+UserRole +" search: (root/Resources at: \""+current+"\").\r\n";
+ log.info(toforward);
+ String resultb= telclient.TelnetPonder2(toforward);
+ log.info(resultb);
+ if (resultb.equals("false"))
+ result=false;
+ if (resultb.equals("true"))
+ result=true;
+ System.out.println(result);
+ authRes.put(current,result);
+
+ }
+ log.info("Print the Resources and their status:");
+ //Map<Integer, Integer> map = new HashMap<Integer, Integer>();
+ String statusonAuth="";
+ for (Map.Entry<String, Boolean> entry : authRes.entrySet()) {
+ System.out.println("Resource = " + entry.getKey() + ", authorized = " + entry.getValue());
+ log.info("Resource = " + entry.getKey() + ", authorized = " + entry.getValue());
+ statusonAuth+="Resource = " + entry.getKey() + ", authorized = " + entry.getValue();
+ }
+
+
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "Authorized Resources " + statusonAuth , "http://www.fp7-novi.eu");
+ }
+
+ return authRes;
+
+ }
+
+
+ /**
+ * @return the userFeedback
+ */
+ public ReportEvent getUserFeedback() {
+ return userFeedback;
+ }
+
+
+ /**
+ * @param userFeedback the userFeedback to set
+ */
+ public void setUserFeedback(ReportEvent userFeedback) {
+ this.userFeedback = userFeedback;
+ }
+
+
+ @Override
+ public int AddTopology(String sessionID, Group topo,String topoID) {
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "Adding the new topology in Policy Service (ponder2) ", "http://www.fp7-novi.eu");
+ }
+
+ String result="";
+ String result2="";
+ if (topo.getContains() ==null)
+ {
+ String message = "The topology is empty";
+ log.warn(message);
+ if(userFeedback != null){
+ if(sessionID == null)
+ sessionID = userFeedback.getCurrentSessionID();
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "We tryied to add an empty Topology in Policy Service (ponder2) ", "http://www.fp7-novi.eu");
+ }
+
+ log.info(message);
+ return -2;
+ }
+ log.info("Not empty topology");
+ Set<Resource> kati=topo.getContains();
+ Iterator it= kati.iterator();
+ System.out.println(topo.getContains().size());
+ //System.out.println(it.toString());
+ String createtopo="root/event/createTopology create: #(\""+topoID+"\").\r\n";
+ System.out.println(createtopo);
+ log.info(createtopo);
+ String createtopo2="root/event/createRemoteTopology create: #(\""+topoID+"\").\r\n";
+ System.out.println(createtopo2);
+ log.info(createtopo2);
+ result = telclient.TelnetPonder2(createtopo);
+ System.out.println(result);
+ log.info(result);
+ result2 = telclient.TelnetPonder2(createtopo2);
+ System.out.println(result2);
+ log.info(result2);
+ while(it.hasNext())
+ {
+ System.out.println("OK");
+ Resource current=(Resource) it.next();
+ System.out.println(current);
+ log.info(current.toString());
+ System.out.println(current.toString());
+ if (current instanceof VirtualNode)
+ {
+ //TODO Lets call both platforms for Everything!!! will do it only in the proper platform soon
+ //if (belong to PlanetLab)
+ if (true)
+ {
+ //We have a VNode and so we have to see if it is local or remote
+ //((VirtualNode) current).getImplementedBy();
+ System.out.println("Printing the PhysicalNode: "+((VirtualNode) current).getImplementedBy());
+ Iterator iter=((VirtualNode) current).getImplementedBy().iterator();
+ while (iter.hasNext())
+ {
+ Node currentNode=(Node) iter.next();
+ String cNode=currentNode.toString();
+ System.out.println(cNode);
+ System.out.println("The Physical Node contains the word federica? (true/false)"+cNode.contains("federica"));
+ if (cNode.contains("federica"))
+ {
+ toforward="root/event/createRemoteVNode create: #(\""+topoID+current+"\" \""+ topoID+"\").\r\n";
+ log.info("We have a remote VNode");
+ }
+ else
+ {
+ toforward="root/event/createVNode create: #(\""+topoID+current+"\" \""+ topoID+"\").\r\n";
+ log.info("We have a local VNode");
+ }
+ System.out.println(toforward);
+ log.info(toforward);
+
+ }
+ }
+
+ //root/event/createVNode create: #("http://fp7-novi.eu/im.owl#planetlab2-novi.lab.netmode.ece.ntua.gr" "midtermWorkshopSlice").
+ }
+ //if (current instanceof VirtualLink)
+ //{
+ // String toforward="root/event/createVLink create: #(\""+current+"\" \""+ topoID+"\").\r\n";
+ // System.out.println(toforward);
+ //}
+ else {
+ System.out.println("No Vnode");
+ toforward=".\r\n";
+ }
+ result= telclient.TelnetPonder2(toforward);
+ System.out.println(result);
+ log.info(result);
+ System.out.println(result);
+ log.info("Policy Service is informed about the new Slice");
+
+
+ }
+ if(userFeedback != null)
+ userFeedback.instantInfo(sessionID, "Policy Manager AA", "Finished addition of the new topology in Policy Service (ponder2) ", "http://www.fp7-novi.eu");
+
+ return 0;
+ }
+
+ @Override
+ public int RemoveTopology(String sessionID, Topology topo,String topoID) {
+ String result="";
+ /*if (topo.getContains().size() == 0)
+ {
+ String message = "The topology is empty";
+ log.warn(message);
+ return -2;
+ }*/
+ Set<Resource> kati=topo.getContains();
+ Iterator it= kati.iterator();
+ System.out.println(topo.getContains().size());
+ //System.out.println(it.toString());
+ String removetopo="root/event/removeTopology create: #(\""+topoID+"\").\r\n";
+ System.out.println(removetopo);
+ result = telclient.TelnetPonder2(removetopo);
+ System.out.println(result);
+ while(it.hasNext())
+ {
+ System.out.println("OK");
+ Resource current=(Resource) it.next();
+ System.out.println(current);
+ System.out.println(current.toString());
+ if (current instanceof VirtualNode)
+ {
+ toforward="root/event/removeVNode create: #(\""+topoID+current+"\" \""+ topoID+"\").\r\n";
+ System.out.println(toforward);
+ //root/event/createVNode create: #("http://fp7-novi.eu/im.owl#planetlab2-novi.lab.netmode.ece.ntua.gr" "midtermWorkshopSlice").
+ }
+ //if (current instanceof VirtualLink)
+ //{
+ // String toforward="root/event/createVLink create: #(\""+current+"\" \""+ topoID+"\").\r\n";
+ // System.out.println(toforward);
+ //}
+ else {
+ System.out.println("No Vnode");
+ toforward=".\r\n";
+ }
+ result= telclient.TelnetPonder2(toforward);
+ System.out.println(result);
+ System.out.println(result);
+
+
+ }
+ return 0;
+ }
+
+ @Override
+ public Boolean AuthorizedForDeletion(String sessionID, NOVIUserImpl caller,
+ Set<NOVIUserImpl> owners) {
+ log.info("The caller is "+ caller.toString());
+ Iterator usersiter= owners.iterator();
+ while(usersiter.hasNext())
+ {
+ NOVIUserImpl current=(NOVIUserImpl) usersiter.next();
+ log.info(current.toString());
+ if (caller.toString().equals(current.toString()))
+ {
+ log.info(caller.toString()+ " equals to " + current.toString());
+ return true;
+ }
+ }
+ log.info(caller.toString()+ " does not equals to any of the owners");
+
+ if (caller.getHasNoviRole().toString().equals("http://fp7-novi.eu/NOVIPolicyService.owl#PlanetLabPI"))
+ {
+ log.info("The User has Role "+ caller.getHasNoviRole().toString());
+ log.info("The User is PI");
+ log.info("It belongs to domain(site) "+caller.getBelogsToDomain());
+ Iterator usersite= owners.iterator();
+ while(usersite.hasNext())
+ {
+ NOVIUserImpl current=(NOVIUserImpl) usersite.next();
+ log.info("The owner "+ current.toString()+ " belongs to domain " +current.getBelogsToDomain());
+ if(current.getBelogsToDomain().equals(caller.getBelogsToDomain()))
+ {
+ log.info("The request came from the PI of the domain!!! return TRUE");
+ return true;
+ }
+ }
+
+ }
+ return false;
+ }
+
+ int initMissions()
+ {
+ String sent1="";
+ //String sent2="";
+ if (testbed!=null)
+ {
+ if (testbed.contains("PlanetLab"))
+ {
+ //sent1="fedeint :=(root import:\"root/role/PlanetLabUser/interface\" from:\"rmi://194.132.52.214:1113/Ponder2FED\").\r\n";
+ // sent2="root/event/newsmc create:#(\"FedericaUser\" fedeint).\r\n";
+ sent1="root/event/newsmc create:#(\"FedericaUser\" (root import:\"root/role/PlanetLabUser/interface\" from:\"rmi://194.132.52.214:1113/Ponder2FED\")).\r\n";
+ }
+ if (testbed.contains("FEDERICA"))
+ {
+ //sent1="plint :=(root import:\"root/role/FedericaUser/interface\" from:\"rmi://150.254.160.28:1113/Ponder2PL\").\r\n";
+ // sent2="root/event/newsmc create:#(\"PlanetLabUser\" plint).\r\n";
+ sent1="root/event/newsmc create:#(\"PlanetLabUser\" (root import:\"root/role/FedericaUser/interface\" from:\"rmi://150.254.160.28:1113/Ponder2PL\")).\r\n";
+ }
+ }
+ log.info("To call :"+sent1);
+ // log.info("To call :"+sent2);
+ String result1 = telclient.TelnetPonder2(sent1);
+ //String result2 = telclient.TelnetPonder2(sent2);
+ log.info("We tried to init the missions. The result is: "+result1);
+ return 0;
+ }
+
+ @Override
+ public int AddAllTopologies(String sessionID, Set<Reservation> slices) {
+ try {
+ log.info("Sleeping for 10 seconds to give time for the init of Missions");
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ this.initMissions();
+ //add time delay
+ try {
+ log.info("Sleeping for 10 seconds to give time for the init of Missions");
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if(slices!=null)
+ {
+ Iterator<Reservation> iter = slices.iterator();
+ while (iter.hasNext())
+ {
+ Reservation curr=iter.next();
+ //curr.getHasLifetimes();
+ // curr.getContains().
+
+ log.info("Topology = " + curr.toString() + ", to be added ");
+ //TopologyImpl currtopo= (TopologyImpl) curr;
+ this.AddTopology(sessionID, curr, curr.toString());
+
+ }
+ }
+ //for (Map.Entry<String, Topology> entry : topologies.entrySet()) {
+ // System.out.println("Topology = " + entry.getKey() + ", to be added = " + entry.getValue());
+ // log.info("Topology = " + entry.getKey() + ", to be added = " + entry.getValue());
+ // this.AddTopology(sessionID, entry.getValue(),entry.getKey());
+ // log.info("OK");
+ //}
+ return 0;
+ }
+
+ @Override
+ public int InformExpirationTime(NOVIUserImpl user, String topoID, Date date) {
+ // Sent email to the user with the sliceID and the information that the slice will be deleted in 48 hours
+ String receiver="";
+ if (user!=null)
+ {
+ log.info("The User has User name "+user.toString());
+ receiver=user.toString().substring(41);
+ log.info("So the email address :"+receiver);
+ }
+ else
+ {
+ return 1;
+ }
+ String slice = "none";
+ if (topoID!=null)
+ {
+ slice=topoID;
+ }
+ String dates="";
+ if (date!=null)
+ {
+ dates=date.toString();
+ }
+ log.info("I am sending email to "+ receiver+ "about slice "+ slice+ " for date "+ dates);
+ String information ="Your slice " + slice+ " is about to expire on "+ dates;
+ // Sent email to the User with the sliceID and the info that it was removed
+ this.sentEmailWithREST(receiver, information);
+ return 0;
+ }
+
+ @Override
+ public int InformExpirationHappened(NOVIUserImpl user, String topoID,Date date) {
+ // RIS called the delete slice
+ String receiver="";
+ if (user!=null)
+ {
+ log.info("The User has User name "+user.toString());
+ receiver=user.toString().substring(41);
+ log.info("So the email address :"+receiver);
+ }
+ else
+ {
+ return 1;
+ }
+ String slice = "none";
+ if (topoID!=null)
+ {
+ slice=topoID;
+ }
+ log.info("I am sending email to "+ receiver+ "about slice "+ slice);
+ String information ="Your slice " + slice+ " has expired";
+ this.sentEmailWithREST(receiver, information);
+ // Sent email to the User with the sliceID and the info that it was removed
+ return 0;
+ }
+
+ @Override
+ public int UpdateExpirationTime(NOVIUserImpl user, String topoID, Date date) {
+ //Call authorizeOndelete to see if the user can update the expiration time
+ //call the myplc function that performs the update
+ String receiver="";
+ if (user!=null)
+ {
+ log.info("The User has User name "+user.toString());
+ receiver=user.toString().substring(41);
+ log.info("So the email address :"+receiver);
+ }
+ else
+ {
+ return 1;
+ }
+ String slice = "none";
+ if (topoID!=null)
+ {
+ slice=topoID;
+ }
+ //Expiration ex=new Expiration();
+ int r=-1;
+ if (authenticationComp!=null)
+ {
+ try {
+
+ r=authenticationComp.updateExpirationTime(user, topoID, date);
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ else {log.info("Authentication Component is null");}
+ //sent email to the User with sliceId the the new date that the expiration will happen
+ log.info("I am sending email to "+ receiver+ "about slice "+ slice);
+ String information ="Your slice " + slice+ " is updated";
+ this.sentEmailWithREST(receiver, information);
+
+
+ return r;
+ }
+
+}
diff --git a/policy-listener/src/main/resources/OSGI-INF/blueprint/config.xml b/policy-listener/src/main/resources/OSGI-INF/blueprint/config.xml
new file mode 100644
index 0000000..b2d1e5a
--- /dev/null
+++ b/policy-listener/src/main/resources/OSGI-INF/blueprint/config.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+
+<!-- Author: Blazej Pietrzak [blazej.pietrzak@man.poznan.pl] -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0">
+
+ <cm:property-placeholder persistent-id="eu.novi.pmAA"/>
+ <bean id="authorizeman" class="eu.novi.policylistener.synchWithRIS.AuthorizationSearch" >
+ <property name="userFeedback" ref="refUserFeedback"/>
+ <property name="testbed" value="${testbed}" />
+ <property name="authenticationComp" ref="refAuthComp" />
+ </bean>
+
+ <service ref="authorizeman" interface="eu.novi.policylistener.interfaces.InterfaceForRIS" >
+ <service-properties>
+ <entry key="service.exported.interfaces" value="*" />
+ </service-properties>
+ </service>
+
+ <bean id="authorizeMon" class="eu.novi.policylistener.monitoringInteractions.MonitoringEvents" >
+ <property name="userFeedback" ref="refUserFeedback"/>
+ </bean>
+ <service ref="authorizeMon" interface="eu.novi.policylistener.interfaces.InterfaceForMonitoring" />
+
+ <bean id="requestToAuthentication" class="eu.novi.policylistener.authentication.Basic">
+ <property name="authenticationComp" ref="refAuthComp" />
+ </bean>
+
+
+ <bean id="authorizeAPI" class="eu.novi.policylistener.authentication.Basic" >
+ <property name="userFeedback" ref="refUserFeedback"/>
+ <property name="testbed" value="${testbed}" />
+ </bean>
+
+ <service ref="authorizeAPI" interface="eu.novi.policylistener.interfaces.InterfaceForAPI">
+ <service-properties>
+ <entry key="service.exported.interfaces" value="*" />
+ </service-properties>
+ </service>
+
+
+ <reference id="refUserFeedback" interface="eu.novi.feedback.event.ReportEvent" />
+ <reference id="refAuthComp" interface="eu.novi.authentication.InterfaceForPS" />
+
+</blueprint>
diff --git a/policy-listener/src/main/test/eu/novi/SynchWithRIS/AuthorizationSearchTest.java b/policy-listener/src/main/test/eu/novi/SynchWithRIS/AuthorizationSearchTest.java
new file mode 100644
index 0000000..b110dfd
--- /dev/null
+++ b/policy-listener/src/main/test/eu/novi/SynchWithRIS/AuthorizationSearchTest.java
@@ -0,0 +1,25 @@
+package eu.novi.SynchWithRIS;
+
+import static org.junit.Assert.*;
+//import junit.framework.TestCase;
+import eu.novi.SynchWithRIS.AuthorizationSearch;
+//import .junit.Test;
+import org.junit.Test;
+
+public class AuthorizationSearchTest{
+
+ @Test
+ public void testAuthorizedForResource() {
+ String auth="AUTH";
+ String notauth="NOAUTH";
+ String response;
+ AuthorizationSearch authsearch= new AuthorizationSearch();
+ response= authsearch.AuthorizedForResource("test1" , "test2");
+ if (response.equals(auth))
+ System.out.println("Resource aurhorized for User");
+ else fail("Not yet implemented");
+
+ }
+
+
+}
diff --git a/policy-listener/src/main/test/eu/novi/policy/impl/PolicyManagerImplTest.java b/policy-listener/src/main/test/eu/novi/policy/impl/PolicyManagerImplTest.java
new file mode 100644
index 0000000..d006bce
--- /dev/null
+++ b/policy-listener/src/main/test/eu/novi/policy/impl/PolicyManagerImplTest.java
@@ -0,0 +1,16 @@
+package eu.novi.policy.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class PolicyManagerImplTest {
+
+ //@Test
+// public void test() {
+ // PolicyManagerImpl PlanetLabPM =new PolicyManagerImpl();
+ //PlanetLabPM.startSMC();
+ // fail("Not yet implemented");
+// }
+
+}
diff --git a/policy-listener/src/test/java/eu/novi/policylistener/SynchWithRIS/AuthorizationSearchTest.java b/policy-listener/src/test/java/eu/novi/policylistener/SynchWithRIS/AuthorizationSearchTest.java
new file mode 100644
index 0000000..037eba8
--- /dev/null
+++ b/policy-listener/src/test/java/eu/novi/policylistener/SynchWithRIS/AuthorizationSearchTest.java
@@ -0,0 +1,355 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.SynchWithRIS;
+
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.anySet;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import eu.novi.im.core.CPU;
+import eu.novi.im.core.Memory;
+import eu.novi.im.core.Node;
+import eu.novi.im.core.NodeComponent;
+import eu.novi.im.core.Reservation;
+import eu.novi.im.core.Storage;
+import eu.novi.im.core.Topology;
+import eu.novi.im.core.VirtualLink;
+import eu.novi.im.core.VirtualNode;
+import eu.novi.im.core.impl.LinkImpl;
+import eu.novi.im.core.impl.NodeImpl;
+import eu.novi.im.core.impl.ReservationImpl;
+import eu.novi.im.core.impl.TopologyImpl;
+import eu.novi.im.core.impl.VirtualLinkImpl;
+import eu.novi.im.core.impl.VirtualNodeImpl;
+import eu.novi.im.policy.NOVIUser;
+import eu.novi.im.policy.Role;
+import eu.novi.im.policy.impl.NOVIUserImpl;
+import eu.novi.im.policy.impl.RoleImpl;
+import eu.novi.im.util.IMUtil;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import eu.novi.policylistener.ponder2comms.TelnetClient;
+import eu.novi.policylistener.synchWithRIS.AuthorizationSearch;
+
+public class AuthorizationSearchTest {
+ TelnetClient MockTelCli = mock(TelnetClient.class);
+ AuthorizationSearch auths= new AuthorizationSearch();
+ private static final transient Logger log = LoggerFactory.getLogger(AuthorizationSearchTest.class);
+
+ @Test
+ //@Ignore
+ public void testAuthorizedForResource() {
+ //auths.setTelnetClient(new TelnetClient());
+ //String User="User1";
+ NOVIUserImpl User=new NOVIUserImpl("testUser");
+ RoleImpl plrole= new RoleImpl("PlanetLabUser");
+ User.setHasNoviRole(plrole);
+ User.setBelongsToDomain("4");
+ Set<String> Resources= new HashSet<String>();
+ Resources.add("planetlab1");
+ //Resources.add("planetlab2");
+ Resources.add("http://fp7-novi.eu/im.owl#PlanetLab+planetlab1-novi.lab.netmode.ece.ntua.gr");
+ Resources.add("http://fp7-novi.eu/im.owl#PlanetLab+planetlab2-novi.lab.netmode.ece.ntua.gr");
+ Resources.add("http://fp7-novi.eu/im.owl#PlanetLab+smilax1.man.poznan.pl");
+ Map<String, Boolean> authRes;
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ authRes=auths.AuthorizedForResource(null, User, Resources,0);
+ System.out.println(authRes);
+ //assertEquals(authRes,"{http://fp7-novi.eu/im.owl#PlanetLab+planetlab2-novi.lab.netmode.ece.ntua.gr=true, http://fp7-novi.eu/im.owl#PlanetLab+planetlab1-novi.lab.netmode.ece.ntua.gr=true, http://fp7-novi.eu/im.owl#PlanetLab+planetds2-novi.lab.netmode.ece.ntua.gr=false, planetlab1=true}");
+ //removed it for the mock. With the mock we can't check the results
+
+ }
+
+ @Test
+ //@Ignore
+ public void testAuthorizedForResource2() {
+ NOVIUserImpl User=new NOVIUserImpl("testUser");
+ RoleImpl plrole= new RoleImpl("PlanetLabUser");
+ User.setHasNoviRole(plrole);
+ User.setBelongsToDomain("4");
+ Set<String> Resources= new HashSet<String>();
+ Resources.add("planetlab1");
+ Map<String, Boolean> authRes;
+ authRes=auths.AuthorizedForResource(null, User, Resources,0);
+ System.out.println(authRes);
+
+ }
+
+ @Test
+ //@Ignore
+ public void testAuthorizedForResourced() {
+ String User="User1";
+ String Resources= "Resource";
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ String authRes=auths.AuthorizedForResourced(null, User, Resources);
+ if (authRes=="AUTH")
+ {
+ System.out.println("OK");
+ }
+
+ }
+
+ @Test
+ //@Ignore
+ public void testAddTopologyOneVnode(){
+ Topology topology = new TopologyImpl("myTopology");
+ VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ vNode1.setHardwareType("x86");
+ vNode1.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")));
+ topology.setContains(IMUtil.createSetWithOneValue(vNode1));
+ // System.out.println(topology.getContains().size());
+ System.out.println("OK so far");
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ auths.AddTopology(null, topology, "mytopology");
+ }
+
+ @Test
+ //@Ignore
+ public void testAddMultibleTopologies(){
+ log.info("testAddMultibleTopologies");
+ /*Topology topology1 = new TopologyImpl("myTopology1");
+ VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ vNode1.setHardwareType("x86");
+ vNode1.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")));
+ topology1.setContains(IMUtil.createSetWithOneValue(vNode1));
+ Reservation reservation1= (Reservation) topology1;
+ Topology topology12 = new TopologyImpl("myTopology12");
+ VirtualNode vNode12 = new VirtualNodeImpl("vnode12");
+ vNode12.setHardwareType("x86");
+ vNode12.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab12.ntua.gr")));
+ topology12.setContains(IMUtil.createSetWithOneValue(vNode12));
+ Reservation reservation12= (Reservation) topology12;*/
+ // System.out.println(topology.getContains().size());
+ System.out.println("OK so far");
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ ReservationImpl reservation1 = new ReservationImpl("myReservation11");
+ VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ vNode1.setHardwareType("x86");
+ vNode1.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")));
+ reservation1.setContains(IMUtil.createSetWithOneValue(vNode1));
+ ReservationImpl reservation12 = new ReservationImpl("myReservation12");
+ VirtualNode vNode12 = new VirtualNodeImpl("vnode12");
+ vNode12.setHardwareType("x86");
+ vNode12.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab12.ntua.gr")));
+ reservation12.setContains(IMUtil.createSetWithOneValue(vNode12));
+ Set<Reservation> res=new HashSet<Reservation>();
+ res.add(reservation1);
+ res.add(reservation12);
+ auths.AddAllTopologies(null,res);
+
+ }
+
+ @Test
+ //@Ignore
+ public void testAddMultibleTopologies2(){
+ log.info("testAddMultibleTopologies2");
+ System.out.println("OK so far");
+ /* ReservationImpl reservation1 = new ReservationImpl("myReservation11");
+ VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ vNode1.setHardwareType("x86");
+ vNode1.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")));
+ reservation1.setContains(IMUtil.createSetWithOneValue(vNode1));
+ ReservationImpl reservation12 = new ReservationImpl("myReservation12");
+ VirtualNode vNode12 = new VirtualNodeImpl("vnode12");
+ vNode12.setHardwareType("x86");
+ vNode12.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab12.ntua.gr")));
+ reservation12.setContains(IMUtil.createSetWithOneValue(vNode12));
+ */ Set<Reservation> res=new HashSet<Reservation>();
+ // res.add(reservation1);
+ // res.add(reservation12);
+ auths.AddAllTopologies(null,res);
+
+ }
+ @Test
+ //@Ignore
+ public void testAddMultibleTopologies3(){
+ log.info("testAddMultibleTopologies3");
+ auths.AddAllTopologies(null,null);
+
+ }
+
+/* @Test
+ public void testAddTopologyOneVnodeandOneVLink(){
+ Topology topology = new TopologyImpl("myTopology2");
+ VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ VirtualNode vNode2 = new VirtualNodeImpl("vnode2");
+ VirtualLink vLink1= new VirtualLinkImpl("vlink1");
+ //vNode1.setHardwareType("x86");
+ //NodeImpl node1 = IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")
+ vNode1.setImplementedBy(node1));
+ vNode2.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab2.ntua.gr")));
+ vLink1.setImplementedBy()));
+ topology.setContains(IMUtil.createSetWithOneValue(vNode1));
+ // System.out.println(topology.getContains().size());
+ System.out.println("OK so far");
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ auths.AddTopology(topology, "mytopology2");
+ }*/
+
+ @Test
+ //@Ignore
+ public void testAddEmptyTopology(){
+ System.out.println("testAddEmptyTopology()");
+ Topology topology = new TopologyImpl("myemptyTopology");
+ //VirtualNode vNode1 = new VirtualNodeImpl("vnode1");
+ //vNode1.setHardwareType("x86");
+ //vNode1.setImplementedBy(IMUtil.createSetWithOneValue(new NodeImpl("planetlab1.ntua.gr")));
+ System.out.println("TESTING THE EMPTY TOPO");
+ // topology.setContains(null);
+ //System.out.println(topology.getContains().size());
+
+ System.out.println("OK so far");
+ //AuthorizationSearch auths= new AuthorizationSearch();
+ auths.AddTopology(null, topology, "myemptyTopology");
+
+
+ }
+
+ @Before
+ public <T> void initialize() throws IOException {
+ System.out.println("HERE");
+ log.debug("Initializing AuthorizationSearchTest...");
+
+ auths.setTelnetClient(MockTelCli);
+ when(MockTelCli.TelnetPonder2(anyString())).thenReturn(telClientMock());
+ System.out.println("EDO EFTASE");
+
+ }
+
+ private String telClientMock() {
+ // TODO Auto-generated method stub
+ System.out.println("telnet mock");
+ Random ran= new Random();
+ //System.out.println("Tiponno tous booleans: "+ran.nextBoolean());
+ boolean kat= ran.nextBoolean();
+ if (kat==true)
+ {
+ return "true";
+ }
+ else
+ return "false";
+
+ }
+
+ @Test
+// @Ignore
+ public void setandgetUserfeedback() {
+ auths.setUserFeedback(null);
+ System.out.println(auths.getUserFeedback());
+
+ }
+
+ @Test
+ //@Ignore
+ public void testAuthorizedForDeletion(){
+ System.out.println("Test AuthorizedForDeletion");
+ NOVIUserImpl caller= new NOVIUserImpl("Yiannos");
+ NOVIUserImpl owner= new NOVIUserImpl("Yiannos");
+ Set<NOVIUserImpl> owners= new HashSet<NOVIUserImpl>();
+ owners.add(owner);
+ boolean res=auths.AuthorizedForDeletion(null, caller, owners);
+ assertEquals(res,true);
+ System.out.println("OK");
+ }
+
+ @Test
+ //@Ignore
+ public void testAuthorizedForDeletionPI(){
+ System.out.println("Test AuthorizedForDeletionPI");
+ NOVIUserImpl caller= new NOVIUserImpl("Yiannos");
+ RoleImpl plrole= new RoleImpl("PlanetLabPI");
+ caller.setHasNoviRole(plrole);
+ caller.setBelongsToDomain("4");
+ NOVIUserImpl owner= new NOVIUserImpl("Kostis");
+ owner.setBelongsToDomain("4");
+ Set<NOVIUserImpl> owners= new HashSet<NOVIUserImpl>();
+ owners.add(owner);
+ boolean res=auths.AuthorizedForDeletion(null, caller, owners);
+ //assertEquals(res,true);
+ System.out.println("OK");
+
+ }
+
+ @Test
+ @Ignore
+ public void testInfoaboutExpirationTIme()
+ {
+ System.out.println("Slice about to expire");
+ auths.InformExpirationTime(null, null, null);
+ }
+
+ @Test
+ @Ignore
+ public void testInfoaboutExpirationTIme2()
+ {
+ System.out.println("Slice about to expire");
+ NOVIUserImpl caller= new NOVIUserImpl("ykryftis@netmode.ece.ntua.gr");
+ Date date=new Date("5/18/2013");
+ auths.InformExpirationTime(caller, "topoID", date);
+ }
+
+ @Test
+ @Ignore
+ public void testInfoaboutExpiration()
+ {
+ System.out.println("Slice expired");
+ auths.InformExpirationHappened(null, null, null);
+ }
+
+ @Test
+ @Ignore
+ public void testUpdateExpiration()
+ {
+ System.out.println("Slice expired");
+ NOVIUserImpl caller= new NOVIUserImpl("ykryftis@netmode.ece.ntua.gr");
+ caller.setHasSessionKey("IMDciUUdS+oh+3Gsflo4tR9qiPBARJA3Hr+mBubflXo=");
+ Date date=new Date("3/18/2013");
+ String sliceName = "novi_slice_699986568";
+ auths.UpdateExpirationTime(caller, sliceName, date);
+ }
+
+}
diff --git a/policy-listener/src/test/java/eu/novi/policylistener/authentication/BasicTest.java b/policy-listener/src/test/java/eu/novi/policylistener/authentication/BasicTest.java
new file mode 100644
index 0000000..1be46f2
--- /dev/null
+++ b/policy-listener/src/test/java/eu/novi/policylistener/authentication/BasicTest.java
@@ -0,0 +1,133 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.authentication;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Set;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import eu.novi.im.policy.NOVIUser;
+import eu.novi.policylistener.authentication.Basic;
+public class BasicTest {
+
+ @Test
+ @Ignore
+ public void TestOnAuth0() throws Exception
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ //NOVIUser theUser=bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi");
+ NOVIUser theUser=bauth.getAuth("chrisap@noc.ntua.gr","novi1");
+
+ System.out.println(theUser.getHasSessionKey());
+ System.out.println(theUser.toString());
+ System.out.println("OK about Authentication without public key");
+ }
+
+ @Test
+ @Ignore
+ public void TestOnSendPolicy()
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ //NOVIUser theUser=bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi");
+ bauth.addPolicyFromFile("http://www.netmode.ntua.gr/~ykryftis/ex1.p2");
+ System.out.println("OK provided the file");
+ }
+
+ @Test
+ @Ignore
+ public void TestOnManualPolicy()
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ //NOVIUser theUser=bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi");
+ System.out.println("So the result of the ls is: \n"+bauth.mCallToPonder2("ls")+".THE END");
+ System.out.println("So the result of the ls is: \n"+bauth.mCallToPonder2("cd event")+".THE END");
+ System.out.println("So the result of the ls is: \n"+bauth.mCallToPonder2("ls /root/event")+".THE END");
+ }
+
+ @Test
+ @Ignore
+ public void TestOnAuth() throws Exception
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ NOVIUser theUser=bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi");
+ //NOVIUser theUser=bauth.getAuth("chrisap@noc.ntua.gr","novi1");
+
+ System.out.println(theUser.getHasSessionKey());
+ System.out.println(theUser.toString());
+ Set<String> theRoles = theUser.getHasRoleInPlatform();
+ for (Object object : theRoles) {
+ System.out.println(object.toString());
+ }
+ System.out.println(theUser.getHasUserPlatform());
+ assertEquals("http://fp7-novi.eu/im.owl#PlanetLab",theUser.getHasUserPlatform().toString());
+ for (Object object : theUser.getPublicKeys()) {
+ System.out.println(object.toString());
+ // assertEquals("ssh-rsa root@snf-965",object.toString());
+ }
+ System.out.println(theUser.getBelogsToDomain());
+ System.out.println("theUser.getHasNoviRole()"+ theUser.getHasNoviRole());
+ System.out.println("OK about Authentication");
+ }
+
+ @Test
+ @Ignore
+ public void TestOnAuth2() throws Exception
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ NOVIUser theUser=bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmoden");
+ if (theUser.getHasSessionKey() == null)
+ {
+ System.out.println("OK SessionKey is null");
+ }
+ System.out.println("OK about NOT Authentication");
+ }
+
+ @Test
+ @Ignore
+ public void TestOnAuth3() throws Exception
+ {
+ Basic bauth= new Basic();
+ //assertEquals(0,bauth.getAuth("ykryftis@netmode.ece.ntua.gr","netmodenovi"));
+ NOVIUser theUser=bauth.getAuth("notexisting@nothing.eu","password");
+ if (theUser.getHasSessionKey() == null)
+ {
+ System.out.println("OK SessionKey is null");
+ }
+ System.out.println("OK about NOT Existing User");
+ }
+
+}
diff --git a/policy-listener/src/test/java/eu/novi/policylistener/ponder2comms/TelnetClientTest.java b/policy-listener/src/test/java/eu/novi/policylistener/ponder2comms/TelnetClientTest.java
new file mode 100644
index 0000000..bdb9954
--- /dev/null
+++ b/policy-listener/src/test/java/eu/novi/policylistener/ponder2comms/TelnetClientTest.java
@@ -0,0 +1,124 @@
+/**
+ *
+ * Copyright (c) 2012, NOVI Consortium, European FP7 NOVI Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the NOVI Consortium nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL NOVI CONSORTIUM BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Contact: Yiannos Kryftis <ykryftis@netmode.ece.ntua.gr>
+ */
+package eu.novi.policylistener.ponder2comms;
+import static org.junit.Assert.*;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.net.UnknownHostException;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.Ignore;
+import org.mockito.stubbing.OngoingStubbing;
+
+import eu.novi.policylistener.ponder2comms.TelnetClient;
+
+import static org.mockito.Mockito.mock;
+
+public class TelnetClientTest {
+
+
+// Piotr Pikusa: I have disabled this test because integration test must not try to connect system-tests instance
+// since on the latter there is nothing installed before successful finish Integration on CI.
+
+
+ TelnetClient telc= new TelnetClient();
+ Socket Mocksoc= mock(Socket.class);
+ DataInputStream MockDin= mock(DataInputStream.class);
+ //BufferedReader MockDin= mock(BufferedReader.class);
+ DataOutputStream MockDout= mock(DataOutputStream.class);
+
+ @Test
+ @Ignore
+ public void test() {
+ String result = "";
+ result = telc.TelnetPonder2("true.\r\n");
+ System.out.println("So we can comminicate with ponder2 with telnet");
+ System.out.println(result);
+ if (result.equals("false"))
+ {
+ fail("No connection with Ponder2 (telnet 150.254.160.28 13570)");
+ }
+ if (result.equals("true"))
+ {
+ System.out.println("We passed the test for the connection");
+ }
+ }
+}
+/* @Test
+ public void testMock() {
+ System.out.println("TTTTTest");
+ String result = "";
+ result = telc.TelnetPonder2("true.\r\n");
+ System.out.println("So we can comminicate with ponder2 with telnet");
+ }
+
+ @SuppressWarnings("deprecation")
+ @Before
+ public <T> void initialize() throws IOException {
+ System.out.println("HERE");
+ //log.debug("Initializing AuthorizationSearchTest...");
+
+ telc.setSocket(Mocksoc);
+ //telc.setDataInputStream(MockDin);
+ //telc.setDataOutputStream(MockDout);
+ //when(Mocksoc.getInputStream()).thenReturn(MockDin);
+ telc.setDataInputStream(MockDin);
+ //when(Mocksoc.getOutputStream()).thenReturn(MockDout);
+ System.out.println("no1");
+ //when(MockDin.readLine()).thenReturn("ds");
+ //when(MockDin.readLine()).thenReturn(mockreadLine());
+ when(MockDin.readLine()).thenReturn("akslfjlksa");
+
+ System.out.println("no2");
+ // when(MockDout.writeBytes(anyString())).thenReturn();
+ System.out.println("no3");
+ }
+
+ //private mockflush()
+ //{
+
+ //}
+
+ public String mockreadLine()
+ {
+ return "ab";
+ }
+
+}
+*/ \ No newline at end of file