01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.context;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23:
24: import javax.servlet.http.HttpServletRequest;
25: import javax.xml.ws.WebServiceContext;
26: import javax.xml.ws.handler.MessageContext;
27: import java.security.Principal;
28:
29: public class WebServiceContextImpl implements WebServiceContext {
30:
31: private static final Log log = LogFactory
32: .getLog(WebServiceContext.class);
33:
34: private MessageContext soapMessageContext;
35:
36: public WebServiceContextImpl() {
37: super ();
38: }
39:
40: /* (non-Javadoc)
41: * @see javax.xml.ws.WebServiceContext#getMessageContext()
42: */
43: public MessageContext getMessageContext() {
44: return soapMessageContext;
45: }
46:
47: /* (non-Javadoc)
48: * @see javax.xml.ws.WebServiceContext#getUserPrincipal()
49: */
50: public Principal getUserPrincipal() {
51: if (soapMessageContext != null) {
52: HttpServletRequest request = (HttpServletRequest) soapMessageContext
53: .get(MessageContext.SERVLET_REQUEST);
54: if (request != null) {
55: if (log.isDebugEnabled()) {
56: log
57: .debug("Access to the user Principal was requested.");
58: }
59: return request.getUserPrincipal();
60: } else {
61: if (log.isDebugEnabled()) {
62: log
63: .debug("No HttpServletRequest object was found, so no Principal can be found.");
64: }
65: }
66: }
67:
68: return null;
69: }
70:
71: /* (non-Javadoc)
72: * @see javax.xml.ws.WebServiceContext#isUserInRole(java.lang.String)
73: */
74: public boolean isUserInRole(String user) {
75: if (soapMessageContext != null) {
76: HttpServletRequest request = (HttpServletRequest) soapMessageContext
77: .get(MessageContext.SERVLET_REQUEST);
78: if (request != null) {
79: if (log.isDebugEnabled()) {
80: log
81: .debug("Checking to see if the user in the role.");
82: }
83: return request.isUserInRole(user);
84: } else {
85: if (log.isDebugEnabled()) {
86: log
87: .debug("No HttpServletRequest object was found, so no role check can be performed.");
88: }
89: }
90: }
91:
92: return false;
93: }
94:
95: public void setSoapMessageContext(MessageContext soapMessageContext) {
96: this.soapMessageContext = soapMessageContext;
97: }
98:
99: }
|