Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d480a31
Keep the stored federated identity when saving a profile or registering
mraible Nov 17, 2026
51be56f
Decline only pending invitations and keep a weblog's last admin from …
mraible Nov 17, 2026
b001ad8
Escape the commenter's user name in the LDAP comment authenticator's …
mraible Nov 18, 2026
e153a69
Limit search query length and treat queries Lucene cannot run as find…
mraible Nov 18, 2026
b3c5688
Check for a remaining weblog admin and change memberships in one lock…
mraible Nov 18, 2026
23eb1e8
Remove pending invitations along with their weblog or user
mraible Nov 18, 2026
7e4b6e1
Drop the opening quote of a phrase that the search query limit cuts off
mraible Nov 18, 2026
15d3803
Handle disabled members and non-members in weblog membership changes
mraible Nov 19, 2026
ba8f051
Key Members page rows by permission so disabled members can be changed
mraible Nov 20, 2026
6e08db6
Merge remote-tracking branch 'origin/master' into account-and-search-…
mraible Nov 20, 2026
79e5d77
Check that a membership change is for a member before locking the weblog
mraible Nov 20, 2026
3616ac3
Show no change counts on the Members page when saving fails
mraible Nov 20, 2026
499e601
Show the outcome of resigning from a weblog on the main menu
mraible Nov 20, 2026
ea0775f
Cap search queries without counting escaped quotes or surrounding whi…
mraible Nov 20, 2026
fda70f8
Treat only query errors from Lucene as a search that finds nothing
mraible Nov 20, 2026
1a00165
Tell a member who declines an accepted invitation that they're alread…
mraible Nov 20, 2026
2711b8a
Tidy the membership and federated identity test cleanup
mraible Nov 20, 2026
9980485
Say in CHANGES that the main menu shows the outcome of resigning
mraible Nov 20, 2026
ffbc863
Require a weblog the user belongs to before resigning from it
mraible Nov 20, 2026
0fa82c3
Say in CHANGES what declining an accepted invitation and spaces aroun…
mraible Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@
- **Tags of a scheduled entry are counted once, when it goes live.** Entries
posted through AtomPub with a future date showed their tags in tag counts
early and counted them twice (#316).
- **A weblog's only administrator can't resign from it**, and declining an
invitation only removes a pending invitation (#322).
- **A weblog's only administrator can't resign from it**, and the main menu
says why. After resigning, the main menu now shows whether it worked.
Declining an invitation only removes a pending invitation, and declining
one you already accepted says you're already a member (#322).
- **Passwords stored with an older encoding are upgraded at login.** With
`passwds.encryption.lazyUpgradeFrom` set (`SHA` by default), passwords from
older Roller versions could be used to log in, but they stayed stored in the
Expand Down Expand Up @@ -203,8 +205,8 @@
permission to publish, media uploads over `uploads.file.maxsize` are
refused with 413 before they're stored, and entries show the creator's
email address only to the creator (also in MetaWeblog responses) (#316).
- **Search queries are limited to 256 characters**, and a query the search
engine can't run finds nothing (#322).
- **Search queries are limited to 256 characters**, after spaces around them
are dropped, and a query the search engine can't run finds nothing (#322).
- **The OpenID Connect identity can't be changed from the profile or
registration forms**; only Roller's OpenID Connect login sets it (#322).
- **Weblog pages ignore a `skipCache` query parameter** (#313).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ List<WeblogPermission> getWeblogPermissions(Weblog weblog)
List<WeblogPermission> getPendingWeblogPermissions(Weblog weblog)
throws WebloggerException;

/**
* Change the memberships of a weblog as one operation that keeps the
* weblog's administrators. Changes for the same weblog are serialized:
* the weblog's row stays locked until the caller flushes or releases the
* session, so the administrator check and the changes cannot interleave
* with another membership update.
* @param weblog Weblog whose memberships change
* @param changes New actions by user name; a null value removes that
* user's membership
* @return false, with nothing changed, if the changes would remove the
* weblog's last administrator (pending invitations don't count)
*/
boolean updateWeblogMembership(Weblog weblog, Map<String, List<String>> changes)
throws WebloggerException;

/**
* Get all permissions (pending or actual) for a weblog.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import jakarta.persistence.EntityManager;
import jakarta.persistence.LockModeType;
import jakarta.persistence.NoResultException;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.TypedQuery;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.GlobalPermission;
Expand Down Expand Up @@ -78,7 +81,10 @@ public void removeUser(User user) throws WebloggerException {
String userName = user.getUserName();

// remove permissions, maintaining both sides of relationship
List<WeblogPermission> perms = getWeblogPermissions(user);
List<WeblogPermission> perms = new ArrayList<>(getWeblogPermissions(user));
// and pending invitations, which a new user of the same name would
// otherwise inherit
perms.addAll(getPendingWeblogPermissions(user));
for (WeblogPermission perm : perms) {
this.strategy.remove(perm);
}
Expand Down Expand Up @@ -514,6 +520,10 @@ public void declineWeblogPermission(Weblog weblog, User user) throws WebloggerEx
} catch (NoResultException ignored) {
throw new WebloggerException("ERROR: permission not found");
}
// only an invitation can be declined; members leave by resigning
if (!existingPerm.isPending()) {
throw new WebloggerException("ERROR: permission is not a pending invitation");
}
// remove permission
this.strategy.remove(existingPerm);
}
Expand Down Expand Up @@ -563,6 +573,94 @@ public List<WeblogPermission> getWeblogPermissions(Weblog weblog) throws Weblogg
return q.getResultList();
}

@Override
public boolean updateWeblogMembership(Weblog weblog, Map<String, List<String>> changes)
throws WebloggerException {

List<WeblogPermission> perms;
try {
// every change has to be for a member of, or a user invited to,
// the weblog; check before taking the lock, so a request for
// someone else's weblog doesn't wait for or hold it
checkMemberships(readMemberships(weblog.getHandle()), changes);

// lock the weblog's row so membership updates for it run one at
// a time
EntityManager em = strategy.getEntityManager(true);
Weblog locked = em.find(Weblog.class, weblog.getId(), LockModeType.PESSIMISTIC_WRITE);
if (locked == null) {
throw new WebloggerException("ERROR: weblog not found");
}

// read the memberships again now that the lock is held
perms = readMemberships(locked.getHandle());
checkMemberships(perms, changes);
} catch (PersistenceException e) {
throw new WebloggerException(e);
}

boolean adminBefore = false;
boolean adminAfter = false;
for (WeblogPermission perm : perms) {
if (perm.isPending()) {
continue;
}
// a disabled user can't manage the weblog
if (perm.getUser() == null || !Boolean.TRUE.equals(perm.getUser().getEnabled())) {
continue;
}
boolean admin = perm.hasAction(WeblogPermission.ADMIN);
adminBefore |= admin;
if (changes.containsKey(perm.getUserName())) {
List<String> actions = changes.get(perm.getUserName());
admin = actions != null && actions.contains(WeblogPermission.ADMIN);
}
adminAfter |= admin;
}
if (adminBefore && !adminAfter) {
return false;
}

for (WeblogPermission perm : perms) {
if (!changes.containsKey(perm.getUserName())) {
continue;
}
// change the row that was read, which also works for a disabled
// user and leaves an invitation pending
List<String> actions = changes.get(perm.getUserName());
if (actions == null) {
this.strategy.remove(perm);
} else {
perm.setActionsAsList(actions);
this.strategy.store(perm);
}
}
return true;
}

// a weblog's memberships and invitations, read from the database rather
// than the cache
private List<WeblogPermission> readMemberships(String handle) throws WebloggerException {
TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending",
WeblogPermission.class);
q.setParameter(1, handle);
q.setHint("eclipselink.refresh", "true");
return q.getResultList();
}

private static void checkMemberships(List<WeblogPermission> perms, Map<String, List<String>> changes)
throws WebloggerException {
for (String userName : changes.keySet()) {
boolean found = false;
for (WeblogPermission perm : perms) {
found |= perm.getUserName().equals(userName);
}
if (!found) {
throw new WebloggerException("ERROR: permission not found");
}
}
}

@Override
public List<WeblogPermission> getWeblogPermissionsIncludingPending(Weblog weblog) throws WebloggerException {
TypedQuery<WeblogPermission> q = strategy.getNamedQuery("WeblogPermission.getByWeblogIdIncludingPending",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ private void removeWeblogContents(Weblog weblog)
removeCategories.setParameter(1, weblog);
removeCategories.executeUpdate();

// remove permissions
for (WeblogPermission perm : umgr.getWeblogPermissions(weblog)) {
umgr.revokeWeblogPermission(perm.getWeblog(), perm.getUser(), WeblogPermission.ALL_ACTIONS);
// remove permissions, and pending invitations, which a new weblog with
// the same handle would otherwise inherit. The rows are removed
// directly, as a disabled user's can't be looked up through the user.
for (WeblogPermission perm : umgr.getWeblogPermissionsIncludingPending(weblog)) {
this.strategy.remove(perm);
}

// flush the changes before returning. This is required as there is a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopFieldCollectorManager;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
import org.apache.roller.weblogger.business.search.IndexManager;
import org.apache.roller.weblogger.config.WebloggerConfig;

Expand Down Expand Up @@ -171,6 +172,15 @@ public void doRun() {
} catch (ParseException e) {
// who cares?
parseError = e.getMessage();

} catch (IllegalArgumentException | IndexSearcher.TooManyClauses
| TooComplexToDeterminizeException e) {
// Lucene rejects some queries that parse, such as an unfinished
// regular expression or a negative phrase slop, only when it
// builds or runs them. Treat them like a query that does not parse.
logger.debug("Could not run search query: " + e.getMessage());
searchresults = null;
parseError = e.getMessage() != null ? e.getMessage() : e.getClass().getName();
}
// don't need to close the reader, since we didn't do any writing!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.Rdn;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

Expand Down Expand Up @@ -153,7 +154,7 @@ public boolean authenticate(HttpServletRequest request) {
* @param ldapUser
* @return
*/
private String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
String qualifedDc = "";
for (String token : StringUtils.delimitedListToStringArray(ldapDc, ",")) {
if (!qualifedDc.isEmpty()) {
Expand All @@ -162,7 +163,9 @@ private String getQualifedDc(String ldapDc, String ldapOu, String ldapUser) {
qualifedDc += "dc=" + token;
}

return "uid=" + ldapUser + ", ou=" + ldapOu + "," + qualifedDc;
// escape the user name so it stays the uid value and cannot add or
// change other parts of the bind name
return "uid=" + Rdn.escapeValue(ldapUser) + ", ou=" + ldapOu + "," + qualifedDc;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public WeblogFeedRequest(HttpServletRequest request)
this.page = parsePageNum(request.getParameter("page"));

if(request.getParameter("q") != null && !request.getParameter("q").isBlank()) {
this.term = URLUtilities.decode(request.getParameter("q"));
this.term = WeblogSearchRequest.capQuery(URLUtilities.decode(request.getParameter("q")));
}

if(this.tags != null && !this.tags.isEmpty() && this.weblogCategoryName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class WeblogSearchRequest extends WeblogRequest {
private static Log log = LogFactory.getLog(WeblogSearchRequest.class);

public static final String SEARCH_SERVLET = "/roller-ui/rendering/search";

/** Longest search query kept, plenty for a person to type. */
public static final int MAX_QUERY_LENGTH = 256;

// lightweight attributes
private String query = null;
Expand Down Expand Up @@ -83,7 +86,7 @@ public WeblogSearchRequest(HttpServletRequest request)
* cat - limit results to a certain weblogCategoryName
*/
if(request.getParameter("q") != null && !request.getParameter("q").isBlank()) {
this.query = request.getParameter("q");
this.query = capQuery(request.getParameter("q"));
}

this.pageNum = parsePageNum(request.getParameter("page"));
Expand All @@ -94,6 +97,48 @@ public WeblogSearchRequest(HttpServletRequest request)
}
}

/**
* Keeps the first MAX_QUERY_LENGTH characters of a search query, so one
* request cannot hand the query parser unbounded work, such as thousands
* of nested parentheses. Leading and trailing whitespace doesn't count.
* Does not split a surrogate pair, and drops the opening quote of a
* phrase, or an escape character, that the cap cuts off.
*/
public static String capQuery(String query) {
if (query == null) {
return null;
}
query = query.strip();
if (query.length() <= MAX_QUERY_LENGTH) {
return query;
}
int end = MAX_QUERY_LENGTH;
if (Character.isHighSurrogate(query.charAt(end - 1))) {
end--;
}
String capped = query.substring(0, end);
// find a quote whose phrase the cap cut off; an escaped quote doesn't
// start or end a phrase
int openQuote = -1;
for (int i = 0; i < capped.length(); i++) {
char c = capped.charAt(i);
if (c == '\\') {
if (i == capped.length() - 1) {
// the cap cut off the escaped character
capped = capped.substring(0, i);
}
i++;
} else if (c == '"') {
openQuote = openQuote < 0 ? i : -1;
}
}
// drop it, so the rest still parses
if (openQuote >= 0) {
capped = capped.substring(0, openQuote) + capped.substring(openQuote + 1);
}
return capped;
}

public String getQuery() {
return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public String decline() {
WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
Weblog weblog = wmgr.getWeblog(getInviteId());
String handle = weblog.getHandle();
// a page loaded before the invitation was accepted still offers
// to decline it
if (umgr.getWeblogPermission(weblog, getAuthenticatedUser()) != null) {
addError("yourWebsites.declineMember", handle);
return DONE;
}
// TODO ROLLER_2.0: notify inviter that invitee has declined invitation
// TODO EXCEPTIONS: better exception handling here
umgr.declineWeblogPermission(weblog, getAuthenticatedUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public String execute() {
}

public String save() {
// The federated identity (issuer#subject) decides which account an
// OIDC login opens, so only the OIDC login code sets it. Use the stored
// value, whatever the request carries, for the checks below.
getBean().setOpenIdUrl(getAuthenticatedUser().getOpenIdUrl());

myValidate();

if (!hasActionErrors()) {
Expand All @@ -79,20 +84,6 @@ public String save() {
// copy updated attributes
getBean().copyTo(existingUser);

if (StringUtils.isNotEmpty(getBean().getOpenIdUrl())) {
try {
String openidurl = getBean().getOpenIdUrl();
if (openidurl != null && openidurl.endsWith("/")) {
openidurl = openidurl.substring(0, openidurl.length() - 1);
}
existingUser.setOpenIdUrl(openidurl);
} catch (Exception ex) {
log.error("Unexpected error saving user OpenID URL", ex);
addError("generic.error.check.logs");
return INPUT;
}
}

if (authMethod == AuthMethod.DB_OIDC) {
if (StringUtils.isEmpty(existingUser.getPassword())
&& StringUtils.isEmpty(bean.getPasswordText())
Expand Down Expand Up @@ -139,11 +130,11 @@ public void myValidate() {
if (RollerPasswordEncoders.isExternalLoginMarker(getBean().getPasswordText())) {
addError("error.add.user.reservedPassword");
}
// check that passwords match if they were specified (w/StringUtils.equals, null == null)
if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) {
addError("userRegister.error.mismatchedPasswords");
}
if (StringUtils.isEmpty(getBean().getOpenIdUrl())) {
// check that passwords match if they were specified (w/StringUtils.equals, null == null)
if (!StringUtils.equals(getBean().getPasswordText(), getBean().getPasswordConfirm())) {
addError("userRegister.error.mismatchedPasswords");
}
if (authMethod == AuthMethod.OIDC) {
addError("userRegister.error.missingOpenID");
}
Expand All @@ -152,7 +143,7 @@ public void myValidate() {
try {
UserManager mgr = WebloggerFactory.getWeblogger().getUserManager();
User user = mgr.getUserByOpenIdUrl(bean.getOpenIdUrl());
if (user != null && !(user.getUserName().equals(bean.getUserName()))) {
if (user != null && !user.getUserName().equals(getAuthenticatedUser().getUserName())) {
addError("error.add.user.openIdInUse");
}
} catch (WebloggerException ex) {
Expand Down
Loading
Loading