You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2026/10/10 10:36:23 UTC

(streampipes) 01/01: fix: Ignore disabled account flag for oauth authentication

This is an automated email from the ASF dual-hosted git repository.

dominikriemer pushed a commit to branch fix-disabled-oauth-accounts
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit 45b29fa1b4bae441a813af3dd52222eb20e73e25
Author: Dominik Riemer <do...@gmail.com>
AuthorDate: Sat Oct 10 12:36:01 2026 +0200

    fix: Ignore disabled account flag for oauth authentication
---
 .../service/core/oauth2/UserService.java           |  1 -
 .../service/core/oauth2/UserServiceTest.java       |  5 +-
 .../user/management/util/PrincipalStatus.java      |  8 +++
 .../user/management/util/PrincipalStatusTest.java  | 79 ++++++++++++++++++++++
 .../src/lib/services/current-user.service.ts       |  2 +-
 .../core/components/toolbar/toolbar.component.ts   |  5 +-
 6 files changed, 95 insertions(+), 5 deletions(-)

diff --git a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/oauth2/UserService.java b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/oauth2/UserService.java
index 15dd63a9cc..dced2b7a3e 100755
--- a/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/oauth2/UserService.java
+++ b/streampipes-service-core/src/main/java/org/apache/streampipes/service/core/oauth2/UserService.java
@@ -237,7 +237,6 @@ public class UserService {
     if (Objects.nonNull(fullName)) {
       user.setFullName(fullName.toString());
     }
-    user.setAccountEnabled(false);
     user.setProvider(registrationId);
     return user;
   }
diff --git a/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/oauth2/UserServiceTest.java b/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/oauth2/UserServiceTest.java
index 48dcea2425..a7c67e6a97 100644
--- a/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/oauth2/UserServiceTest.java
+++ b/streampipes-service-core/src/test/java/org/apache/streampipes/service/core/oauth2/UserServiceTest.java
@@ -42,6 +42,7 @@ import java.util.Set;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
@@ -181,7 +182,7 @@ class UserServiceTest {
   }
 
   @Test
-  void createsDisabledAccountForNewUserWithUnusedEmail() {
+  void createsEnabledAccountForNewUserWithUnusedEmail() {
     addLocalAdmin();
 
     var details = userService.processUserRegistration(PROVIDER, claims("new-user", "new.user@example.org"));
@@ -190,7 +191,7 @@ class UserServiceTest {
     assertEquals("new.user@example.org", created.getUsername());
     assertEquals(PROVIDER, created.getProvider());
     assertEquals("New User", created.getFullName());
-    assertFalse(created.isAccountEnabled());
+    assertTrue(created.isAccountEnabled());
     assertEquals("new.user@example.org", details.getUsername());
     verify(userStorage).storeUser(created);
     verify(userStorage, never()).updateUser(any());
diff --git a/streampipes-user-management/src/main/java/org/apache/streampipes/user/management/util/PrincipalStatus.java b/streampipes-user-management/src/main/java/org/apache/streampipes/user/management/util/PrincipalStatus.java
index 93160a5eda..35609d46d5 100644
--- a/streampipes-user-management/src/main/java/org/apache/streampipes/user/management/util/PrincipalStatus.java
+++ b/streampipes-user-management/src/main/java/org/apache/streampipes/user/management/util/PrincipalStatus.java
@@ -18,6 +18,7 @@
 package org.apache.streampipes.user.management.util;
 
 import org.apache.streampipes.model.client.user.Principal;
+import org.apache.streampipes.model.client.user.UserAccount;
 
 public final class PrincipalStatus {
 
@@ -25,6 +26,13 @@ public final class PrincipalStatus {
   }
 
   public static boolean canAuthenticate(Principal principal) {
+    // External providers own account status. Legacy OAuth accounts were stored as disabled.
+    // This check only determines eligibility; callers must still validate the credentials.
+    if (principal instanceof UserAccount user
+        && user.getProvider() != null && !user.getProvider().isBlank()
+        && !UserAccount.LOCAL.equals(user.getProvider())) {
+      return true;
+    }
     return principal != null && principal.isAccountEnabled()
         && !principal.isAccountLocked() && !principal.isAccountExpired();
   }
diff --git a/streampipes-user-management/src/test/java/org/apache/streampipes/user/management/util/PrincipalStatusTest.java b/streampipes-user-management/src/test/java/org/apache/streampipes/user/management/util/PrincipalStatusTest.java
new file mode 100644
index 0000000000..d7559c2861
--- /dev/null
+++ b/streampipes-user-management/src/test/java/org/apache/streampipes/user/management/util/PrincipalStatusTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.streampipes.user.management.util;
+
+import org.apache.streampipes.model.client.user.Principal;
+import org.apache.streampipes.model.client.user.ServiceAccount;
+import org.apache.streampipes.model.client.user.UserAccount;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class PrincipalStatusTest {
+
+  @Test
+  void externalProviderOwnsStatusIncludingLegacyDisabledAccounts() {
+    var user = new UserAccount();
+    user.setProvider("keycloak");
+    user.setAccountEnabled(false);
+    user.setAccountLocked(true);
+    user.setAccountExpired(true);
+
+    assertTrue(PrincipalStatus.canAuthenticate(user));
+  }
+
+  @Test
+  void localAndMissingProvidersEnforceLocalStatus() {
+    var user = new UserAccount();
+    assertLocalStatus(user);
+    user.setProvider(null);
+    assertLocalStatus(user);
+    user.setProvider("");
+    assertLocalStatus(user);
+    user.setProvider(" ");
+    assertLocalStatus(user);
+  }
+
+  @Test
+  void serviceAccountsEnforceLocalStatus() {
+    assertLocalStatus(new ServiceAccount());
+  }
+
+  @Test
+  void missingPrincipalCannotAuthenticate() {
+    assertFalse(PrincipalStatus.canAuthenticate(null));
+  }
+
+  private void assertLocalStatus(Principal principal) {
+    principal.setAccountEnabled(true);
+    principal.setAccountLocked(false);
+    principal.setAccountExpired(false);
+    assertTrue(PrincipalStatus.canAuthenticate(principal));
+
+    principal.setAccountEnabled(false);
+    assertFalse(PrincipalStatus.canAuthenticate(principal));
+    principal.setAccountEnabled(true);
+    principal.setAccountLocked(true);
+    assertFalse(PrincipalStatus.canAuthenticate(principal));
+    principal.setAccountLocked(false);
+    principal.setAccountExpired(true);
+    assertFalse(PrincipalStatus.canAuthenticate(principal));
+  }
+}
diff --git a/ui/projects/streampipes/shared-ui/src/lib/services/current-user.service.ts b/ui/projects/streampipes/shared-ui/src/lib/services/current-user.service.ts
index 885edf6d89..077a7a5ffc 100644
--- a/ui/projects/streampipes/shared-ui/src/lib/services/current-user.service.ts
+++ b/ui/projects/streampipes/shared-ui/src/lib/services/current-user.service.ts
@@ -43,7 +43,7 @@ export class CurrentUserService {
     }
 
     public hasRole(role: string): boolean {
-        const roles = this.getCurrentUser().roles;
+        const roles = this.getCurrentUser()?.roles ?? [];
         return roles.includes('ROLE_ADMIN') || roles.includes(role);
     }
 
diff --git a/ui/src/app/core/components/toolbar/toolbar.component.ts b/ui/src/app/core/components/toolbar/toolbar.component.ts
index 45b28e9c1c..75336db024 100644
--- a/ui/src/app/core/components/toolbar/toolbar.component.ts
+++ b/ui/src/app/core/components/toolbar/toolbar.component.ts
@@ -82,7 +82,10 @@ export class ToolbarComponent
     ngOnInit(): void {
         this.assetFilterService.applyAssetLinkType('');
         this.currentUserService.user$.subscribe(user => {
-            this.userEmail = user.displayName || user.username;
+            this.userEmail = user?.displayName || user?.username || '';
+            if (!user) {
+                return;
+            }
             this.profileService
                 .getUserProfile(user.username)
                 .subscribe(userInfo => {