01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.itest;
17:
18: import java.io.IOException;
19: import java.io.PrintWriter;
20: import java.rmi.AccessException;
21: import java.rmi.RemoteException;
22:
23: import javax.ejb.CreateException;
24: import javax.naming.InitialContext;
25: import javax.naming.NamingException;
26: import javax.servlet.ServletException;
27: import javax.servlet.ServletOutputStream;
28: import javax.servlet.http.HttpServlet;
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.http.HttpServletResponse;
31:
32: /**
33: * @version $Rev: 579469 $ $Date: 2007-09-25 21:37:21 -0700 (Tue, 25 Sep 2007) $
34: */
35: public class TestServlet extends HttpServlet {
36:
37: public void init() {
38: System.out.println("Test Servlet init");
39: }
40:
41: protected void service(HttpServletRequest httpServletRequest,
42: HttpServletResponse httpServletResponse)
43: throws ServletException, IOException {
44: PrintWriter out = httpServletResponse.getWriter();
45: out.println("TestServlet principal: "
46: + httpServletRequest.getUserPrincipal().getName());
47: try {
48: InitialContext ctx = new InitialContext();
49:
50: //test ejb access using geronimo plan refs
51: TestSessionHome home = (TestSessionHome) ctx
52: .lookup("java:comp/env/TestSession");
53: TestSession session = home.create();
54: String principalName = session.testAccess();
55: out.println("Test EJB principal: " + principalName);
56: try {
57: String bad = session.testNoAccess();
58: out
59: .println("NoAccess method call succeeded with principal: "
60: + bad);
61: } catch (AccessException e) {
62: out
63: .println("Correctly received security exception on noAccess method");
64: }
65:
66: } catch (NamingException e) {
67: System.out.print("Exception:");
68: e.printStackTrace();
69: } catch (RemoteException e) {
70: e.printStackTrace();
71: } catch (CreateException e) {
72: e.printStackTrace();
73: }
74: out.flush();
75: }
76:
77: }
|