Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
eafd7ad
fix(docs): only unlock accounts the lock script locked
mo-auto Nov 18, 2026
edef92e
fix(docs): keep admin changes made during a lock
mo-auto Nov 18, 2026
f37e4e7
fix(docs): match lock updatedAt exactly on unlock
mo-auto Nov 18, 2026
6f32447
feat(jans-orm): CAS on entries without a version
mo-auto Nov 18, 2026
bdd3e8c
feat: version jansPerson entries
mo-auto Nov 18, 2026
63e3085
fix(docs): use versioned writes in basic lock script
mo-auto Nov 18, 2026
bcc1c98
test(ci): read config-api user status key
mo-auto Nov 18, 2026
237c046
test(ci): check basic-lock unlock after expiry
mo-auto Nov 18, 2026
8b151eb
fix(docs): record stored updatedAt in lock marker
mo-auto Nov 18, 2026
78c28af
test(ci): patch user status with enum name
mo-auto Nov 19, 2026
6e63ec5
Merge branch 'pr-15743' into feat/basic-lock-cas
mo-auto Nov 19, 2026
5f26a93
feat(jans-orm): CAS plain merge on versioned entries
mo-auto Nov 19, 2026
5d19709
fix(docs): count and lock in one versioned write
mo-auto Nov 19, 2026
b76cfd2
docs: bump jansVersion in manual user updates
mo-auto Nov 19, 2026
645b264
fix(jans-auth-server): keep inherited User equality
mo-auto Nov 19, 2026
efbfd8d
refactor(jans-orm): simplify versioned merge loop
mo-auto Nov 19, 2026
e453c71
fix(jans-orm): keep first-read changes on merge retry
mo-auto Nov 19, 2026
23b4416
feat: version Casa, Link and SCIM person entities
mo-auto Nov 19, 2026
94b20cc
docs: quote jansVersion in PgSQL update, list versioned writers
mo-auto Nov 19, 2026
44a93b0
fix(jans-scim): drop version from read-only SimplePerson
mo-auto Nov 19, 2026
4f7f8a1
fix(jans-orm): fail merge instead of unchecked write
mo-auto Nov 19, 2026
66bcd99
docs: note stale-read writers can lift a lock early
mo-auto Nov 19, 2026
facfef4
docs: scope basic lock guarantee to versioned writers
mo-auto Nov 19, 2026
e07f66b
Merge branch 'main' of https://github.com/JanssenProject/jans into fe…
mo-auto Nov 19, 2026
f3115e9
Merge branch 'main' into feat/basic-lock-cas
yurem Nov 19, 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
4 changes: 2 additions & 2 deletions automation/ci/script_catalog/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def get_script(self, inum):
def delete_script(self, inum):
self.api("DELETE", f"/api/v1/config/scripts/{inum}", ok=(200, 204, 404))

def create_user(self, uid, password):
def create_user(self, uid, password, status="active"):
return self.api("POST", "/mgt/configuser", {
"userId": uid, "mail": f"{uid}@example.org", "displayName": uid, "givenName": uid,
"jansStatus": "active", "userPassword": password,
"jansStatus": status, "userPassword": password,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"customAttributes": [{"name": "sn", "multiValued": False, "values": [uid]}]})

def get_user(self, inum):
Expand Down
15 changes: 13 additions & 2 deletions automation/ci/script_catalog/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def behavior_tests(run, scripts):
assert not stalled, "jans-auth did not reload the behavior-test scripts"
time.sleep(RELOAD_INTERVAL + 5)

def new_user(label):
def new_user(label, status="active"):
uid = f"ci{run.tag}{label}"
user = aio.create_user(uid, password)
user = aio.create_user(uid, password, status)
run.users.append(user["inum"])
return uid, user["inum"]

Expand Down Expand Up @@ -320,9 +320,20 @@ def basic_lock():
assert status == "inactive", f"jansStatus={status!r} after 3 failed logins, expected 'inactive'"
assert not aio.login(client, lock_acr, lock_uid, password), "locked account still logs in"

def basic_lock_keeps_disabled():
off_uid, off_inum = new_user("lockoff", status="inactive")
client = aio.register_client()
for _ in range(4):
assert not aio.login(client, lock_acr, off_uid, "wrong-" + password), "wrong password accepted"
assert not aio.login(client, lock_acr, off_uid, password), "admin-disabled account logs in"
status = (aio.get_user(off_inum) or {}).get("jansStatus")
assert status == "inactive", f"jansStatus={status!r}: logins reactivated an admin-disabled account"

behavior(run, "ScriptCatalog.behavior", "introspection_custom_params.py returns public sid", introspection_sid)
behavior(run, "ScriptCatalog.behavior", "TokenExchange.java keeps built-in validation", token_exchange)
behavior(run, "ScriptCatalog.behavior", "BasicLockAccount locks after max attempts", basic_lock)
behavior(run, "ScriptCatalog.behavior", "BasicLockAccount never unlocks admin-disabled accounts",
basic_lock_keeps_disabled)


def client_authn_test(run, scripts):
Expand Down
9 changes: 9 additions & 0 deletions docs/janssen-server/reference/database/mysql-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Say we want to increase the size of `mail` field to 144. Do the following:<br>
* c. Ensure you restart services after DB schema modification


### Add user version column on upgrade
User updates are versioned through the `jansVersion` column of `jansPerson`. Container and Kubernetes
deployments add it automatically through the persistence loader. On a VM install, add it before
upgrading the Janssen services:
```
ALTER TABLE `jansdb`.`jansPerson` ADD COLUMN `jansVersion` BIGINT NULL DEFAULT NULL;
```
Existing rows keep a `NULL` version until their next update.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

### Add user in Jans admin group

* Search for inum of `JansGrp`
Expand Down
12 changes: 12 additions & 0 deletions docs/janssen-server/reference/database/pgsql-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ ALTER TABLE "jansPerson"
ADD COLUMN membership_level VARCHAR DEFAULT 'Basic';
```

## Add user version column on upgrade

User updates are versioned through the `jansVersion` column of `jansPerson`. Container and Kubernetes
deployments add it automatically through the persistence loader. On a VM install, add it before
upgrading the Janssen services:

```
ALTER TABLE "jansPerson" ADD COLUMN "jansVersion" BIGINT;
```

Existing rows keep a `NULL` version until their next update.

## Output column data into txt

If you want to output the data from a PostgreSQL table's column into a text file, you can use the `COPY` command. This command allows you to copy the contents of a table or query result into an external file. Here's how you can do it:
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,14 @@ This module has 2 properties:
Default value: 3
3) lock_expiration_time - Specify the time in seconds when lock will be expired
Default value: 180

While an account is locked, `invalid_login_count_attribute` holds `locked:<epoch millis>:<jansVersion>` instead of a
count. The script only unlocks inactive accounts carrying this marker that were not modified after the lock, so accounts
disabled by an administrator stay disabled, even if the administrator acted while the account was locked.

User writes are compare-and-set on the `jansVersion` attribute of `jansPerson`: a lock, unlock or counter update that
races another write re-reads the user and decides again, so concurrent logins and administrator changes are never
overwritten. Backends without versioned updates fall back to a plain update.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Upgrade note: accounts locked by a previous version of this script have no marker and are not unlocked when their
lock expires. An administrator must reactivate them.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,37 @@

import org.json.JSONArray;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.jans.as.model.exception.InvalidClaimException;
import io.jans.model.user.SimpleUser;
import io.jans.orm.annotation.AttributeName;
import io.jans.orm.annotation.DataEntry;
import io.jans.orm.annotation.ObjectClass;
import io.jans.orm.annotation.Version;

/**
* @author Yuriy Movchan Date: 06/11/2013
*/
@DataEntry
@ObjectClass(value = "jansPerson")
public class User extends SimpleUser {

Check warning on line 27 in jans-auth-server/common/src/main/java/io/jans/as/common/model/common/User.java

View check run for this annotation

SonarQubeCloud / [Jans authentication server parent] SonarCloud Code Analysis

Override the "equals" method in this class.

See more on https://sonarcloud.io/project/issues?id=JanssenProject_jans-auth-server&issues=AaHvXvo7RdtTDdCBayJG&open=AaHvXvo7RdtTDdCBayJG&pullRequest=15749

private static final long serialVersionUID = 6634191420188575733L;

@JsonIgnore
@Version
@AttributeName(name = "jansVersion", ignoreDuringUpdate = true)
private Long version;

public Long getVersion() {
return version;
}

public void setVersion(Long version) {
this.version = version;
}

public Object getAttribute(String attributeName, boolean optional, boolean multivalued) throws InvalidClaimException {
Object attribute = null;

Expand Down
3 changes: 2 additions & 1 deletion jans-linux-setup/jans_setup/schema/jans_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5460,7 +5460,8 @@
"jansStrongAuthPolicy",
"jansUnlinkedExternalUids",
"jansBackchannelDeviceRegistrationTkn",
"jansBackchannelUsrCode"
"jansBackchannelUsrCode",
"jansVersion"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
],
"must": [
"objectclass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ enum PERSITENCE_TYPES {ldap, couchbase, sql, spanner, hybrid};
* {@code @Version} value still equals the value held on {@code entry} at call time. On success,
* increments the stored version and writes the same new value back onto {@code entry}.
*
* <p>A null version on {@code entry} expects the stored entry to have no version attribute (an
* entry written before its class got {@code @Version}); the write then stores version 1. Load
* the entry with its version attribute, or the CAS fails against an existing stored version.</p>
*
* <p>Like {@link #merge(Object)}, this call pre-reads the entry's current attributes to build
* the diff. If the entry does not exist at all when the call begins, the backend's normal
* not-found behavior for {@code merge()} applies (e.g. {@code EntryPersistenceException}), not
Expand All @@ -80,7 +84,7 @@ enum PERSITENCE_TYPES {ldap, couchbase, sql, spanner, hybrid};
* call's own pre-read and its write.</p>
*
* @throws io.jans.orm.exception.MappingException if entry's class has more than one
* {@code @Version} field, or that field's current value on {@code entry} is null
* {@code @Version} field
* @throws io.jans.orm.exception.VersionMismatchException if the stored version no longer matches
* at the compare-and-swap (another writer updated first, or the entry was deleted after
* this call's own pre-read)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,19 +376,15 @@ public Void updateWithVersion(Object entry) {
throw new MappingException("Entry should has setter for property " + versionPropertyName);
}

Object expectedVersionObject = versionGetter.get(entry);
if (expectedVersionObject == null) {
throw new MappingException(String.format(
"Entry '%s' @Version field must be initialized -- call persist() or find() first", entryClass));
}

Class<?> parameterType = ReflectHelper.getSetterType(versionSetter);
if (!(parameterType.equals(Long.class) || parameterType.equals(Long.TYPE))) {
throw new MappingException(String.format(
"Entry '%s' @Version field must be Long/long", entryClass));
}

long expectedVersionValue = ((Long) expectedVersionObject).longValue();
// Null means the stored entry has no version yet (written before the class got @Version, or by
// a class without it): the CAS then expects the attribute to be absent
Long expectedVersionValue = (Long) versionGetter.get(entry);

boolean forceUpdate = isUseEntryForceUpdate(entryClass);
if (forceUpdate) {
Expand Down Expand Up @@ -424,14 +420,14 @@ public Void updateWithVersion(Object entry) {

String versionAttributeName = getVersionAttributeName(entryClass, versionPropertyName, propertiesAnnotations);

long newVersionValue = expectedVersionValue + 1;
long newVersionValue = (expectedVersionValue == null ? 0L : expectedVersionValue.longValue()) + 1;
applyVersionBump(attributeDataModifications, versionAttributeName, newVersionValue);

boolean updated = mergeWithVersion(dnValue.toString(), objectClasses, attributeDataModifications, expirationValue,
versionAttributeName, Long.valueOf(expectedVersionValue), Long.valueOf(newVersionValue));
versionAttributeName, expectedVersionValue, Long.valueOf(newVersionValue));

if (!updated) {
throw new VersionMismatchException(dnValue.toString(), Long.valueOf(expectedVersionValue));
throw new VersionMismatchException(dnValue.toString(), expectedVersionValue);
}

if (isValidateAfterUpdate()) {
Expand Down Expand Up @@ -464,7 +460,8 @@ public Void updateWithVersion(Object entry) {
}

/**
* Per-backend hook for {@link #updateWithVersion(Object)}. Concrete with a default throw (not
* Per-backend hook for {@link #updateWithVersion(Object)}. A null {@code expectedVersionValue} must
* match only an entry that has no stored version attribute. Concrete with a default throw (not
* abstract) so every existing backend subclass keeps compiling before its own CAS support lands.
*/
protected boolean mergeWithVersion(String dn, String[] objectClasses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package io.jans.orm.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -102,15 +103,37 @@ public void updateWithVersionOnEntityWithZeroVersionFieldsThrowsUnsupportedOpera
}

@Test
public void updateWithVersionWithNullVersionFieldThrowsMappingException() {
public void updateWithVersionWithNullVersionExpectsAbsentVersionAndStoresOne() {
VersioningFakeVersionEntryManager entryManager = new VersioningFakeVersionEntryManager();
entryManager.storage.put("o=test", new ArrayList<>(List.of(new AttributeData("uid", "same"))));

VersionedEntry entry = new VersionedEntry();
entry.setDn("o=test");
entry.setUid("same");
entry.setVersion(null);

assertThrows(MappingException.class, () -> entryManager.updateWithVersion(entry));
entryManager.updateWithVersion(entry);

assertNull(entryManager.lastExpectedVersionValue);
assertEquals(Long.valueOf(1L), entryManager.lastNewVersionValue);
assertEquals(Long.valueOf(1L), entry.getVersion());
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}

@Test
public void updateWithVersionWithNullVersionOnStaleReadThrowsVersionMismatchException() {
VersioningFakeVersionEntryManager entryManager = new VersioningFakeVersionEntryManager();
entryManager.mergeWithVersionResult = false;
entryManager.storage.put("o=test", new ArrayList<>(List.of(new AttributeData("uid", "same"))));

VersionedEntry entry = new VersionedEntry();
entry.setDn("o=test");
entry.setUid("same");
entry.setVersion(null);

VersionMismatchException ex = assertThrows(VersionMismatchException.class,
() -> entryManager.updateWithVersion(entry));
assertNull(ex.getExpectedVersion());
assertNull(entry.getVersion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,9 @@ private boolean updateEntryWithVersionImpl(String dn, List<Modification> modific

// Filter.createEqualityFilter() RFC-4515-escapes the assertion value for us, so this is
// safe even if the version type ever changes to something needing escaping.
Filter assertionFilter = Filter.createEqualityFilter(versionAttributeName, String.valueOf(expectedVersionValue));
Filter assertionFilter = (expectedVersionValue == null)
? Filter.createNOTFilter(Filter.createPresenceFilter(versionAttributeName))
: Filter.createEqualityFilter(versionAttributeName, String.valueOf(expectedVersionValue));

ModifyRequest modifyRequest = new ModifyRequest(dn, modifications);
modifyRequest.addControl(new AssertionRequestControl(assertionFilter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,9 @@ private boolean updateEntryWithVersionImpl(TableMapping tableMapping, String key

Predicate docIdPredicate = ExpressionUtils.eq(Expressions.stringPath(SqlOperationService.DOC_ID),
Expressions.constant(key));
Predicate versionPredicate = ExpressionUtils.eq(Expressions.path(Object.class, versionAttributeName),
Expressions.constant(expectedVersionValue));
Path<Object> versionPath = Expressions.path(Object.class, versionAttributeName);
Predicate versionPredicate = (expectedVersionValue == null) ? ExpressionUtils.isNull(versionPath)
: ExpressionUtils.eq(versionPath, Expressions.constant(expectedVersionValue));
Predicate whereExp = ExpressionUtils.allOf(docIdPredicate, versionPredicate);

long rowInserted = sqlUpdateQuery.where(whereExp).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class ScimCustomPerson extends Entry implements Serializable {
@AttributeName(name = "jansPPID")
private List<String> ppid;

@Version
@AttributeName(name = "jansVersion", ignoreDuringUpdate = true)
private Long version;

@AttributesList(name = "name", value = "values", multiValued = "multiValued", sortByName = true, attributesConfiguration = {
@AttributeName(name = "inum", ignoreDuringUpdate = true),
@AttributeName(name = "uid"),
Expand All @@ -49,6 +53,14 @@ public Date getCreationDate() {
return creationDate;
}

public Long getVersion() {
return version;
}

public void setVersion(Long version) {
this.version = version;
}

public String getDisplayName() {
return getAttribute("displayName");
}
Expand Down
Loading