snf-occi API server now logs voms info in requests
authorJohn Giannelos <johngian@grnet.gr>
Sun, 28 Oct 2012 16:47:01 +0000 (18:47 +0200)
committerJohn Giannelos <johngian@grnet.gr>
Sun, 28 Oct 2012 17:39:09 +0000 (19:39 +0200)
snfOCCI/APIserver.py
snfOCCI/voms/__init__.py

index 9111312..ca7af62 100755 (executable)
@@ -12,11 +12,12 @@ from occi.core_model import Mixin, Resource
 from occi.backend import MixinBackend
 from occi.extensions.infrastructure import COMPUTE, START, STOP, SUSPEND, RESTART, RESOURCE_TEMPLATE, OS_TEMPLATE
 from occi.wsgi import Application
+from occi.exceptions import HTTPError
 
 from wsgiref.simple_server import make_server
 from wsgiref.validate import validator
 
-
+import voms
 
 
 class MyAPP(Application):
@@ -98,8 +99,22 @@ class MyAPP(Application):
         self.refresh_flavors(compClient,cyclClient)
         self.refresh_compute_instances(compClient)
 
-        # token will be represented in self.extras
-        return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)
+        ssl_dict = dict()
+        ssl_dict["SSL_CLIENT_S_DN_ENV"] = environ["SSL_CLIENT_S_DN_ENV"]
+        ssl_dict["SSL_CLIENT_CERT_ENV"] = environ["SSL_CLIENT_CERT_ENV"]
+        ssl_dict["SSL_CLIENT_CERT_CHAIN_0_ENV"] = environ["SSL_CLIENT_CERT_CHAIN_0_ENV"]
+
+        info = voms.authenticate(ssl_dict)
+        print info
+
+        #Always authenticated, only for testing purposes 
+        authenticated = True
+
+        if authenticated:
+            # token will be represented in self.extras
+            return self._call_occi(environ, response, security = None, token = environ['HTTP_AUTH_TOKEN'], snf = compClient, client = cyclClient)
+        else:
+            raise HTTPError(404, "Unauthorized access")
 
 
 def main():
index 238ebf4..4e94a5c 100644 (file)
@@ -8,6 +8,7 @@ import M2Crypto
 
 import snfOCCI.config
 import voms_helper
+import exception
 
 SSL_CLIENT_S_DN_ENV = "SSL_CLIENT_S_DN"
 SSL_CLIENT_CERT_ENV = "SSL_CLIENT_CERT"
@@ -69,8 +70,7 @@ def _get_voms_info(self, ssl_info):
     except M2Crypto.X509.X509Error:
         print "Error getting certificate chain"
 
-    with voms_helper.VOMS(VOMS_CONFIG["vomsdir_path"],
-                          VOMS_CONFIG["ca_path"], VOMS_CONFIG["vomsapi_lib"] as v:
+    with voms_helper.VOMS(VOMS_CONFIG["vomsdir_path"],VOMS_CONFIG["ca_path"], VOMS_CONFIG["vomsapi_lib"]) as v:
         if self._no_verify:
             v.set_no_verify()
         voms_data = v.retrieve(cert, chain)