예제 #1
0
 @Test
 public void testOnlyRole1() {
   try {
     entryBean.callOnlyRole1();
     fail("Expected EJBAccessException");
   } catch (EJBAccessException e) {
     // good
   }
 }
예제 #2
0
 @Test
 public void testAuthentication_TwoBeans() throws Exception {
   LoginContext lc = Util.getCLMLoginContext("user1", "password1");
   lc.login();
   try {
     String[] response = entryBean.doubleWhoAmI();
     assertEquals("user1", response[0]);
     assertEquals(
         "anonymous",
         response[
             1]); // Unless a run-as-principal configuration has been done, you cannot expect a
                  // principal
   } finally {
     lc.logout();
   }
 }
예제 #3
0
  @Test
  public void testRunAsICIR_TwoBeans() throws Exception {
    LoginContext lc = Util.getCLMLoginContext("user1", "password1");
    lc.login();
    try {
      // TODO - Enable once auth checks are working.
      /*
       * try { whoAmIBean.getCallerPrincipal(); fail("Expected call to whoAmIBean to fail"); } catch (Exception expected)
       * { }
       */

      boolean[] response;
      response = entryBean.doubleDoIHaveRole("Users");
      assertTrue(response[0]);
      assertFalse(response[1]);

      response = entryBean.doubleDoIHaveRole("Role1");
      assertTrue(response[0]);
      assertFalse(response[1]);

      response = entryBean.doubleDoIHaveRole("Role2");
      assertFalse(response[0]);
      assertTrue(response[1]);
    } finally {
      lc.logout();
    }

    lc = Util.getCLMLoginContext("user2", "password2");
    lc.login();
    try {
      // Verify the call now passes.
      Principal user = whoAmIBean.getCallerPrincipal();
      assertNotNull(user);

      boolean[] response;
      response = entryBean.doubleDoIHaveRole("Users");
      assertTrue(response[0]);
      assertFalse(response[1]);

      response = entryBean.doubleDoIHaveRole("Role1");
      assertFalse(response[0]);
      assertFalse(response[1]);

      response = entryBean.doubleDoIHaveRole("Role2");
      assertTrue(response[0]);
      assertTrue(response[1]);
    } finally {
      lc.logout();
    }
  }