Skip to content

Commit 1df29d8

Browse files
authored
Merge pull request #249 from georchestra/fix-insert-roles
fix: add roles from org to users when created
2 parents 5cb3c1e + 3f4f837 commit 1df29d8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

gateway/src/main/java/org/georchestra/gateway/accounts/admin/ldap/LdapAccountsManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import java.util.List;
2323
import java.util.Objects;
2424
import java.util.Optional;
25+
import java.util.stream.Collectors;
2526

2627
import com.google.common.annotations.VisibleForTesting;
2728
import org.apache.commons.lang3.StringUtils;
2829
import org.georchestra.ds.DataServiceException;
2930
import org.georchestra.ds.DuplicatedCommonNameException;
3031
import org.georchestra.ds.orgs.Org;
3132
import org.georchestra.ds.orgs.OrgsDao;
33+
import org.georchestra.ds.roles.Role;
3234
import org.georchestra.ds.roles.RoleDao;
3335
import org.georchestra.ds.roles.RoleFactory;
3436
import org.georchestra.ds.users.Account;
@@ -236,6 +238,11 @@ private void ensureRolesExist(GeorchestraUser mapped, Account newAccount) {
236238
if (!mapped.getRoles().contains("ROLE_USER")) {
237239
roleDao.addUser("USER", newAccount);
238240
}
241+
if (newAccount.getOrg() != null) {
242+
List<Role> r = roleDao.findAllForOrg(orgsDao.findByCommonName(newAccount.getOrg()));
243+
if (!r.isEmpty())
244+
roleDao.addUsersInRoles(r.stream().map(Role::getName).collect(Collectors.toList()), List.of(newAccount));
245+
}
239246
for (String role : mapped.getRoles()) {
240247
role = role.replaceFirst("^ROLE_", "");
241248
ensureRoleExists(role);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.springframework.cloud</groupId>
66
<artifactId>spring-cloud-starter-parent</artifactId>
7-
<version>2024.0.1</version>
7+
<version>2024.0.3</version>
88
<relativePath></relativePath>
99
<!-- lookup parent from repository -->
1010
</parent>

0 commit comments

Comments
 (0)