Search in sources :

Example 11 with EJBAccessException

use of jakarta.ejb.EJBAccessException in project tomee by apache.

the class SecureServlet method doGet.

protected void doGet(final HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/plain");
    final ServletOutputStream out = response.getOutputStream();
    out.println("Servlet");
    Principal principal = request.getUserPrincipal();
    if (principal != null) {
        out.println("Servlet.getUserPrincipal()=" + principal + " [" + principal.getName() + "]");
    } else {
        out.println("Servlet.getUserPrincipal()=<null>");
    }
    out.println("Servlet.isCallerInRole(\"user\")=" + request.isUserInRole("user"));
    out.println("Servlet.isCallerInRole(\"manager\")=" + request.isUserInRole("manager"));
    out.println("Servlet.isCallerInRole(\"fake\")=" + request.isUserInRole("fake"));
    out.println();
    out.println("@EJB=" + secureEJBLocal);
    if (secureEJBLocal != null) {
        principal = secureEJBLocal.getCallerPrincipal();
        if (principal != null) {
            out.println("@EJB.getCallerPrincipal()=" + principal + " [" + principal.getName() + "]");
        } else {
            out.println("@EJB.getCallerPrincipal()=<null>");
        }
        out.println("@EJB.isCallerInRole(\"user\")=" + secureEJBLocal.isCallerInRole("user"));
        out.println("@EJB.isCallerInRole(\"manager\")=" + secureEJBLocal.isCallerInRole("manager"));
        out.println("@EJB.isCallerInRole(\"fake\")=" + secureEJBLocal.isCallerInRole("fake"));
        try {
            secureEJBLocal.allowUserMethod();
            out.println("@EJB.allowUserMethod() ALLOWED");
        } catch (EJBAccessException e) {
            out.println("@EJB.allowUserMethod() DENIED");
        }
        try {
            secureEJBLocal.allowManagerMethod();
            out.println("@EJB.allowManagerMethod() ALLOWED");
        } catch (EJBAccessException e) {
            out.println("@EJB.allowManagerMethod() DENIED");
        }
        try {
            secureEJBLocal.allowFakeMethod();
            out.println("@EJB.allowFakeMethod() ALLOWED");
        } catch (final EJBAccessException e) {
            out.println("@EJB.allowFakeMethod() DENIED");
        }
        try {
            secureEJBLocal.denyAllMethod();
            out.println("@EJB.denyAllMethod() ALLOWED");
        } catch (EJBAccessException e) {
            out.println("@EJB.denyAllMethod() DENIED");
        }
    }
    out.println();
}
Also used : ServletOutputStream(jakarta.servlet.ServletOutputStream) Principal(java.security.Principal) EJBAccessException(jakarta.ejb.EJBAccessException)

Aggregations

EJBAccessException (jakarta.ejb.EJBAccessException)11 OpenEJBException (org.apache.openejb.OpenEJBException)5 ApplicationException (org.apache.openejb.ApplicationException)4 EJBHome (jakarta.ejb.EJBHome)3 EJBLocalHome (jakarta.ejb.EJBLocalHome)3 EJBLocalObject (jakarta.ejb.EJBLocalObject)3 EJBObject (jakarta.ejb.EJBObject)3 Method (java.lang.reflect.Method)3 BeanContext (org.apache.openejb.BeanContext)3 ThreadContext (org.apache.openejb.core.ThreadContext)3 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)3 AccessLocalException (jakarta.ejb.AccessLocalException)2 ServletOutputStream (jakarta.servlet.ServletOutputStream)2 AccessException (java.rmi.AccessException)2 RemoteException (java.rmi.RemoteException)2 Principal (java.security.Principal)2 InitialContext (javax.naming.InitialContext)2 InvalidateReferenceException (org.apache.openejb.InvalidateReferenceException)2 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)2 SystemException (org.apache.openejb.SystemException)2