01: /**
02: *
03: * Licensed to the Apache Software Foundation (ASF) under one or more
04: * contributor license agreements. See the NOTICE file distributed with
05: * this work for additional information regarding copyright ownership.
06: * The ASF licenses this file to You under the Apache License, Version 2.0
07: * (the "License"); you may not use this file except in compliance with
08: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package org.apache.openejb.tomcat.catalina;
18:
19: import org.apache.catalina.connector.Request;
20: import org.apache.catalina.connector.Response;
21: import org.apache.catalina.valves.ValveBase;
22: import org.apache.openejb.loader.SystemInstance;
23: import org.apache.openejb.spi.SecurityService;
24: import org.apache.openejb.util.OpenEjbVersion;
25:
26: import javax.servlet.ServletException;
27: import java.io.IOException;
28:
29: public class OpenEJBValve extends ValveBase {
30: protected TomcatSecurityService securityService;
31:
32: public OpenEJBValve() {
33: info = getClass().getName() + "/"
34: + OpenEjbVersion.get().getVersion();
35: securityService = getSecurityService();
36: }
37:
38: public void invoke(Request request, Response response)
39: throws IOException, ServletException {
40: Object oldState = null;
41: if (securityService != null && request.getWrapper() != null) {
42: oldState = securityService.enterWebApp(request.getWrapper()
43: .getRealm(), request.getUserPrincipal(), request
44: .getWrapper().getRunAs());
45: }
46:
47: try {
48: getNext().invoke(request, response);
49: } finally {
50: if (securityService != null) {
51: securityService.exitWebApp(oldState);
52: }
53: }
54: }
55:
56: private TomcatSecurityService getSecurityService() {
57: SecurityService securityService = SystemInstance.get()
58: .getComponent(SecurityService.class);
59: if (securityService instanceof TomcatSecurityService) {
60: return (TomcatSecurityService) securityService;
61: }
62: return null;
63: }
64: }
|