[Yanel-dev] Problems with new security api

Josias Thöny josias.thoeny at wyona.com
Wed Feb 21 19:56:30 CET 2007


Hi Paloma,

Paloma Gomez wrote:
> Hi all,
> 
> I have some problems with the new security api. I am unable to retrieve 
> the groups a user belongs to: I always receive an empty array.

It was a silly bug in YarepGroup.java. It should be fixed now.
Thanks for reporting the bug and providing a testcase. I added your 
testcase to the test class.

josias

> 
> I have extended the tests to see what's happening:
> 
> ---------------------------------------------------------------------------------------------------------- 
> 
> public void testGetUserGroups() throws Exception {
>    String userID = "lenya";
>    String groupID = "editors";
>    User user = identityManager.getUserManager().getUser(userID);
>    assertNotNull(user);      //Group group = 
> identityManager.getGroupManager().getGroup(groupID);
>     //assertTrue(group.isMember(user));
>     Group[] userGroups = user.getGroups();
>     assertEquals(1,userGroups.length);
>     assertEquals(groupID , userGroups[0].getID());
> }
> --------------------------------------------------------------------------------------------------------- 
> 
> 
> The test fails:
> -------------------------------------------------------------------------------------- 
> 
> [junit] Testcase: testGetUserGroups took 0,04 sec
> [junit]     FAILED
> [junit] expected:<1> but was:<0>
> ---------------------------------------------------------------------------------------- 
> 
> 
> If I uncomment the lines above I get:
> 
> -------------------------------------------------------------------------------------- 
> 
> [junit] Testcase: testAuthenticate1 took 0,359 sec
> [junit] Testcase: testGetUser took 0,031 sec
> [junit] Testcase: testGetUserGroups took 0,031 sec
> [junit]     FAILED
> [junit] null
> --------------------------------------------------------------------------------- 
> 
> 
> Since the method isMember() works for the other tests, I assume I'm 
> misunderstanding something.
> This test suite is supposed to use the files in repository2, right?
> 
> I have made minor changes to the wyona security package (see attached 
> patch), but I think they are not related...
> 
> 
> Any hints?
> 
> Thanks,
> Paloma
> 
> 
> ------------------------------------------------------------------------
> 
> Index: src/test/java/org/wyona/security/test/IdentityManagerImplTest.java
> ===================================================================
> --- src/test/java/org/wyona/security/test/IdentityManagerImplTest.java	(revisión: 22819)
> +++ src/test/java/org/wyona/security/test/IdentityManagerImplTest.java	(copia de trabajo)
> @@ -48,7 +48,19 @@
>          assertNotNull(user);
>          assertEquals("lenya at wyona.org", user.getEmail());
>      }
> -
> +    
> +    public void testGetUserGroups() throws Exception {
> +	String userID = "lenya";
> +	String groupID = "editors";
> +	User user = identityManager.getUserManager().getUser(userID);
> +        assertNotNull(user);   
> +        Group group = identityManager.getGroupManager().getGroup(groupID);        
> +        assertTrue(group.isMember(user));     
> +        Group[] userGroups = user.getGroups();
> +        assertEquals(1,userGroups.length);
> +        assertEquals(groupID , userGroups[0].getID());
> +    }
> +    
>      public void testAddUser() throws Exception {
>          UserManager userManager = identityManager.getUserManager(); 
>          String id = "testuser";
> Index: src/impl/java/org/wyona/security/impl/PolicyManagerImpl.java
> ===================================================================
> --- src/impl/java/org/wyona/security/impl/PolicyManagerImpl.java	(revisión: 22819)
> +++ src/impl/java/org/wyona/security/impl/PolicyManagerImpl.java	(copia de trabajo)
> @@ -36,8 +36,16 @@
>          this.policiesRepository = policiesRepository;
>          configBuilder = new DefaultConfigurationBuilder();
>      }
> -
> +    
>      /**
> +     * Get policies repository of realm
> +     */
> +     public Repository getPoliciesRepository() {
> +           return policiesRepository;
> +     }
> +         
> +     
> +    /**
>       * @deprecated
>       */
>      public boolean authorize(Path path, Identity identity, Role role) throws AuthorizationException {
> Index: src/core/java/org/wyona/security/core/api/PolicyManager.java
> ===================================================================
> --- src/core/java/org/wyona/security/core/api/PolicyManager.java	(revisión: 22819)
> +++ src/core/java/org/wyona/security/core/api/PolicyManager.java	(copia de trabajo)
> @@ -12,11 +12,15 @@
>      /**
>       * @deprecated
>       */
> -    public boolean authorize(Path path, Identity idenitity, Role role) throws AuthorizationException;
> +    public boolean authorize(Path path, Identity identity, Role role) throws AuthorizationException;
>      
>      /**
>       *
>       */
>      public boolean authorize(String path, Identity idenitity, Role role) throws AuthorizationException;
>     
> +    /**
> +     * Get policies repository of realm
> +     */
> +     public Repository getPoliciesRepository();
>  }
> Index: build.xml
> ===================================================================
> --- build.xml	(revisión: 22819)
> +++ build.xml	(copia de trabajo)
> @@ -20,11 +20,11 @@
>        <dependency groupId="wyona-org-commons" artifactId="wyona-org-commons"
>                    version="0.0.1-dev-r22019"/>
>        <dependency groupId="yarep" artifactId="yarep-core"
> -                  version="0.0.1-dev-r22480"/>
> +                  version="0.0.1-dev-r22584"/>
>  
>        <!-- Runtime libraries -->
>        <dependency groupId="yarep" artifactId="yarep-impl"
> -                  version="0.0.1-dev-r22097"/>
> +                  version="0.0.1-dev-r22672"/>
>        <dependency groupId="avalon-framework" artifactId="avalon-framework-api"
>                    version="4.1.5"/>
>        <dependency groupId="avalon-framework" artifactId="avalon-framework-impl"
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Yanel-development mailing list
> Yanel-development at wyona.com
> http://wyona.com/cgi-bin/mailman/listinfo/yanel-development




More information about the Yanel-development mailing list