01: /*
02: * Copyright 2007 The Kuali Foundation
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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: package org.kuali.bus.security.jms;
17:
18: import javax.jms.JMSException;
19: import javax.jms.Message;
20:
21: import org.acegisecurity.Authentication;
22: import org.acegisecurity.context.SecurityContext;
23: import org.acegisecurity.context.SecurityContextHolder;
24: import org.acegisecurity.context.SecurityContextImpl;
25: import org.logicblaze.lingo.jms.JmsServiceExporter;
26:
27: /**
28: * Extension to the JmsServiceExporter that attempts to retrieve an
29: * {@link Authentication} object from
30: * {@link AuthenticationJmsProxyFactoryBean#CONST_KUALI_JMS_AUTHENTICATION} and
31: * place it in an Acegi {@link SecurityContext}.
32: *
33: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
34: * @version $Revision: 1.2.16.1.6.1 $ $Date: 2007/10/17 20:32:06 $
35: * @since 0.9
36: *
37: */
38: public class AuthenticatedJmsServiceExporter extends JmsServiceExporter {
39:
40: public void onMessage(final Message message) {
41:
42: try {
43: final Authentication authentication = (Authentication) message
44: .getObjectProperty(AuthenticationJmsProxyFactoryBean.CONST_KUALI_JMS_AUTHENTICATION);
45: if (authentication != null) {
46: final SecurityContextImpl impl = new SecurityContextImpl();
47: impl.setAuthentication(authentication);
48: authentication.setAuthenticated(false);
49: SecurityContextHolder.setContext(impl);
50: }
51: super .onMessage(message);
52:
53: } catch (final JMSException e) {
54: logger.error(e, e);
55: } finally {
56: SecurityContextHolder.clearContext();
57: }
58: }
59: }
|