Quantcast

Acegi 0.5.1 on Grails 1.1-beta3, Roles not being saved when updating a user if authority is not prefixed with ROLE_

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Acegi 0.5.1 on Grails 1.1-beta3, Roles not being saved when updating a user if authority is not prefixed with ROLE_

Jonathan Andrew Ong
Hi,

I have a practice project that I am working on to experiment with acegi and audit logging plugin.
When I update a user and tick a role, the role does not get saved to the users' roles. 

I noticed something on the codes. In the User Controller, when saving a user, I believe that this is the section of the code that saves the roles:

private void addRoles(person) {
for (String key in params.keySet()) {
            println params
if (key.contains('ROLE') && 'on' == params.get(key)) {
Authority.findByAuthority(key).addToPeople(person)
}
}
}

It seems to be looking for an input field with name ROLE.

However, the generated Person edit.gsp:

GSP:
<g:each var="entry" in="${roleMap}">
<li>${entry.key.authority.encodeAsHTML()}
<g:checkBox name="${entry.key.authority}" value="${entry.value}"/>
</li>
</g:each>

I have tested with Authorities starting with ROLE and others that do not, and only those roles that start with the prefix gets saved. 

Is this a design by default? What is the reason behind this?

thanks!
Jonathan


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Acegi 0.5.1 on Grails 1.1-beta3, Roles not being saved when updating a user if authority is not prefixed with ROLE_

David Trattnig
As far as I know this is an requirement by Spring Security that role names have to start with the prefix "ROLE_"

cheers
david


On Mon, Feb 16, 2009 at 11:14 AM, Jonathan Andrew Ong <[hidden email]> wrote:
Hi,

I have a practice project that I am working on to experiment with acegi and audit logging plugin.
When I update a user and tick a role, the role does not get saved to the users' roles. 

I noticed something on the codes. In the User Controller, when saving a user, I believe that this is the section of the code that saves the roles:

private void addRoles(person) {
for (String key in params.keySet()) {
            println params
if (key.contains('ROLE') && 'on' == params.get(key)) {
Authority.findByAuthority(key).addToPeople(person)
}
}
}

It seems to be looking for an input field with name ROLE.

However, the generated Person edit.gsp:

GSP:
<g:each var="entry" in="${roleMap}">
<li>${entry.key.authority.encodeAsHTML()}
<g:checkBox name="${entry.key.authority}" value="${entry.value}"/>
</li>
</g:each>

I have tested with Authorities starting with ROLE and others that do not, and only those roles that start with the prefix gets saved. 

Is this a design by default? What is the reason behind this?

thanks!
Jonathan





--
____david_trattnig_____
http://photos.bitfusion.org
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Acegi 0.5.1 on Grails 1.1-beta3, Roles not being saved when updating a user if authority is not prefixed with ROLE_

Jonathan Andrew Ong
Hi David,

Thanks for the quick reply. Will keep that in mind.

Regards,
Jonathan

On Mon, Feb 16, 2009 at 1:47 PM, David Trattnig <[hidden email]> wrote:
As far as I know this is an requirement by Spring Security that role names have to start with the prefix "ROLE_"

cheers
david



On Mon, Feb 16, 2009 at 11:14 AM, Jonathan Andrew Ong <[hidden email]> wrote:
Hi,

I have a practice project that I am working on to experiment with acegi and audit logging plugin.
When I update a user and tick a role, the role does not get saved to the users' roles. 

I noticed something on the codes. In the User Controller, when saving a user, I believe that this is the section of the code that saves the roles:

private void addRoles(person) {
for (String key in params.keySet()) {
            println params
if (key.contains('ROLE') && 'on' == params.get(key)) {
Authority.findByAuthority(key).addToPeople(person)
}
}
}

It seems to be looking for an input field with name ROLE.

However, the generated Person edit.gsp:

GSP:
<g:each var="entry" in="${roleMap}">
<li>${entry.key.authority.encodeAsHTML()}
<g:checkBox name="${entry.key.authority}" value="${entry.value}"/>
</li>
</g:each>

I have tested with Authorities starting with ROLE and others that do not, and only those roles that start with the prefix gets saved. 

Is this a design by default? What is the reason behind this?

thanks!
Jonathan





--
____david_trattnig_____
http://photos.bitfusion.org

Loading...