Package org.jboss.security.authorization.modules.ejb

Examples of org.jboss.security.authorization.modules.ejb.EJBPolicyModuleDelegate


   /**
    * Test a successful authorization case
    */
   public void testEJBAuthorizationPass()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
      
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>();
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );
     
      assertEquals(AuthorizationContext.PERMIT,epmd.authorize(resource,
            new Subject(),
            getRoleGroup(new String[]{"gooduser", "validuser" })) );
   }
View Full Code Here


   /**
    * Test an unsuccessful authorization case
    */
   public void testEJBAuthorizationFail()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>()
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );
     
      int res = epmd.authorize(resource, new Subject(), getRoleGroup(new String[]{"baduser"}));
     
      assertEquals(AuthorizationContext.DENY, res);
   }
View Full Code Here

   /**
    * Test the Unchecked method permissions
    */
   public void testEJBAuthorizationUnchecked()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>()
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {AnybodyPrincipal.ANYBODY}) );
     
      int res = epmd.authorize(resource, new Subject(), getRoleGroup(new String[]{"baduser"}));
      assertEquals(AuthorizationContext.PERMIT, res);
   }
View Full Code Here

   /**
    * Test that in the absence of method roles sent, the authorization fails
    */
   public void testEJBAuthorizationMissingMethodRoles()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
    
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>()
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
     
      int res = epmd.authorize(resource, new Subject(), getRoleGroup(new String[]{"baduser"}));
      assertEquals(AuthorizationContext.DENY, res);
   }
View Full Code Here

   /**
    * Test EJBContext.isCallerInRole (Success Case)
    */
   public void testIsCallerInRoleValid()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>();
     
      cmap.put(ResourceKeys.ROLEREF_PERM_CHECK, true);
      cmap.put(ResourceKeys.ROLENAME, "employee");
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );

      Set<SecurityRoleRef> roleRefSet = new HashSet<SecurityRoleRef>();
      roleRefSet.add(new SecurityRoleRef("employee", "gooduser"));
      resource.setSecurityRoleReferences(roleRefSet);
     
      int result = epmd.authorize(resource,
            new Subject(),
            getRoleGroup(new String[]{"gooduser", "validuser" }));
     
      assertEquals(AuthorizationContext.PERMIT, result);
   }
View Full Code Here

   /**
    * Test EJBContext.isCallerInRole (Failure Case)
    */
   public void testIsCallerInRoleInvalid()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>();
     
      cmap.put(ResourceKeys.ROLEREF_PERM_CHECK, true);
      cmap.put(ResourceKeys.ROLENAME, "employee");
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );

      Set<SecurityRoleRef> roleRefSet = new HashSet<SecurityRoleRef>();
      roleRefSet.add(new SecurityRoleRef("employee", "baduser")); //Bad user
      resource.setSecurityRoleReferences(roleRefSet);
     
      int result = epmd.authorize(resource,
            new Subject(),
            getRoleGroup(new String[]{"gooduser", "validuser" }));
     
      assertEquals(AuthorizationContext.DENY, result);
   }
View Full Code Here

   /**
    * Test EJB 1.1 EJBContext.isCallerInRole case
    */
   public void testIsCallerInRoleValidEJB11()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>();
     
      cmap.put(ResourceKeys.ROLEREF_PERM_CHECK, true);
      cmap.put(ResourceKeys.ROLENAME, "employee");
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );
      resource.setEnforceEJBRestrictions(true); //Enforce EJB 1.1

      Set<SecurityRoleRef> roleRefSet = new HashSet<SecurityRoleRef>();
      roleRefSet.add(new SecurityRoleRef("employee", "gooduser"))
      resource.setSecurityRoleReferences(roleRefSet);

      int result = epmd.authorize(resource,
            new Subject(),
            getRoleGroup(new String[]{"gooduser", "validuser" }));
      assertEquals(AuthorizationContext.PERMIT, result);
   }
View Full Code Here

   /**
    * Test EJB 1.1 EJBContext.isCallerInRole case
    */
   public void testIsCallerInRoleInvalidEJB11()
   {
      EJBPolicyModuleDelegate epmd = new EJBPolicyModuleDelegate();
     
      //Create a context map
      Map<String,Object> cmap = new HashMap<String,Object>();
     
      cmap.put(ResourceKeys.ROLEREF_PERM_CHECK, true);
      cmap.put(ResourceKeys.ROLENAME, "impostor");
     
      EJBResource resource = new EJBResource(cmap);
      resource.setPrincipal(new SimplePrincipal("AuthenticatedPrincipal"));
      resource.setEjbMethod(DummyClass.class.getDeclaredMethods()[0]);
      resource.setEjbName(DummyClass.class.getCanonicalName());
      resource.setEjbMethodRoles( getRoleGroup(new String[] {"gooduser"}) );
      resource.setEnforceEJBRestrictions(true); //Enforce EJB 1.1

      Set<SecurityRoleRef> roleRefSet = new HashSet<SecurityRoleRef>();
      roleRefSet.add(new SecurityRoleRef("employee", "baduser")); //Bad user
      resource.setSecurityRoleReferences(roleRefSet);
     
      try
      {
          epmd.authorize(resource,
               new Subject(),
               getRoleGroup(new String[]{"gooduser", "validuser" }));
          fail("Should have thrown a RuntimeException due to ejb 1.1 restrictions");
      }
      catch(RuntimeException e)
View Full Code Here

TOP

Related Classes of org.jboss.security.authorization.modules.ejb.EJBPolicyModuleDelegate

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.