Skip to content

Commit 741c994

Browse files
author
Dariusz Suchojad
committed
SESPRINGPYTHONPY-126: Synced with trunk.
git-svn-id: https://src.springframework.org/svn/se-springpython-py/sandbox/dsuch/jira/SESPRINGPYTHONPY-126@714 ce8fead1-4192-4296-8608-a705134b927f
2 parents 6409afb + 3fe954b commit 741c994

22 files changed

+4211
-84
lines changed
Binary file not shown.
Binary file not shown.
Loading

springpython/docs/reference/src/index.xml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
<!ENTITY aop SYSTEM "aop.xml">
77
<!ENTITY transaction SYSTEM "transaction.xml">
88
<!ENTITY dao SYSTEM "dao.xml">
9-
<!ENTITY remoting SYSTEM "remoting.xml">
10-
<!ENTITY security SYSTEM "security.xml">
9+
<!ENTITY remoting SYSTEM "remoting.xml">
10+
<!ENTITY security SYSTEM "security.xml">
1111
<!ENTITY plugins SYSTEM "plugins.xml">
12-
<!ENTITY samples SYSTEM "samples.xml">
12+
<!ENTITY jms SYSTEM "jms.xml">
13+
<!ENTITY samples SYSTEM "samples.xml">
1314
]>
1415
<book>
1516
<bookinfo>
@@ -36,15 +37,16 @@
3637
<!-- front matter -->
3738
<toc/>
3839

39-
&preface;
40+
&preface;
4041
&overview;
41-
&objects;
42-
&aop;
43-
&dao;
44-
&transaction;
45-
&security;
42+
&objects;
43+
&aop;
44+
&dao;
45+
&transaction;
46+
&security;
4647
&remoting;
48+
&jms;
4749
&plugins;
48-
&samples;
50+
&samples;
4951

5052
</book>

springpython/docs/reference/src/jms.xml

Lines changed: 1625 additions & 0 deletions
Large diffs are not rendered by default.

springpython/docs/reference/src/overview.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
server pieces using the IoC container, then going from local to distributed is
6666
just a configuration change.</para>
6767
</listitem>
68+
69+
<listitem>
70+
<para><link linkend="jms">JMS Messaging</link> - Connect to Java
71+
or Python applications using queueing middleware. Spring Python
72+
can act as a standalone client of a JMS provider with no
73+
Java EE infrastructure needed on Python side.</para>
74+
</listitem>
75+
6876
<listitem>
6977
<para><link linkend="plugins">Plug-ins/command-line tool</link> - Use the plugin
7078
system designed to help you rapidly develop applications.</para>

springpython/docs/reference/src/samples.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
</listitem>
2121
</itemizedlist>
2222

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>
24-
2523
<section id="samples-petclinic-running">
2624
<title>How to run</title>
2725

@@ -44,7 +42,8 @@ bash$ python petclinic.py
4442

4543
<para>This assumes you have <ulink url="http://www.cherrypy.org">CherryPy 3</ulink>
4644
installed. It probably <emphasis>won't</emphasis> work if you are still using
47-
CherryPy 2.</para>
45+
CherryPy 2. NOTE: If you are using Python 2.5.2+, you must install CherryPy 3.1.2+. The older
46+
version of CherryPy (3.1.0) only works pre-2.5.2.</para>
4847

4948
<para>Finally, after launching it, you should see a nice URL at the bottom: http://localhost:8080.
5049
Well, go ahead! Things should look good now!</para>

springpython/samples/springwiki/noxml.py

Lines changed: 126 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,143 @@
1616

1717
import controller
1818
import view
19-
from springpython.config import PythonConfig
20-
from springpython.config import Object
21-
from springpython.security.web import FilterChainProxy
19+
20+
from springpython.config import *
21+
from springpython.security.web import *
22+
from springpython.security.providers import *
23+
from springpython.security.providers.dao import *
24+
from springpython.security.userdetails import *
25+
from springpython.security.vote import *
2226

2327
class SpringWikiClientAndServer(PythonConfig):
2428
def __init__(self):
2529
super(SpringWikiClientAndServer, self).__init__()
2630

31+
@Object
32+
def controller(self):
33+
return controller.SpringWikiController()
34+
2735
@Object
2836
def read(self):
2937
wikiView = view.Springwiki()
3038
wikiView.controller = self.controller()
3139
return wikiView
3240

3341
@Object
34-
def controller(self):
35-
return controller.SpringWikiController()
36-
42+
def userDetailsService2(self):
43+
service = InMemoryUserDetailsService()
44+
service.user_dict = {"writer": ("comein", ["VET_ANY"], True)}
45+
return service
46+
47+
@Object
48+
def plainEncoder(self):
49+
return PlaintextPasswordEncoder()
50+
51+
@Object
52+
def plainAuthenticationProvider(self):
53+
provider = DaoAuthenticationProvider()
54+
provider.user_details_service = self.userDetailsService2()
55+
provider.password_encoder = self.plainEncoder()
56+
return provider
57+
58+
59+
@Object
60+
def authenticationManager(self):
61+
manager = AuthenticationManager()
62+
manager.auth_providers = [self.plainAuthenticationProvider()]
63+
return manager
64+
65+
@Object
66+
def authenticationProcessingFilter(self):
67+
filter = AuthenticationProcessingFilter()
68+
filter.auth_manager = self.authenticationManager()
69+
filter.alwaysReauthenticate = False
70+
return filter
71+
72+
@Object
73+
def cherrypySessionStrategy(self):
74+
return CP3SessionStrategy()
75+
76+
@Object
77+
def redirectStrategy(self):
78+
return CP3RedirectStrategy()
79+
80+
@Object
81+
def httpContextFilter(self):
82+
filter = HttpSessionContextIntegrationFilter()
83+
filter.sessionStrategy = self.cherrypySessionStrategy()
84+
return filter
85+
86+
@Object
87+
def authenticationProcessingFilterEntryPoint(self):
88+
filter_point = AuthenticationProcessingFilterEntryPoint()
89+
filter_point.loginFormUrl = "/login"
90+
filter_point.redirectStrategy = self.redirectStrategy()
91+
return filter_point
92+
@Object
93+
def accessDeniedHandler(self):
94+
handler = SimpleAccessDeniedHandler()
95+
handler.errorPage = "/accessDenied"
96+
handler.redirectStrategy = self.redirectStrategy()
97+
return handler
98+
99+
@Object
100+
def exceptionTranslationFilter(self):
101+
filter = ExceptionTranslationFilter()
102+
filter.authenticationEntryPoint = self.authenticationProcessingFilterEntryPoint()
103+
filter.accessDeniedHandler = self.accessDeniedHandler()
104+
return filter
105+
106+
@Object
107+
def filterSecurityInterceptor(self):
108+
interceptor = FilterSecurityInterceptor()
109+
interceptor.validate_config_attributes = False
110+
interceptor.auth_manager = self.authenticationManager()
111+
interceptor.access_decision_mgr = self.accessDecisionManager()
112+
interceptor.sessionStrategy = self.cherrypySessionStrategy()
113+
interceptor.obj_def_source = [("/.*", ["VET_ANY", "CUSTOMER_ANY"])]
114+
return interceptor
115+
116+
@Object
117+
def vetRoleVoter(self):
118+
voter = RoleVoter()
119+
voter.role_prefix = "VET"
120+
return voter
121+
122+
@Object
123+
def customerRoleVoter(self):
124+
voter = RoleVoter()
125+
voter.role_prefix = "CUSTOMER"
126+
return voter
127+
128+
@Object
129+
def accessDecisionManager(self):
130+
policy = AffirmativeBased()
131+
policy.allow_if_all_abstain = False
132+
policy.access_decision_voters = [self.vetRoleVoter(), self.customerRoleVoter()]
133+
return policy
134+
37135
@Object
38136
def filterChainProxy(self):
39-
proxy = FilterChainProxy()
40-
proxy.filterInvocationDefinitionSource = [("/.*", [])]
41-
return proxy
137+
proxy = CP3FilterChainProxy()
138+
proxy.filterInvocationDefinitionSource = [
139+
("/login.*",
140+
["httpContextFilter"]),
141+
("/.*",
142+
["httpContextFilter",
143+
"exceptionTranslationFilter",
144+
"authenticationProcessingFilter",
145+
"filterSecurityInterceptor"]
146+
)]
147+
return proxy
148+
149+
@Object
150+
def loginForm(self):
151+
form = view.CherryPyAuthenticationForm()
152+
form.filter = self.authenticationProcessingFilter()
153+
form.controller = self.controller()
154+
form.authenticationManager = self.authenticationManager()
155+
form.redirectStrategy = self.redirectStrategy()
156+
form.httpContextFilter = self.httpContextFilter()
157+
return form
158+

springpython/samples/springwiki/springwiki-noxml.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from springpython.config import PyContainerConfig
2222
from springpython.config import PythonConfig
2323
from springpython.context import ApplicationContext
24+
from springpython.security.context import SecurityContextHolder
2425

2526
port = 8003
2627

@@ -38,9 +39,15 @@
3839
logger.addHandler(ch)
3940

4041
applicationContext = ApplicationContext(noxml.SpringWikiClientAndServer())
42+
filterChainProxy = applicationContext.get_object("filterChainProxy")
43+
44+
SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)
45+
SecurityContextHolder.getContext()
4146

4247
# Use a configuration file for server-specific settings.
43-
conf = {"/": {"tools.staticdir.root": os.getcwd()},
48+
conf = {"/": {"tools.staticdir.root": os.getcwd(),
49+
"tools.sessions.on": True,
50+
"tools.filterChainProxy.on": True},
4451
"/images": {"tools.staticdir.on": True,
4552
"tools.staticdir.dir": "images"},
4653
"/html": {"tools.staticdir.on": True,
@@ -68,8 +75,11 @@
6875
}
6976

7077
cherrypy.config.update({'server.socket_port': port})
71-
72-
cherrypy.tree.mount(applicationContext.get_object(name = "read"), '/', config=conf)
78+
79+
app = applicationContext.get_object(name = "read")
80+
app.login = applicationContext.get_object(name = "loginForm")
81+
82+
cherrypy.tree.mount(app, '/', config=conf)
7383

7484
cherrypy.engine.start()
7585
cherrypy.engine.block()

springpython/samples/springwiki/view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def index(self, fromPage="/", login="", password="", errorMsg=""):
131131
def logout(self):
132132
"""Replaces current authentication token, with an empty, non-authenticated one."""
133133
self.filter.logout()
134+
self.httpContextFilter.saveContext()
134135
raise cherrypy.HTTPRedirect("/")
135136

136137
def attemptAuthentication(self, username, password):
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Copyright 2006-2008 SpringSource (http://springsource.com), All Rights Reserved
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
"""
16+
17+
# JMS constants
18+
19+
DELIVERY_MODE_NON_PERSISTENT = 1
20+
DELIVERY_MODE_PERSISTENT = 2
21+
22+
RECEIVE_TIMEOUT_INDEFINITE_WAIT = 0
23+
RECEIVE_TIMEOUT_NO_WAIT = -1
24+
25+
DEFAULT_DELIVERY_MODE = DELIVERY_MODE_PERSISTENT
26+
DEFAULT_TIME_TO_LIVE = 0
27+
28+
class JMSException(Exception):
29+
""" Base class for all JMS-related exceptions.
30+
"""
31+
32+
class NoMessageAvailableException(JMSException):
33+
""" Raised when the jms_template's call to receive returned no message
34+
in the expected wait interval.
35+
"""
36+
37+
class WebSphereMQJMSException(JMSException):
38+
""" Class for exceptions related to WebSphereMQ only.
39+
"""
40+
def __init__(self, message=None, completion_code=None, reason_code=None):
41+
JMSException.__init__(self, message)
42+
self.message = message
43+
self.completion_code = completion_code
44+
self.reason_code = reason_code

0 commit comments

Comments
 (0)