Skip to content

Configure Spring Security in Java instead of security.xml - #300

Open
mraible wants to merge 15 commits into
apache:masterfrom
mraible:java-security-config
Open

mraible wants to merge 15 commits into
apache:masterfrom
mraible:java-security-config

Conversation

@mraible

@mraible mraible commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Replaces WEB-INF/security.xml with a Java SecurityConfig, loaded by the annotation-based web application context that web.xml now sets up. It removes a file admins edit, so it belongs in the major release, and Spring Security 7's MFA support is only available through Java config, which we want for 7.1.

The filter chain keeps the same URL rules, form login, OpenID Connect login, remember-me, security headers and saved request after login. Roller's own static files (/images, /theme, /webjars, /roller-ui/styles, /roller-ui/scripts, /roller-ui/images, /roller-ui/theme) skip the chain, so they can be cached; each is under a reserved name. security.xml listed /scripts and /styles too, which don't exist at the root.

This also fixes the login page's "Remember me" checkbox. It was named _spring_security_remember_me, Spring Security 3's parameter, while Roller's remember-me services read Spring's default, remember-me, so ticking it set no cookie. That was broken with security.xml too. SecurityConfigTest reads the checkbox name from Login.jsp, so it fails if the two disagree again. "Remember me" isn't offered with LDAP login, since a remembered login is checked against Roller's database only and would outlive a change to the directory account; Roller's old LDAP signature override was never called by Spring Security 7 and is removed.

One deliberate change: the login form now needs Spring Security's CSRF token. Roller protects its own forms with the salt that LoadSaltFilter and ValidateSaltFilter check on every POST under /roller-ui, so Spring's CSRF protection stays off elsewhere, as it was in security.xml. The login form posts to /roller_j_security_check, outside /roller-ui, so nothing protected it. SecurityConfig now requires the token for that POST only, and Login.jsp sends it. The token is created only when the login page asks for it, so other pages still don't start a session. A login posted without a valid token, for example from a login page left open past the session timeout, goes back to the login page with "The login page expired. Please try again." CHANGES notes that scripts posting straight to the login URL need to send the token.

  • SecurityConfigTest sends requests through the chain built from SecurityConfig. Its table was recorded from security.xml first, before the login CSRF change. The two configurations gave the same status, redirect, response headers and session behaviour for every request, including FORWARD and ERROR dispatches, the saved request after login and the default request firewall, except one: with remember-me off, a failed login no longer sends a header clearing a remember-me cookie that was never set. It also covers overlapping /** and /fam/** rules on a weblog's public and rendering addresses.
  • A second deliberate change: only GET requests are saved for the return after login (Spring's default once CSRF is configured). security.xml saved any method, so after logging in, a form submitted with an expired session was sent back to its address with the old submission, which Roller's salt check refused with an "Unexpected Exception" page (RC1 does this too). The login now goes to the start page instead, and CHANGES has a bug-fix entry.
  • RollerContext no longer looks up beans by the names the XML namespace generated (DaoAuthenticationProvider#0, _formLoginEntryPoint and the authentication manager). SecurityConfig sets the password encoder, the HTTPS-only login entry point (securelogin.enabled) and remember-me (rememberme.enabled) from roller.properties, and each of these has a test. The encoder factory is RollerPasswordEncoders, and RollerContext.getPasswordEncoder() returns the same instance the login provider uses, which also upgrades passwords stored with an older encoding at login (Upgrade passwords stored with an older encoding at login #301).
  • RollerRememberMeAuthenticationProvider is removed. rememberMe() creates a provider with the remember-me services' key, which is the key Roller's provider used.

For sites that edited security.xml:

  • Roller refuses to start while a WEB-INF/security.xml is still in place, with a message in Roller's log saying where its settings went, so a customized copy isn't ignored without notice.
  • LDAP is set with authentication.method=ldap and new users.ldap.url, users.ldap.managerDn, users.ldap.managerPassword, users.ldap.userSearchBase, users.ldap.userSearchFilter and users.ldap.defaultRole properties, which map one-to-one to the beans the XML asked admins to uncomment. A blank users.ldap.defaultRole gives directory users only their Roller roles. Directory connections time out (users.ldap.connectTimeout, users.ldap.readTimeout), and other JNDI settings are users.ldap.env.<name> properties. As with the XML, LDAP replaces the database login; a test checks that the directory is the only provider that checks passwords.
  • URL rules, such as a private weblog for one role, are security.access.<path>=<roles> properties, matched without regard to case. They add to Roller's own rules (a request has to pass both, so a broad rule can't open the admin pages), the most specific matching rule applies, and they check the paths visitors request, not Roller's internal forwards to JSPs and servlets. A weblog's rendering addresses (/roller-ui/rendering/<servlet>/<handle>/... for pages, feeds, resources, media files, search, RSD and comments) are checked against the rules for the weblog's own path, and the most specific of those decides, so with /**=member and /fam/**=family a family user can read /roller-ui/rendering/page/fam/... just as they can read /fam/.... For media files this relies on Serve a media file only at its own weblog's address #308, now merged, which serves a media file only at its own weblog's address. The login page, the login and OAuth2 endpoints, logout and the files the login page loads are left out of them, and so are the install, upgrade and first-registration pages while Roller is being set up, so a rule for /** doesn't lock everyone out. webjars and oauth2 join the reserved names, as theme already was, and creating a weblog with a reserved handle is refused. A rule whose path can't be parsed stops the start with a message naming the property.
  • CHANGES has entries under "Behaviour changes worth reading before upgrading", and the install guide describes all of this. The user guide doesn't cover it, so it doesn't change.

Testing:

  • mvn test passes.
  • On a copy of a production site (Tomcat 11 behind httpd, 7.0.0 RC1 data): a private weblog with two security.access properties gave anonymous visitors the login page, non-members 403 and members 200 for the weblog and its feed in any casing; the more specific of two overlapping rules decided; a leftover security.xml stopped the start with the message above; and a 1,741-address sample matched RC1 in status, Location, cookie names, Content-Type and Cache-Control. A /** rule was then checked on jetty:run: the login page renders and other pages ask for a login.
  • The Playwright UI tests passed against jetty:run with database login and against the Docker Compose stack (Tomcat, PostgreSQL, Keycloak) with db-oidc; CI runs the db, db-oidc and oidc suites.
  • LDAP login wasn't tested against a directory server; the project's stacks don't include one.

A further review pass added these fixes:

  • A security.access rule for one part of a weblog, such as /fam/mediaresource/** or /fam/feed/**, also covers that part's internal rendering address, and a line break in the address no longer skips the rule.
  • A weblog whose handle is a reserved name is hidden whatever case the URL uses.

@mraible

mraible commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Tested against a real site's data: master with this PR merged (84b6dc3), behind Apache httpd and a TLS-terminating proxy, with two security.access properties replacing the site's hand edit of security.xml to keep one weblog private for a role. All logins below were scripted with curl, not a browser.

  • Private weblog: anonymous requests get 302 to the login page, a user without the role gets 403, and a member gets 200, for the weblog and its feed. The rules apply to other casings of its path as well.
  • Proxy: redirects to the login page and back to the saved request keep the forwarded scheme and host, and JSESSIONID is Secure and HttpOnly.
  • Login form: a POST to /roller_j_security_check without _csrf gets 403. With the token read from login.rol in the same session, member and non-member logins work. A wrong password gets 302 to login.rol?error=true without the remember-me cookie-clearing header that RC1 sends, the one expected difference.
  • Sessions and caching: ten anonymous pages and feeds (home, entry pages with comment forms, Atom and RSS feeds, tag, category, search) set no cookie, and weblog pages and feeds still send Last-Modified without Cache-Control.
  • Comments: anonymous comment preview and post aren't refused by the security chain and set no cookie.
  • Baseline: all 18,597 addresses from the site's baseline matched RC1 in status, Location, cookie names, Content-Type and Cache-Control on 0ced33c, and a 1,741-address sample matched again on 84b6dc3.

Not covered: remember-me with the box ticked, logout, AtomPub, XML-RPC, OIDC and a browser.

@mraible
mraible force-pushed the java-security-config branch from b96e88c to 56f6948 Compare November 17, 2026 01:38

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR-Review: 1 inline comment posted.

SecurityConfig replaces WEB-INF/security.xml and is loaded by the web application context that web.xml sets up. The filter chain keeps the same URL rules, form login, OpenID Connect login, remember-me, headers and static-file exceptions. A new SecurityConfigTest sends requests through the chain; its table was recorded from security.xml, and the two configurations gave the same result for every request except one: with remember-me off, a failed login no longer clears a remember-me cookie that was never set.

RollerContext no longer looks up beans by the names the XML namespace generated. SecurityConfig sets the password encoder, the HTTPS-only login entry point and remember-me from roller.properties, and RollerContext shares the same encoder, now built by RollerPasswordEncoders.

LDAP login is configured with new users.ldap.* properties instead of uncommented beans, and sites can add URL rules with security.access.<path>=<roles> properties, matched without regard to case. CHANGES and the install guide describe both.
Roller protects its own forms with the salt that LoadSaltFilter and ValidateSaltFilter check on every POST under /roller-ui, so Spring's CSRF protection stays off, as it was in security.xml. The login form posts to /roller_j_security_check, outside /roller-ui, so nothing protected it. SecurityConfig now requires Spring's CSRF token for that POST only, and Login.jsp sends it. The token is created only when the login page asks for it, so other pages still don't start a session.

SecurityConfigTest logs in with the token from the login page and checks that a login post without it gets 403. CHANGES notes that scripts posting straight to /roller_j_security_check need the token.
The checkbox was still named _spring_security_remember_me, Spring Security 3's parameter. RollerRememberMeServices uses Spring's default parameter, remember-me, so ticking the box set no cookie on sites with rememberme.enabled=true. It also failed with security.xml. SecurityConfigTest now reads the checkbox name from Login.jsp, so the test fails if the page and the remember-me services disagree.
Rebased on apache#301, SecurityConfig gives the database login provider the user service as its UserDetailsPasswordService. SecurityConfigTest logs in through the filter chain as a user with an unsalted SHA-1 hash and checks that the stored password becomes {bcrypt}.
A login posted without a valid CSRF token, for example from a login page left open past the session timeout, from a second tab, or after a server restart, now redirects to the login page with a message to try again instead of showing the access-denied page. Other refused requests still get the 403 page.
…onfig

Follow-ups from a review of the Java configuration:

- security.access.* rules now add to Roller's own rules instead of replacing them: a request has to pass both, so a broad rule such as /**=member can't open the admin or authoring pages to other roles. The login page, the login and OAuth2 endpoints, logout and the files the login page loads are left out of these rules, so a rule for /** no longer locks everyone out.
- When several rules match, the most specific one applies (PathPattern specificity instead of pattern length), and a rule with a path that can't be parsed stops the start with a message naming the property.
- The request that needed a login is saved whatever its method, as security.xml did; configuring CSRF had made Spring save only GET requests.
- Roller refuses to start while a WEB-INF/security.xml is still in place, so a customized copy isn't ignored without notice.
- A blank users.ldap.defaultRole gives directory users only their Roller roles instead of stopping the start.
- The remember-me signature override uses the method Spring Security 7 calls, and a directory user without a Roller account who ticks "Remember me" is logged in without a cookie instead of being shown a wrong-password message.
- The LDAP test checks that the directory is the only provider that checks passwords, and the install guide and CHANGES describe the access-denied page, the LDAP-only login and the new rules.
… a POST after login

- security.access.* rules now check REQUEST dispatches only, the paths visitors ask for. Roller forwards the login action to its JSP, and a rule for /** caught that forward, so the login page redirected to itself. Roller's own rules still apply to forwards as before.
- The request cache is back to Spring's default, which saves only GET requests. Saving any method, as security.xml did, sent the browser back to a form's address after login with the old submission, which Roller's salt check refuses with an error page.
- webjars and oauth2 are reserved like theme, so no weblog handle can share a path that security.access rules leave out.
- The leftover security.xml message is also logged to Roller's log.
- "Remember me" isn't offered with LDAP login: the cookie is checked against Roller's database only, so it would keep working after the directory account changed or was removed.
- security.access.* rules leave the install, upgrade, bootstrap-token and first-registration pages alone while Roller is being set up, so a rule for /** can't block installing or upgrading.
- The login page's stylesheet and images (/roller-ui/styles, /roller-ui/images) are left out of the rules too.
- Only /images skips the security filter chain; there are no /scripts or /styles directories at the root.
- New weblogs can't take a reserved handle such as webjars or oauth2.
- LDAP connections have connect and read timeouts (users.ldap.connectTimeout, users.ldap.readTimeout), and other JNDI settings can be given as users.ldap.env.* properties.
- Each rule's authority check is built once, and the roller.properties comment says the rules add to Roller's own.
Roller renders a weblog's pages, feeds, resources, search results and comments at /roller-ui/rendering/<servlet>/<handle>/... as well as at /<handle>/.... security.access rules now apply to the first as if it were the second, so a rule for a weblog covers both. Uploaded media files are served by their ID, so the install guide notes that a rule doesn't hide a file from someone who has its address.
@mraible
mraible force-pushed the java-security-config branch from 0a7cb55 to 2b8eece Compare November 17, 2026 18:16
…ached

- A weblog's media addresses under /roller-ui/rendering/media-resources/<handle>/ are checked as if they were the weblog's own path, like its pages and feeds. With apache#308, a media file is only served at its own weblog's address, so the install guide no longer needs its note about media files.
- Roller's own static files (/images, /theme, /webjars, /roller-ui/styles, /roller-ui/scripts, /roller-ui/images) skip the security filter chain, so they're served without Cache-Control: no-store and can be cached. Each path is under a reserved name.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 0b95fdc0b: The Java configuration and tests cover the main login and URL behavior. Two verified gaps remain in how site access rules apply to rendering paths.

…d serve Roller UI theme files without the security chain

A request under /roller-ui/rendering/<servlet>/<handle>/ is now checked only against the most specific security.access rule for the weblog's own path, so with /**=member and /fam/**=family a family user can read /roller-ui/rendering/page/fam/... just as they can read /fam/.... A new test covers those overlapping rules on public and rendering URLs.

/roller-ui/theme/** joins the static paths that skip the security filter chain, so the front-page theme images can be cached and load without a login when a rule covers /**.
@mraible
mraible requested a review from snoopdave November 18, 2026 04:15
@mraible
mraible marked this pull request as draft November 19, 2026 01:29
@mraible
mraible marked this pull request as ready for review November 19, 2026 02:06
… address

A rendering address such as /roller-ui/rendering/media-resources/fam/abc was matched as /fam/abc, so a rule for /fam/mediaresource/**, /fam/feed/**, /fam/resource/**, /fam/search or /fam/rsd did not apply to it. The path is now rebuilt the way WeblogRequestMapper maps it, including a locale before the feed or search element.

A rendering path holding a line break the request firewall lets through, such as U+0085, no longer skips the weblog's rule.

WeblogRequestMapper now ignores case when it checks a handle against the reserved names, so a weblog named webjars or oauth2 is not shown at /WebJars/ on a database that ignores case.

SecurityConfigTest now removes a property that was unset before a test set it more than once.

@snoopdave snoopdave left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 035144498: The current diff covers the earlier review points. I found no new verified defects in the code or tests reviewed; this was a read-only review, with no build run.

Earlier comments: 4 of 4 resolved.

No new issues found.

# Conflicts:
#	app/src/main/java/org/apache/roller/weblogger/ui/core/security/RollerRememberMeServices.java
…emoves

Spring Security 7 never called RollerRememberMeServices.makeTokenSignature, so this change removes the override and doesn't offer remember-me with LDAP login. The test that came from master with the merge exercised that override.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants