Skip to content

Commit

Permalink
Ensure groups logic works with Keycloak 20+ (#11)
Browse files Browse the repository at this point in the history
The 'getGroups()' method was removed in Keycloak 20 and replaced with 'getGroupsStream()'
  • Loading branch information
treydock authored Apr 3, 2023
1 parent 4a44d22 commit cfc3a88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<keycloak.version>18.0.0</keycloak.version>
<keycloak.version>21.0.1</keycloak.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -111,4 +111,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void authenticate(AuthenticationFlowContext authenticationFlowContext) {
}
String username = user.getUsername();
if (!duoRequired(duoGroups, user)) {
String userGroupsStr = user.getGroups().stream().map(GroupModel::getName).collect(Collectors.joining(","));
String userGroupsStr = user.getGroupsStream().map(GroupModel::getName).collect(Collectors.joining(","));
logger.infof("Skipping Duo MFA for %s based on group membership, groups=%s", username, userGroupsStr);
authenticationFlowContext.success();
return;
Expand Down Expand Up @@ -258,8 +258,9 @@ private boolean duoRequired(String duoGroups, UserModel user) {
if (duoGroups == "none") return true;
if (duoGroups != null && duoGroups.isEmpty()) return true;
List<String> groups = Arrays.asList(duoGroups.split(","));
for (GroupModel group : user.getGroups()) {
if (groups.contains(group.getName())) {
List<String> groupNames = user.getGroupsStream().map(GroupModel::getName).collect(Collectors.toList());
for (String group : groupNames) {
if (groups.contains(group)) {
return true;
}
}
Expand Down

0 comments on commit cfc3a88

Please sign in to comment.