Package org.jboss.security.client

Examples of org.jboss.security.client.SecurityClient


         {
            log.debug("Invoking create() failed by an unexpected reason:", e);
            fail("Unexpected exception");
         }
      }
      SecurityClient client = SecurityClientFactory.getSecurityClient();
      client.setSimple("scott", "echoman");
      client.login();
      try
      {
         bean = home.create();
         bean.echo("hi");
      }
View Full Code Here


{
   public static void main(String args[]) throws Exception
   {
      Context ctx = new InitialContext();
      CompleteXMLDD completeXMLDDBean = (CompleteXMLDD) ctx.lookup("CompleteXMLDD/remote");
      SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
      securityClient.setSimple("jai", "jai123");
      securityClient.login();
     
      System.out.println("jai is a normal user");
      // call sayHello
      System.out.println(completeXMLDDBean.sayHello("jai"));

      // call greet methods
      System.out.println(completeXMLDDBean.greetWithNotSupportedTransaction("jai"));
      System.out.println(completeXMLDDBean.greetWithRequiredTransaction("jai"));

      // bye
      System.out.println(completeXMLDDBean.sayBye("jai"));

      // let's try the uncallable method
      System.out.println("We'll try calling an uncallable method");
      try
      {
         completeXMLDDBean.uncallableMethod();
         throw new RuntimeException("Bean method in <excluded-list> was allowed to be invoked");
      }
      catch (EJBAccessException e)
      {
         System.out.println("Caught expected exception : " + e.getMessage());
      }
      securityClient.logout();
     
      // let's login with other user
      securityClient.setSimple("bill", "bill123");
      securityClient.login();
      System.out.println("bill is an admin");
      // Now work on the other bean
      PartialXMLDD partialXMLDDBean = (PartialXMLDD) ctx.lookup("PartialXMLDD/remote");
      System.out.println("Sending Hello World message to bean. We expect the bean to change it");
      System.out.println(partialXMLDDBean.changeMessage("Hello world"));
View Full Code Here

   }

   private static void testShoppingCart() throws Exception
   {
      // Establish the proxy with an incorrect security identity
      SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
      securityClient.setSimple("bill", "incorrectpassword");
      securityClient.login();
     
      Context ctx = new InitialContext();
      ShoppingCart cart = (ShoppingCart) ctx.lookup("ShoppingCart");

      System.out.println("Attempting to buy 1 memory stick with incorrect password");
      try
      {
         cart.buy("Memory stick", 1);
         throw new RuntimeException("ERROR - User with incorrect password was able to access the bean");
      }
      catch (javax.ejb.EJBAccessException e)
      {
         System.out.println("Caught javax.ejb.EJBAccessException as expected");
      }

      System.out.println("Setting user/password");
      securityClient.logout();
     
      securityClient.setSimple("bill", "password-test");
      securityClient.login();

      System.out.println("bill is a shopper, so is allowed to buy");
      System.out.println("Buying 1 memory stick");
      cart.buy("Memory stick", 1);
      System.out.println("Buying another memory stick");
      cart.buy("Memory stick", 1);

      System.out.println("Buying a laptop");
      cart.buy("Laptop", 1);

      System.out.println("Print cart:");
      HashMap<String, Integer> fullCart = cart.getCartContents();
      for (String product : fullCart.keySet())
      {
         System.out.println(fullCart.get(product) + "     " + product);
      }

      System.out.println("bill is not a clerk, so is not allowed to price check");
      try
      {
         cart.priceCheck("Laptop");
         throw new RuntimeException("ERROR - User with insufficient access rights allowed to access bean method");
      }
      catch (javax.ejb.EJBAccessException ex)
      {
         System.out.println("Caught EJBAccessException as expected");
      }

      System.out.println("Checkout");
      cart.checkout();

      System.out.println("Should throw an object not found exception by invoking on cart after @Remove method");
      try
      {
         cart.getCartContents();
         throw new RuntimeException("ERROR - Bean not discarded");
      }
      catch (NoSuchEJBException e)
      {
         System.out.println("Successfully caught no such object exception.");
      }
     
      // logout the user
      securityClient.logout();
   }
View Full Code Here

   private static void testStateless() throws Exception
   {
      InitialContext jndiContext = new InitialContext();
      StatelessTest stateless = (StatelessTest) jndiContext.lookup("StatelessTest");

      SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
      securityClient.setSimple("bill2", "invalidpassword");
      securityClient.login();
     
      try
      {
         stateless.testSecurity();
         throw new RuntimeException("ERROR - User with incorrect password accessed the bean");
      }
      catch (javax.ejb.EJBAccessException e)
      {
         System.out.println("Caught javax.ejb.EJBAccessException, for SLSB, as expected");
      }

      // logout and login back with correct credentials
      System.out.println("Now passing the correct user/password to access the SLSB");
      securityClient.logout();
      securityClient.setSimple("bill2", "password-default");
      securityClient.login();
     
      // call the bean method
      stateless.testSecurity();

      System.out.println("Successfully accessed SLSB");
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testAuthz() throws Exception {
        SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
        securityClient.setSimple("jduke", "theduke");
        try {
            securityClient.login();
            assertEquals(HelloBean.HELLO_WORLD, hello.sayHelloWorld());
        } finally {
            securityClient.logout();
        }
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testNotAuthz() throws Exception {
        SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
        securityClient.setSimple("JohnDoe", "jdoe");
        try {
            securityClient.login();
            hello.sayHelloWorld();
            fail("Access to sayHelloWorld() should be denied for JohnDoe.");
        } catch (EJBAccessException e) {
            //OK - expected
        } finally {
            securityClient.logout();
        }
    }
View Full Code Here

            hello.sayHelloWorld();
            fail("Access to sayHello() should be denied if not authenticated.");
        } catch (EJBAccessException e) {
            //OK
        }
        SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
        securityClient.setSimple("jduke", "theduke");
        try {
            securityClient.login();
            assertEquals(HelloBean.HELLO_WORLD, hello.sayHelloWorld());
        } finally {
            securityClient.logout();
        }
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testInvocationOnSecuredMethodWithCorrectRole() throws Exception {
        final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
        final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
        securityClient.setSimple("user1", "password1");
        try {
            // login
            securityClient.login();
            // expects role1, so should succeed
            securedSingleton.allowedForRole1();
        } finally {
            securityClient.logout();
        }

    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testInvocationOnSecuredMethodWithInCorrectRole() throws Exception {
        final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
        final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
        securityClient.setSimple("user2", "password2");
        try {
            // login
            securityClient.login();
            try {
                // expects role1, so should fail
                securedSingleton.allowedForRole1();
                Assert.fail("Call to secured method, with incorrect role, was expected to fail");
            } catch (EJBAccessException ejbae) {
                // expected
            }
        } finally {
            securityClient.logout();
        }

    }
View Full Code Here

    @EJB(lookup = "java:global/ejb3-servlet-ejbs/StatelessBean!org.jboss.as.test.integration.ejb.servlet.StatelessLocal")
    StatelessLocal injectedStateless;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        SecurityClient client = null;
        try {
            InitialContext ctx = new InitialContext();

            client = SecurityClientFactory.getSecurityClient();
            client.setSimple("user1", "password1");
            client.login();

            injectedSession.hello();
            injectedSession.goodbye();

            injectedStateless.hello();
            injectedStateless.goodbye();

            String lookupString = "java:global/ejb3-servlet-ejbs/Session30!";
            EJBServletHelper test = new EJBServletHelper();
            test.processRequest(lookupString, ctx);
        } catch (Exception e) {
            log.error(e);
            throw new ServletException("Failed to call EJBs/Session30 through remote and local interfaces", e);
        } finally {
            client.logout();
        }
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        out.print("EJBServlet OK");
        out.close();
View Full Code Here

TOP

Related Classes of org.jboss.security.client.SecurityClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.