Skip to content

Commit

Permalink
Merge pull request #85 from marwanehcine/making_default_org_optional_…
Browse files Browse the repository at this point in the history
…for_OAuth2_users

Adding Optional Default Org for OAuth2 users
  • Loading branch information
emmdurin authored Dec 22, 2023
2 parents bce93a4 + f9eb79d commit 81a7d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.georchestra.gateway.accounts.admin.AccountManager;
import org.georchestra.security.api.UsersApi;
import org.georchestra.security.model.GeorchestraUser;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ldap.NameNotFoundException;

import lombok.NonNull;
Expand All @@ -55,6 +56,7 @@
@Slf4j(topic = "org.georchestra.gateway.accounts.admin.ldap")
class LdapAccountsManager extends AbstractAccountsManager {

private @Value("${georchestra.gateway.security.defaultOrganization:}") String defaultOrganization;
private final @NonNull AccountDao accountDao;
private final @NonNull RoleDao roleDao;

Expand Down Expand Up @@ -148,7 +150,11 @@ private Account mapToAccountBrief(@NonNull GeorchestraUser preAuth) {
Account newAccount = AccountFactory.createBrief(username, password, firstName, lastName, email, phone, title,
description, oAuth2ProviderId);
newAccount.setPending(false);
newAccount.setOrg(org);
if (StringUtils.isEmpty(org) && !StringUtils.isBlank(defaultOrganization)) {
newAccount.setOrg(defaultOrganization);
} else {
newAccount.setOrg(org);
}
return newAccount;
}

Expand All @@ -172,6 +178,8 @@ private void ensureOrgExists(@NonNull Account newAccount) {
org = new Org();
org.setId(orgId);
org.setName(orgId);
org.setShortName(orgId);
org.setOrgType("Other");
org.setMembers(Arrays.asList(newAccount.getUid()));
orgsDao.insert(org);
}
Expand Down
1 change: 1 addition & 0 deletions gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ georchestra:
gateway:
security:
create-non-existing-users-in-l-d-a-p: false
defaultOrganization: ${defaultOrganization:}
header-authentication:
enabled: false
events:
Expand Down

0 comments on commit 81a7d30

Please sign in to comment.