source: TI12-security/trunk/python/Tests/security.py @ 1007

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/security.py@1007
Revision 1007, 6.0 KB checked in by pjkersha, 16 years ago (diff)

Tests/security.py: derived class from SecurityCGI for testing x domain cookie functionality.

Line 
1#!/usr/bin/env python
2
3"""Example NDG Security CGI service based on SecurityCGI base class
4
5NERC Data Grid Project
6
7P J Kershaw 25/05/06
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14from NDG.SecurityCGI import *
15
16
17class TestSecurityCGI(SecurityCGI):
18    """CGI interface test class for NDG Security"""
19    #_________________________________________________________________________
20    def showLogin(self,
21                  returnURI=None,
22                  **junk):
23        """Display initial NDG login form"""
24   
25        if returnURI:
26            returnURIfield = \
27                "<input type=hidden name=returnURI value=\"%s\">" % returnURI
28        else:
29            returnURIfield = ''
30           
31           
32        if bAuthorise:
33            authoriseArg = "<input type=hidden name=authorise value=\"1\">"
34        else:
35            authoriseArg = ""
36   
37   
38        # Set authorisation method default
39        authorisationMethodChk = {  "allowMapping":              '',
40                                    "allowMappingWithPrompt" :   '',
41                                    "noMapping":                 ''}
42   
43        if self.__authorisationMethod is None:
44            # Default to safest option for user
45            authorisationMethodChk["allowMappingWithPrompt"] = ' checked'
46        else:
47            authorisationMethodChk[self.__authorisationMethod] = ' checked'
48   
49
50        print """Content-type: text/html
51       
52<html>"   
53<head>
54<title>%s</title>
55<style type=\"text/css\">
56<!--
57.al {
58text-align: justify
59}
60a{
61text-decoration:none;
62}
63a:hover{
64color:#0000FF;
65}
66    body { font-family: Verdana, sans-serif; font-size: 11}
67    table { font-family: Verdana, sans-serif; font-size: 11}
68-->
69</style>
70</head>
71<body>
72    <script language="javascript">
73        <!--
74            function toggleLayer(layerId)
75            {
76                if (document.getElementById)
77                {
78                    // Standard
79                    var style = document.getElementById(layerId).style;
80                }
81                else if (document.all)
82                {
83                    // Old msie versions
84                    var style = document.all[whichLayer].style;
85                }
86                else if (document.layers)
87                {
88                    // nn4
89                    var style = document.layers[whichLayer].style;
90                }
91                style.visibility = style.visibility == "visible" ? "hidden":"visible";
92            }
93        //-->
94    </script>
95    <h3>NERC Data Grid Site Login (Test)<BR clear=all></h3>
96    <hr>
97   
98    <form action="%s" method="POST">
99   
100    <table bgcolor=#ADD8E6 cellspacing=0 border=0 cellpadding=5>
101    <tbody>
102    <tr><td>User Name:</td> <td><input type=text name=userName value="">
103    </td></tr>
104    <tr>
105        <td>Password:</td>
106        <td><input type=password name=passPhrase></td>
107    </tr>
108    <tr>
109        <td colspan="2" align="right">
110            <a href="javascript:toggleLayer('advSettings');">Advanced Settings</a>
111            <input type=submit value="Login">
112        </td>
113    </tr>
114    <input type=hidden name=authenticate value="1">
115    %s"""  % (self.scriptName, returnURIfield)
116   
117        print \
118    """</tbody></table>
119    <br>
120    <div id="advSettings" style="position: relative; visibility: hidden;">
121        <h4>Role Mapping for access to other trusted sites</h4>
122        <p>Your account has roles or <i>privileges</i> which determine what data you have access to.  If you access data at another NDG trusted site, these roles can be mapped to local roles at that site to help you gain access:
123        </p>
124        <table bgcolor=#ADD8E6 cellspacing=0 border=0 cellpadding=5>
125        <tbody>
126        <tr>
127        <td>
128            <input type="radio" name="authorisationMethod" value="allowMapping"%s>
129        </td>
130            <td>
131                Allow my roles to be mapped to local roles at other NDG trusted sites.
132            </td>
133        </tr>
134        <tr>
135            <td>
136                <input type="radio" name="authorisationMethod" value="allowMappingWithPrompt"%s>
137            </td>
138        <td>
139            Allow my roles to be mapped, but prompt me so that I may choose which roles to map before gaining access.
140        </td>
141        <tr>
142        <td>
143            <input type="radio" name="authorisationMethod" value="noMapping"%s>
144        </td>
145        <td>
146            Don't allow mapping of my roles.
147        </td>
148        </tr>
149        </tbody>
150        </table>
151    </div>
152    </form>
153</body>
154</html>""" % (authorisationMethodChk['allowMapping'], \
155              authorisationMethodChk['allowMappingWithPrompt'], \
156              authorisationMethodChk['noMapping'])
157   
158        # end of showLogin()
159   
160   
161    def showHomeSiteSelect(self, trustedHosts=None):
162
163        if trustedHosts:
164            self.trustedHosts = trustedHosts           
165               
166        print """Content-type: text/html
167               
168<html>
169<head>
170    <title>Select site to retrieve credentials</title>
171    <style type=\"text/css\">
172    <!--
173    .al {
174    text-align: justify
175    }
176    a{
177    text-decoration:none;
178    }
179    a:hover{
180    color:#0000FF;
181    }
182        body { font-family: Verdana, sans-serif; font-size: 11}
183        table { font-family: Verdana, sans-serif; font-size: 11}
184    -->
185    </style>
186</head>
187<body>
188    <form action="%s" method="POST">
189    <table bgcolor=#ADD8E6 cellspacing=0 border=0 cellpadding=5>
190    <tbody>
191    <tr>
192      <td>
193        <select name="requestURI">       
194          <option value="">Select your home site...""" % self.scriptName
195         
196        for hostname, uri in trustedHosts.items():
197            print "<option value=\"%s\">%s" % (uri, hostname)
198               
199        print \
200"""     </select>
201      </td>
202      <td align="right">
203        <input type=submit value="Go">
204      </td>
205    </tr>
206    </tbody>
207    </table>
208    </form>
209</body></html>"""
210   
211        # end of showHomeSiteSelect()
212
213if __name__ == "__main__":
214    securityCGI = TestSecurityCGI()
215    securityCGI()
Note: See TracBrowser for help on using the repository browser.