This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch roller-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/roller-6.1.x by this push:
new 639c308da Refuse disabled accounts when signing in with an OpenID URL
(#224)
639c308da is described below
commit 639c308dab09565f0e505e9a76a4ce75817c2836
Author: David M. Johnson <[email protected]>
AuthorDate: Thu Oct 29 22:44:52 2026 -0400
Refuse disabled accounts when signing in with an OpenID URL (#224)
* Refuse disabled accounts when signing in with an OpenID URL
* Note the OpenID sign-in change in CHANGES.md
* Reword the OpenID sign-in entry in CHANGES.md
* Pass the account's enabled flag to Spring and share OpenID URL handling
---
CHANGES.md | 4 +
.../roller/weblogger/ui/core/RollerSession.java | 9 +-
.../weblogger/ui/core/security/OpenIdUrls.java | 36 +++++++
.../ui/core/security/RollerUserDetailsService.java | 17 +--
.../security/RollerUserDetailsServiceTest.java | 116 +++++++++++++++++++++
5 files changed, 170 insertions(+), 12 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 23072ab37..819373e77 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -78,6 +78,10 @@
- **Previews need a role in the weblog.** Previewing a weblog's pages or
theme resources now requires an enabled user with a role in that weblog
(Limited, Author or Admin), or a global admin.
+- **Disabled accounts cannot sign in with an OpenID URL.** An account that an
+ administrator has disabled is now refused whenever its OpenID URL is used to
+ sign in, on every sign-in form, as user name and password sign-in already
+ does.
### Bug fixes
diff --git
a/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSession.java
b/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSession.java
index 5c0f029c2..a1b1caf33 100644
--- a/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSession.java
+++ b/app/src/main/java/org/apache/roller/weblogger/ui/core/RollerSession.java
@@ -34,6 +34,7 @@ import org.apache.roller.weblogger.business.WebloggerFactory;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.pojos.User;
import org.apache.roller.weblogger.ui.core.security.AutoProvision;
+import org.apache.roller.weblogger.ui.core.security.OpenIdUrls;
/**
@@ -91,12 +92,8 @@ public class RollerSession
User user = umgr.getUserByUserName(principal.getName());
// check for OpenID username (in the form of a URL)
- if (user == null && principal.getName() != null &&
principal.getName().startsWith("http://")) {
- String openidurl = principal.getName();
- if (openidurl.endsWith("/")) {
- openidurl = openidurl.substring(0,
openidurl.length() - 1);
- }
- user = umgr.getUserByOpenIdUrl(openidurl);
+ if (user == null &&
OpenIdUrls.isOpenIdUrl(principal.getName())) {
+ user =
umgr.getUserByOpenIdUrl(OpenIdUrls.normalize(principal.getName()));
}
// try one time to auto-provision, only happens if
user==null
diff --git
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/OpenIdUrls.java
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/OpenIdUrls.java
new file mode 100644
index 000000000..b49dc0302
--- /dev/null
+++
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/OpenIdUrls.java
@@ -0,0 +1,36 @@
+/*
+ * 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
+ *
+ * https://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.roller.weblogger.ui.core.security;
+
+/**
+ * How a sign-in name that is an OpenID URL is recognized and stored.
+ */
+public final class OpenIdUrls {
+
+ private OpenIdUrls() {
+ }
+
+ /** True if the sign-in name is an OpenID URL rather than a user name. */
+ public static boolean isOpenIdUrl(String name) {
+ return name != null && (name.startsWith("http://") ||
name.startsWith("https://"));
+ }
+
+ /** The URL as stored in the user table: without a trailing slash. */
+ public static String normalize(String url) {
+ return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
+ }
+}
diff --git
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
index db41c19b1..5b88d61dd 100644
---
a/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
+++
b/app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsService.java
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.security.authentication.DisabledException;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -40,10 +41,8 @@ public class RollerUserDetailsService implements
UserDetailsService {
UserManager umgr = roller.getUserManager();
User userData;
// OpenID user?
- if (userName.startsWith("http://") ||
userName.startsWith("https://")) {
- if (userName.endsWith("/")) {
- userName = userName.substring(0, userName.length() -1 );
- }
+ if (OpenIdUrls.isOpenIdUrl(userName)) {
+ userName = OpenIdUrls.normalize(userName);
try {
userData = umgr.getUserByOpenIdUrl(userName);
if (userData == null) {
@@ -53,6 +52,9 @@ public class RollerUserDetailsService implements
UserDetailsService {
} catch (WebloggerException ex) {
throw new DataRetrievalFailureException("ERROR in user
lookup", ex);
}
+ if (userData != null &&
!Boolean.TRUE.equals(userData.getEnabled())) {
+ throw new DisabledException("User account is disabled: " +
userData.getUserName());
+ }
String name;
String password;
List<SimpleGrantedAuthority> authorities;
@@ -71,8 +73,11 @@ public class RollerUserDetailsService implements
UserDetailsService {
name = userData.getUserName();
password = userData.getPassword();
}
+ // a disabled user was refused above; pass the flag anyway so
+ // Spring's own account checks see it
+ boolean enabled = userData == null ||
Boolean.TRUE.equals(userData.getEnabled());
return new
org.springframework.security.core.userdetails.User(name, password,
- true, true, true, true, authorities);
+ enabled, true, true, true, authorities);
} else {
// standard username/password auth
try {
@@ -85,7 +90,7 @@ public class RollerUserDetailsService implements
UserDetailsService {
}
List<SimpleGrantedAuthority> authorities =
getAuthorities(userData, umgr);
return new
org.springframework.security.core.userdetails.User(userData.getUserName(),
userData.getPassword(),
- true, true, true, true, authorities);
+ Boolean.TRUE.equals(userData.getEnabled()), true,
true, true, authorities);
}
} catch (WebloggerException ex) {
throw new DataAccessResourceFailureException("ERROR: fetching
roles", ex);
diff --git
a/app/src/test/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsServiceTest.java
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsServiceTest.java
new file mode 100644
index 000000000..42d8dacfc
--- /dev/null
+++
b/app/src/test/java/org/apache/roller/weblogger/ui/core/security/RollerUserDetailsServiceTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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
+ *
+ * https://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.roller.weblogger.ui.core.security;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.roller.weblogger.business.UserManager;
+import org.apache.roller.weblogger.business.Weblogger;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.pojos.User;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.springframework.security.authentication.DisabledException;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+/**
+ * Sign-in through an OpenID URL honors the account's enabled flag.
+ */
+class RollerUserDetailsServiceTest {
+
+ private static final String OPENID = "https://id.example.com/reader";
+
+ private MockedStatic<WebloggerFactory> factory;
+ private UserManager users;
+
+ @BeforeEach
+ void setUp() throws Exception {
+ users = mock(UserManager.class);
+ Weblogger roller = mock(Weblogger.class);
+ when(roller.getUserManager()).thenReturn(users);
+ factory = mockStatic(WebloggerFactory.class);
+ factory.when(WebloggerFactory::getWeblogger).thenReturn(roller);
+ }
+
+ @AfterEach
+ void tearDown() {
+ factory.close();
+ }
+
+ private User user(Boolean enabled) throws Exception {
+ User user = new User();
+ user.setUserName("reader");
+ user.setPassword("x");
+ user.setEnabled(enabled);
+ when(users.getUserByOpenIdUrl(OPENID)).thenReturn(user);
+ when(users.getRoles(user)).thenReturn(List.of("editor"));
+ return user;
+ }
+
+ @Test
+ void enabledOpenIdUserSignsIn() throws Exception {
+ user(true);
+ UserDetails details = new
RollerUserDetailsService().loadUserByUsername(OPENID);
+ assertEquals("reader", details.getUsername());
+ }
+
+ @Test
+ void disabledOpenIdUserIsRefused() throws Exception {
+ user(false);
+ assertThrows(DisabledException.class,
+ () -> new
RollerUserDetailsService().loadUserByUsername(OPENID));
+ }
+
+ @Test
+ void enabledOpenIdUserIsMarkedEnabled() throws Exception {
+ user(true);
+ assertTrue(new
RollerUserDetailsService().loadUserByUsername(OPENID).isEnabled());
+ }
+
+ @Test
+ void openIdUserWithNoEnabledFlagIsRefused() throws Exception {
+ user(null);
+ assertThrows(DisabledException.class,
+ () -> new
RollerUserDetailsService().loadUserByUsername(OPENID));
+ }
+
+ @Test
+ void disabledOpenIdUserIsRefusedWithTrailingSlash() throws Exception {
+ user(false);
+ assertThrows(DisabledException.class,
+ () -> new RollerUserDetailsService().loadUserByUsername(OPENID
+ "/"));
+ }
+
+ @Test
+ void unknownOpenIdUrlGetsTheRegistrationPlaceholder() throws Exception {
+ UserDetails details = new
RollerUserDetailsService().loadUserByUsername(OPENID);
+ assertEquals("openid", details.getUsername());
+ assertEquals(List.of("rollerOpenidLogin"),
details.getAuthorities().stream()
+
.map(GrantedAuthority::getAuthority).collect(Collectors.toList()));
+ }
+}