antalk / Tapestry-Spring-Security

A Tapestry 5.3.x spring based security library
11 stars 6 forks source link

Problem when using other implementation of GrantedAuthority than GrantedAuthorityImpl #5

Closed tnodev closed 10 years ago

tnodev commented 10 years ago

Hello

The component IfRole doesn't work when using other implementation of GrantedAuthority than GrantedAuthorityImpl. Exemple : SimpleGrantedAuthority, or your own !

May be you should use a String collection and put the getAuthority from any implementation of GrantedAuthority

Thomas

antalk commented 10 years ago

You;re right.. i've written a simple test and it seems not to work. I may create a patch for this.

antalk commented 10 years ago

So i've created a fix:

Replaced the method

private Collection<GrantedAuthority> retainAll(final Collection<GrantedAuthority> granted, final Collection<GrantedAuthority> required)

with:

private Collection<GrantedAuthority> retainAll(final Collection<GrantedAuthority> granted, final Collection<GrantedAuthority> required) {
        Collection<GrantedAuthority> grantedRoles = new ArrayList<GrantedAuthority>();
        for (GrantedAuthority auth: granted) {
            for (GrantedAuthority req: required) {
                if (req.getAuthority().equals(auth.getAuthority())) {
                    grantedRoles.add(auth);
                    break;
                }
            }
        }

        return rolesToAuthorities(grantedRoles, granted);
    }

This way the implementation only uses the interface GrantedAuthority and not it's actual implementation as the retainAll function in the Collections does.

Let me know what you think, i've tested it with 'SimpleGrantedAuthority' and it seems to work.

tnodev commented 10 years ago

I test...

OK it works !

Great