X Tutup
Skip to content

Commit 1bfa3ad

Browse files
committed
SESPRINGPYTHONPY-49: Merged trunk/springpython@144:branches/SESPRINGPYTHONPY-49@144 into trunk. Verified everything works. Included new option to run tests with coverage analysis. Also put notice about FilterSecurityInterceptor into PetClinic as well as reference documentation.
git-svn-id: https://src.springframework.org/svn/se-springpython-py/trunk/springpython@145 ce8fead1-4192-4296-8608-a705134b927f
1 parent 5816d70 commit 1bfa3ad

File tree

12 files changed

+526
-141
lines changed

12 files changed

+526
-141
lines changed

.pydevproject

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
<pydev_project>
55
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
66
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
7-
<path>/springpython/src</path>
8-
<path>/springpython/samples/petclinic</path>
9-
<path>/springpython/samples/springirc</path>
10-
<path>/springpython/samples/springwiki</path>
11-
<path>/springpython/test</path>
7+
<path>/se-springpython-py-49/src</path>
8+
<path>/se-springpython-py-49/samples/petclinic</path>
9+
<path>/se-springpython-py-49/samples/springirc</path>
10+
<path>/se-springpython-py-49/samples/springwiki</path>
11+
<path>/se-springpython-py-49/test</path>
12+
<path>/se-springpython-py-49/samples/basic</path>
1213
</pydev_pathproperty>
1314
</pydev_project>

build.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def usage():
5353
print "\t--help\t\t\tprint this help message"
5454
print "\t--clean\t\t\tclean out this build by deleting the %s directory" % p["targetDir"]
5555
print "\t--test\t\t\trun the test suite, leaving all artifacts in %s" % p["testDir"]
56+
print "\t--coverage\t\trun the test suite with coverage analysis, leaving all artifacts in %s" % p["testDir"]
5657
print "\t--package\t\tpackage everything up into a tarball for release to sourceforge in %s" % p["packageDir"]
5758
print "\t--build-stamp [tag]\tfor --package, this specifies a special tag, generating version tag '%s-<tag>'" % p["version"]
5859
print "\t\t\t\tIf this option isn't used, default will be tag will be '%s-<current time>'" % p["version"]
@@ -68,7 +69,7 @@ def usage():
6869
try:
6970
optlist, args = getopt.getopt(sys.argv[1:],
7071
"hct",
71-
["help", "clean", "test", "package", "build-stamp=", \
72+
["help", "clean", "test", "coverage", "package", "build-stamp=", \
7273
"publish", "register", \
7374
"site", "docs-html-multi", "docs-html-single", "docs-pdf", "docs-all"])
7475
except getopt.GetoptError:
@@ -92,14 +93,18 @@ def clean(dir):
9293
print "Removing '%s' directory" % dir
9394
if os.path.exists(dir):
9495
shutil.rmtree(dir)
96+
# TODO: Make this OS-independent
97+
os.system("find . -name '*.pyc' -exec rm -f {} \;")
98+
os.system("find . -name '*.class' -exec rm -f {} \;")
99+
os.system("find . -name '*~' -exec rm -f {} \;")
95100

96101
def test(dir):
97102
os.makedirs(dir)
98103
os.system("nosetests --with-nosexunit --source-folder=src --where=test/springpythontest --xml-report-folder=%s" % dir)
99104

100-
# TODO(9/5/2008 GLT): Capture coverage data that is visible to bamboo. Does coverage have an API to view .coverage file?
101-
# With coverage... (copied from former bamboo.sh, not yet tested in this configuration)
102-
#os.system("nosetests --with-nosexunit --with-coverage --xml-report-folder=build --cover-package=springpython")
105+
def test_coverage(dir):
106+
os.makedirs(dir)
107+
os.system("nosetests --with-nosexunit --source-folder=src --where=test/springpythontest --xml-report-folder=%s --with-coverage --cover-package=springpython" % dir)
103108

104109
def package(dir, version):
105110
os.makedirs(dir)
@@ -240,6 +245,9 @@ def docs_pdf(version):
240245
if option[0] in ("--test"):
241246
test(p["testDir"])
242247

248+
if option[0] in ("--coverage"):
249+
test_coverage(p["testDir"])
250+
243251
if option[0] in ("--package"):
244252
package(p["packageDir"], completeVersion)
245253

docs/reference/src/samples.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
<emphasis>raw</emphasis>) is part of the source code. You can read it from here
1919
or by clicking on a hyperlink while running the application.</para>
2020
</listitem>
21-
</itemizedlist>
21+
</itemizedlist>
22+
23+
<para>NOTICE: Spring Python's FilterSecurityInterceptor has NOT been upgraded to CherryPy 3.1 yet (while the rest of PetClinic has). Somes pages for certain users are not yet denying access as expected.</para>
2224

2325
<section id="samples-petclinic-running">
2426
<title>How to run</title>
@@ -618,4 +620,4 @@ ProxyPassReverse /coily/ http://localhost:9001/
618620

619621
</section>
620622

621-
</chapter>
623+
</chapter>

samples/basic/app.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Copyright 2006-2008 SpringSource (http://springsource.com), All Rights Reserved
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
"""
19+
NOTE: This is a test application being used to help migrate Spring Python
20+
to support CherryPy version 3.1. Hopefully, it will become a standard part
21+
of the application samples.
22+
"""
23+
24+
import cherrypy
25+
26+
from springpython.security.providers import AuthenticationManager
27+
from springpython.security.providers.dao import DaoAuthenticationProvider
28+
from springpython.security.userdetails import InMemoryUserDetailsService
29+
from springpython.security.cherrypy31 import AuthenticationFilter, ContextSessionFilter, SecurityFilter
30+
from springpython.security.context import SecurityContextHolder, SecurityContext
31+
32+
def initialize_spring():
33+
# Global is probably not a very good idea...
34+
SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)
35+
SecurityContextHolder.getContext()
36+
37+
def filter_chainer(filters):
38+
for f in filters:
39+
f.run()
40+
41+
def make_session_filter():
42+
contextSessionFilter = ContextSessionFilter()
43+
cherrypy.tools.sessionFilter = cherrypy.Tool('before_handler', filter_chainer, priority=74)
44+
45+
return contextSessionFilter
46+
47+
def make_auth_manager():
48+
userDetailsService = InMemoryUserDetailsService({"admin": ("test", ["ADMIN"], True)})
49+
return AuthenticationManager([DaoAuthenticationProvider(userDetailsService)])
50+
51+
def make_authentication_filter(manager):
52+
authFilter = AuthenticationFilter(authManager=manager)
53+
cherrypy.tools.authFilter = cherrypy.Tool('before_handler', filter_chainer, priority=75)
54+
return authFilter
55+
56+
def make_security_filter(manager):
57+
securityFilter = SecurityFilter(authManager=manager)
58+
cherrypy.tools.securityFilter = cherrypy.Tool('before_handler', filter_chainer, priority=75)
59+
return securityFilter
60+
61+
initialize_spring()
62+
63+
manager = make_auth_manager()
64+
65+
session_filter = make_session_filter()
66+
auth_filter = make_authentication_filter(manager)
67+
security_filter = make_security_filter(manager)
68+
69+
70+
class BasicApplication(object):
71+
72+
@cherrypy.expose
73+
def index(self):
74+
return """<html>
75+
<head><title>Basic Spring Python demo</title></head>
76+
<body>
77+
Hello there. Please login below:
78+
<form action="/login" method="post">
79+
<label for="username">Username:</label>
80+
<input type="text" name="username" id="username" />
81+
<label for="password">Password:</label>
82+
<input type="password" name="password" id="password" />
83+
<input type="submit" />
84+
</form>
85+
</body>
86+
</html>"""
87+
88+
@cherrypy.expose
89+
def login(self, username, password):
90+
# if we got here it means we are authenticated
91+
raise cherrypy.HTTPRedirect('/admin')
92+
93+
class AdminApplication(object):
94+
@cherrypy.expose
95+
def index(self):
96+
return "You are in a restricted area."
97+
98+
if __name__ == '__main__':
99+
conf = {'/': {'tools.sessions.on': True,
100+
'tools.sessionFilter.on': True,
101+
'tools.sessionFilter.filters': [session_filter]},
102+
'/login': {'tools.authFilter.on': True,
103+
'tools.authFilter.filters': [auth_filter]}}
104+
admin_conf = {'/': {'tools.sessions.on': True,
105+
'tools.securityFilter.on': True,
106+
'tools.securityFilter.filters': [session_filter, security_filter]}}
107+
108+
cherrypy.tree.mount(BasicApplication(), '/', config=conf)
109+
cherrypy.tree.mount(AdminApplication(), '/admin', config=admin_conf)
110+
111+
cherrypy.engine.start()
112+
cherrypy.engine.block()
113+

samples/basic/app2.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Copyright 2006-2008 SpringSource (http://springsource.com), All Rights Reserved
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
"""
19+
NOTE: This is a test application being used to help migrate Spring Python
20+
to support CherryPy version 3.1. Hopefully, it will become a standard part
21+
of the application samples.
22+
"""
23+
24+
import cherrypy
25+
26+
from springpython.security.providers import AuthenticationManager
27+
from springpython.security.providers.dao import DaoAuthenticationProvider
28+
from springpython.security.userdetails import InMemoryUserDetailsService
29+
from springpython.security.cherrypy31 import AuthenticationFilter, ContextSessionFilter, SecurityFilter
30+
from springpython.security.context import SecurityContextHolder, SecurityContext
31+
32+
def initialize_spring():
33+
# Global is probably not a very good idea...
34+
SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)
35+
SecurityContextHolder.getContext()
36+
37+
def filter_chainer(filters):
38+
for f in filters:
39+
f.run()
40+
41+
def make_session_filter():
42+
contextSessionFilter = ContextSessionFilter()
43+
cherrypy.tools.sessionFilter = cherrypy.Tool('before_handler', filter_chainer, priority=74)
44+
return contextSessionFilter
45+
46+
def make_auth_manager():
47+
userDetailsService = InMemoryUserDetailsService({"admin": ("test", ["ADMIN"], True)})
48+
return AuthenticationManager([DaoAuthenticationProvider(userDetailsService)])
49+
50+
def make_authentication_filter(manager):
51+
authFilter = AuthenticationFilter(authManager=manager)
52+
cherrypy.tools.authFilter = cherrypy.Tool('before_handler', filter_chainer, priority=75)
53+
return authFilter
54+
55+
def make_security_filter(manager):
56+
securityFilter = SecurityFilter(authManager=manager)
57+
cherrypy.tools.securityFilter = cherrypy.Tool('before_handler', filter_chainer, priority=75)
58+
return securityFilter
59+
60+
initialize_spring()
61+
62+
manager = make_auth_manager()
63+
64+
session_filter = make_session_filter()
65+
auth_filter = make_authentication_filter(manager)
66+
security_filter = make_security_filter(manager)
67+
68+
69+
def filterProxyChainer(filters):
70+
def outter(func):
71+
def inner(*args, **kwargs):
72+
for f in filters:
73+
f.run()
74+
return func(*args, **kwargs)
75+
return inner
76+
return outter
77+
78+
79+
class BasicApplication(object):
80+
81+
@cherrypy.expose
82+
def index(self):
83+
return """<html>
84+
<head><title>Basic Spring Python demo</title></head>
85+
<body>
86+
Hello there. Please login below:
87+
<form action="/login" method="post">
88+
<label for="username">Username:</label>
89+
<input type="text" name="username" id="username" />
90+
<label for="password">Password:</label>
91+
<input type="password" name="password" id="password" />
92+
<input type="submit" />
93+
</form>
94+
</body>
95+
</html>"""
96+
97+
@cherrypy.expose
98+
@filterProxyChainer(filters=[session_filter, auth_filter])
99+
def login(self, username, password):
100+
# if we got here it means we are authenticated
101+
raise cherrypy.HTTPRedirect('/admin')
102+
103+
class AdminApplication(object):
104+
@cherrypy.expose
105+
@filterProxyChainer(filters=[session_filter, security_filter])
106+
def index(self):
107+
return "You are in a restricted area."
108+
109+
if __name__ == '__main__':
110+
conf = {'/': {'tools.sessions.on': True,}}
111+
admin_conf = {'/': {'tools.sessions.on': True}}
112+
113+
cherrypy.tree.mount(BasicApplication(), '/', config=conf)
114+
cherrypy.tree.mount(AdminApplication(), '/admin', config=admin_conf)
115+
116+
cherrypy.engine.start()
117+
cherrypy.engine.block()
118+

samples/petclinic/cherrypy/noxml.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ def view(self):
314314
petClientView.controller = self.controller()
315315
return petClientView
316316

317+
@component
318+
def root(self):
319+
return view.PetClinicView(self.controller())
320+
317321
@component
318322
def userDetailsService(self):
319323
userDetailsService = PyroProxyFactory()

0 commit comments

Comments
 (0)
X Tutup