Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added removeRoles function that removes all existing UserRoles for th… #90

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class SpringSecurityUiService implements AclStrategy, ErrorsStrategy, Persistent
return
}

UserRole.removeAll user
removeRoles user, roleNames
addRoles user, roleNames
removeUserFromCache user
}
Expand All @@ -334,10 +334,32 @@ class SpringSecurityUiService implements AclStrategy, ErrorsStrategy, Persistent

protected void addRoles(user, List<String> roleNames) {
String authorityNameField = uiPropertiesStrategy.paramNameToPropertyName('authority', 'role')

try {
for (String roleName in roleNames) {
UserRole.create user, Role.findWhere((authorityNameField): roleName)
def role = Role.findWhere((authorityNameField): roleName)
if (!UserRole.findByUserAndRole(user,role)) {
UserRole.create user, Role.findWhere((authorityNameField): roleName)
}
}
}
catch (e) {
uiErrorsStrategy.handleException e, user, null, this, 'addRoles', transactionStatus
}
}

protected void removeRoles(user, List<String> roleNames) {
String authorityNameField = uiPropertiesStrategy.paramNameToPropertyName('authority', 'role')
try {
for (def existingRole in UserRole.findAllByUser(user)) {
Boolean delete = true
for (String roleName in roleNames) {
if (existingRole.role == Role.findWhere((authorityNameField): roleName)) {
delete = false
}
}
if (delete) {
existingRole.delete()
}
}
}
catch (e) {
Expand Down