KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webservice > axis > TicketCallbackSpringHandler


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webservice.axis;
18
19 import javax.servlet.ServletContext JavaDoc;
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21
22 import org.apache.axis.AxisFault;
23 import org.apache.axis.MessageContext;
24 import org.apache.axis.handlers.BasicHandler;
25 import org.apache.axis.transport.http.HTTPConstants;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.apache.ws.security.handler.WSHandlerConstants;
29 import org.springframework.web.context.WebApplicationContext;
30 import org.springframework.web.context.support.WebApplicationContextUtils;
31
32 /**
33  * Axis handler that retrieves the TicketCallbackHandler instance from
34  * a Spring context. The authentication service is injected by Spring
35  * so that when it gets called by the WSS4J handler it can verify the
36  * ticket passed to the service.
37  * The callback handler is then added to the MessageContext under the standard
38  * WsHandlerConstants.PW_CALLBACK_REF property.
39  *
40  * @author gavinc
41  */

42 public class TicketCallbackSpringHandler extends BasicHandler
43 {
44    private static final Log logger = LogFactory.getLog(TicketCallbackSpringHandler.class);
45    private static final String JavaDoc BEAN_NAME = "ticketCallbackHandler";
46    private static final long serialVersionUID = -135125831180499667L;
47
48    /**
49     * @see org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)
50     */

51    public void invoke(MessageContext msgContext) throws AxisFault
52    {
53       // get hold of the Spring context and retrieve the AuthenticationService
54
HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
55       ServletContext JavaDoc servletCtx = req.getSession().getServletContext();
56       WebApplicationContext webAppCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletCtx);
57       TicketCallbackHandler callback = (TicketCallbackHandler)webAppCtx.getBean(BEAN_NAME);
58       
59       // store the callback in the context where the WS-Security handler can pick it up from
60
msgContext.setProperty(WSHandlerConstants.PW_CALLBACK_REF, callback);
61    }
62 }
63
Popular Tags