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: */package org.apache.cxf.jaxws.context;
19:
20: import java.security.Principal;
21:
22: import javax.xml.ws.WebServiceContext;
23: import javax.xml.ws.handler.MessageContext;
24:
25: import org.apache.cxf.security.SecurityContext;
26:
27: public class WebServiceContextImpl implements WebServiceContext {
28:
29: private static ThreadLocal<MessageContext> context = new ThreadLocal<MessageContext>();
30:
31: public WebServiceContextImpl() {
32: }
33:
34: public WebServiceContextImpl(MessageContext ctx) {
35: setMessageContext(ctx);
36: }
37:
38: // Implementation of javax.xml.ws.WebServiceContext
39:
40: public final MessageContext getMessageContext() {
41: return context.get();
42: }
43:
44: public final Principal getUserPrincipal() {
45: SecurityContext ctx = (SecurityContext) getMessageContext()
46: .get(SecurityContext.class.getName());
47: if (ctx == null) {
48: return null;
49: }
50: return ctx.getUserPrincipal();
51: }
52:
53: public final boolean isUserInRole(final String role) {
54: SecurityContext ctx = (SecurityContext) getMessageContext()
55: .get(SecurityContext.class.getName());
56: if (ctx == null) {
57: return false;
58: }
59: return ctx.isUserInRole(role);
60: }
61:
62: // TODO JAX-WS 2.1
63: /*
64: public EndpointReference getEndpointReference(Element... referenceParameters) {
65: // TODO
66: throw new UnsupportedOperationException();
67: }
68:
69: public <T extends EndpointReference> T getEndpointReference(Class<T> clazz,
70: Element... referenceParameters) {
71: // TODO
72: throw new UnsupportedOperationException();
73: }
74: */
75:
76: public static void setMessageContext(MessageContext ctx) {
77: //ContextPropertiesMapping.mapCxf2Jaxws(ctx);
78: context.set(ctx);
79: }
80:
81: public static void clear() {
82: context.set(null);
83: }
84:
85: }
|