Skip to content

Commit 1d2d49c

Browse files
committed
use userManager.getCurrentUserInfo() instead of LdapUserInfoProvider
1 parent 32ea509 commit 1d2d49c

File tree

2 files changed

+12
-121
lines changed

2 files changed

+12
-121
lines changed

server/impl/src/main/java/com/walmartlabs/concord/server/process/form/FormAccessManager.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import com.walmartlabs.concord.server.security.Roles;
2727
import com.walmartlabs.concord.server.security.UnauthorizedException;
2828
import com.walmartlabs.concord.server.security.UserPrincipal;
29-
import com.walmartlabs.concord.server.security.ldap.LdapPrincipal;
30-
import com.walmartlabs.concord.server.security.ldap.LdapUserInfoProvider;
29+
import com.walmartlabs.concord.server.user.UserInfoProvider;
30+
import com.walmartlabs.concord.server.user.UserManager;
3131
import io.takari.bpm.form.Form;
3232

3333
import javax.inject.Inject;
@@ -38,7 +38,6 @@
3838
import java.util.Map;
3939
import java.util.Optional;
4040
import java.util.Set;
41-
import java.util.function.Supplier;
4241
import java.util.regex.Matcher;
4342
import java.util.regex.Pattern;
4443

@@ -49,12 +48,12 @@ public class FormAccessManager {
4948
private static final Pattern GROUP_PATTERN = Pattern.compile("CN=(.*?),", Pattern.CASE_INSENSITIVE);
5049

5150
private final ProcessStateManager stateManager;
52-
private final LdapUserInfoProvider ldapUserInfoProvider;
51+
private final UserManager userManager;
5352

5453
@Inject
55-
public FormAccessManager(ProcessStateManager stateManager, LdapUserInfoProvider ldapUserInfoProvider) {
54+
public FormAccessManager(ProcessStateManager stateManager, UserManager userManager) {
5655
this.stateManager = stateManager;
57-
this.ldapUserInfoProvider = ldapUserInfoProvider;
56+
this.userManager = userManager;
5857
}
5958

6059
@SuppressWarnings("unchecked")
@@ -93,37 +92,22 @@ public void assertFormAccess(String formName, Map<String, Serializable> runAsPar
9392
"the necessary permissions to access the form.");
9493
}
9594

96-
Set<String> groups = com.walmartlabs.concord.forms.FormUtils.getRunAsLdapGroups(formName, runAsParams);
97-
if (!groups.isEmpty()) {
98-
Set<String> userLdapGroups = getLdapPrincipalGroups(p, ldapUserInfoProvider, LdapPrincipal::getCurrent);
95+
Set<String> formRunAsGroups = com.walmartlabs.concord.forms.FormUtils.getRunAsLdapGroups(formName, runAsParams);
96+
if (!formRunAsGroups.isEmpty()) {
97+
Set<String> userLdapGroups = Optional.ofNullable(userManager.getCurrentUserInfo())
98+
.map(UserInfoProvider.UserInfo::groups)
99+
.orElseGet(Set::of);
99100

100-
boolean isGroupMatched = groups.stream()
101+
boolean isGroupMatched = formRunAsGroups.stream()
101102
.anyMatch(group -> matchesLdapGroup(group, userLdapGroups));
102103

103104
if (!isGroupMatched) {
104105
throw new UnauthorizedException("The current user (" + p.getUsername() + ") doesn't have " +
105-
"the necessary permissions to resume process. Expected LDAP group(s) '" + groups + "'");
106+
"the necessary permissions to resume process. Expected LDAP group(s) '" + formRunAsGroups + "'");
106107
}
107108
}
108109
}
109110

110-
static Set<String> getLdapPrincipalGroups(UserPrincipal p,
111-
LdapUserInfoProvider ldapUserInfoProvider,
112-
Supplier<LdapPrincipal> currentPrincipalSupplier) {
113-
if (p == null) {
114-
return Set.of();
115-
}
116-
117-
if (p.getRealm().equals("apikey")) {
118-
// apikey realm doesn't look up groups by default, get them now
119-
return ldapUserInfoProvider.getInfo(null, p.getUsername(), p.getDomain()).groups();
120-
}
121-
122-
return Optional.ofNullable(currentPrincipalSupplier.get())
123-
.map(LdapPrincipal::getGroups)
124-
.orElseGet(Set::of);
125-
}
126-
127111
// TODO: move to the formManager
128112
private Form getForm(ProcessKey processKey, String formName) {
129113
String resource = path(Constants.Files.JOB_ATTACHMENTS_DIR_NAME,

server/impl/src/test/java/com/walmartlabs/concord/server/process/form/FormAccessManagerTest.java

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)