Package: OpenEjbSecurityInitializationValve

OpenEjbSecurityInitializationValve

nameinstructionbranchcomplexitylinemethod
OpenEjbSecurityInitializationValve()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getSecurityService()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
invoke(Request, Response)
M: 34 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2012 SAP AG
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * SAP AG - initial contribution
10: *******************************************************************************/
11:
12: package org.eclipse.virgo.web.enterprise.security.valve;
13:
14: import java.io.IOException;
15:
16: import javax.servlet.ServletException;
17:
18: import org.apache.catalina.Wrapper;
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.Assembler;
24: import org.eclipse.virgo.web.enterprise.security.StandardSecurityService;
25:
26: public class OpenEjbSecurityInitializationValve extends ValveBase {
27:
28: private StandardSecurityService securityService;
29:
30: public OpenEjbSecurityInitializationValve() {
31: super(true);
32: }
33:
34: @Override
35: public void invoke(Request request, Response response) throws IOException, ServletException {
36: Object oldState = null;
37: Wrapper wrapper = (Wrapper) request.getMappingData().wrapper;
38:
39:• if (getSecurityService() != null && wrapper != null) {
40: oldState = this.securityService.enterWebApp(wrapper, request.getPrincipal(), wrapper.getRunAs());
41: }
42:
43: try {
44: getNext().invoke(request, response);
45: } finally {
46:• if (this.securityService != null) {
47: this.securityService.exitWebApp(oldState);
48: }
49: }
50:
51: }
52:
53: private StandardSecurityService getSecurityService() {
54:• if (this.securityService == null) {
55: Assembler assembler = SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
56: this.securityService = (StandardSecurityService) assembler.getSecurityService();
57: }
58: return this.securityService;
59: }
60:
61: }