source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/config/attributeauthority/sitea/attributeauthorityapp.py @ 7844

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/config/attributeauthority/sitea/attributeauthorityapp.py@7844
Revision 7844, 2.1 KB checked in by pjkersha, 9 years ago (diff)

2.2.0 Release Candidate

  • Includes paster templates for OpenID Provider, SAML Attribute and Authorisation Services and generic templates for securing a WSGI application and for running a complete set of the security services.
  • Property svn:executable set to *
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2"""NDG Security Attribute Authority test harness for unit test site 'A'
3
4NERC Data Grid Project
5
6"""
7__author__ = "P J Kershaw"
8__date__ = "24/09/08"
9__copyright__ = "(C) 2009 Science and Technology Facilities Council"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id$"
12from os import path
13import optparse
14from ndg.security.server.utils.paste_utils import PasteDeployAppServer
15
16INI_FILENAME = 'attribute-service.ini'
17
18
19# To start the Site A Attribute Authority run
20# $ paster serve attribute-service.ini or run this file as a script
21# $ ./sitea_attributeauthority.py [--port #][--conf <config file path>]
22if __name__ == '__main__':
23    cfgFilePath = path.join(path.dirname(path.abspath(__file__)), INI_FILENAME) 
24       
25    parser = optparse.OptionParser()
26    parser.add_option("-p",
27                      "--port",
28                      dest="port",
29                      default=5443,
30                      type='int',
31                      help="port number to run under")
32
33    parser.add_option("-c",
34                      "--cert-file",
35                      dest='certFilePath',
36                      help="SSL Certificate file")
37
38    parser.add_option("-k",
39                      "--private-key-file",
40                      dest='priKeyFilePath',
41                      help="SSL private key file")
42
43    parser.add_option("-f",
44                      "--conf",
45                      dest="configFilePath",
46                      default=cfgFilePath,
47                      help="Configuration file path")
48   
49    opt = parser.parse_args()[0]       
50   
51    if opt.certFilePath:   
52        from OpenSSL import SSL
53       
54        ssl_context = SSL.Context(SSL.SSLv23_METHOD)
55        ssl_context.set_options(SSL.OP_NO_SSLv2)
56   
57        ssl_context.use_privatekey_file(opt.priKeyFilePath)
58        ssl_context.use_certificate_file(opt.certFilePath)
59    else:
60        ssl_context = None
61       
62    server = PasteDeployAppServer(cfgFilePath=opt.configFilePath, 
63                                  port=opt.port,
64                                  ssl_context=ssl_context) 
65    server.start()
Note: See TracBrowser for help on using the repository browser.