View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
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   */
17  package org.jboss.as.quickstarts.ejb_security_interceptors;
18  
19  import static org.jboss.as.quickstarts.ejb_security_interceptors.EJBUtil.lookupSecuredEJB;
20  
21  import javax.annotation.security.PermitAll;
22  import javax.ejb.Remote;
23  import javax.ejb.Stateless;
24  
25  import org.jboss.ejb3.annotation.SecurityDomain;
26  
27  /**
28   * An EJB for testing EJB to remote EJB calls.
29   * 
30   * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
31   */
32  @Stateless
33  @Remote(IntermediateEJBRemote.class)
34  @SecurityDomain("quickstart-domain")
35  @PermitAll
36  public class IntermediateEJB implements IntermediateEJBRemote {
37  
38      public String makeTestCalls() {
39          try {
40              StringBuilder sb = new StringBuilder("* * IntermediateEJB - Begin Testing * * \n");
41              SecuredEJBRemote remote = lookupSecuredEJB();
42  
43              sb.append("SecuredEJBRemote.getSecurityInformation()=").append(remote.getSecurityInformation()).append("\n");
44  
45              try {
46                  sb.append("Can call roleOneMethod=");
47                  remote.roleOneMethod();
48                  sb.append("true\n");
49              } catch (Exception e) {
50                  sb.append("false\n");
51              }
52  
53              try {
54                  sb.append("Can call roleTwoMethod=");
55                  remote.roleTwoMethod();
56                  sb.append("true\n");
57              } catch (Exception e) {
58                  sb.append("false\n");
59              }
60  
61              sb.append("* * IntermediateEJB - End Testing * * ");
62              return sb.toString();
63          } catch (Exception e) {
64              if (e instanceof RuntimeException) {
65                  throw (RuntimeException) e;
66              }
67              throw new RuntimeException("Teasting failed.", e);
68          }
69      }
70  
71  }