Skip to content

[OID4VCI] Enforce DID uniqueness and restrict DID updates to admins#50112

Open
Awambeng wants to merge 3 commits into
keycloak:mainfrom
adorsys:issue-46524
Open

[OID4VCI] Enforce DID uniqueness and restrict DID updates to admins#50112
Awambeng wants to merge 3 commits into
keycloak:mainfrom
adorsys:issue-46524

Conversation

@Awambeng

Copy link
Copy Markdown
Contributor

This PR hardens the DID attribute management on user profiles to ensure DID uniqueness across users and prevent unauthorized modifications.

Key Changes

  • Added DuplicateDidValidator to enforce DID uniqueness across all users within a realm.
  • Restricted DID attribute updates to administrators only, while keeping the attribute visible in the account console.
  • Fixed DID pattern validation by using ignore.empty.value=true, allowing optional DID values while still enforcing valid DID format when provided.
  • Registered DuplicateDidValidator in META-INF/services/org.keycloak.validate.ValidatorFactory for automatic validator discovery.
  • Added test coverage to verify duplicate DID rejection and aligned test configuration with production behavior.

Closes #46524

Copilot AI review requested due to automatic review settings June 18, 2026 10:27
@Awambeng Awambeng requested a review from a team as a code owner June 18, 2026 10:27

Copilot AI 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.

Pull request overview

This PR strengthens management of the did user-profile attribute for OID4VCI by adding server-side uniqueness validation and tightening edit permissions, while keeping the attribute readable where appropriate.

Changes:

  • Added a new DuplicateDidValidator and registered it for automatic discovery.
  • Updated default user-profile metadata for the DID attribute (pattern validation + uniqueness + write restrictions).
  • Updated OID4VC tests/config to reflect the new DID behavior and added a duplicate-DID rejection test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/base/src/test/java/org/keycloak/tests/oid4vc/OID4VCUserDidAttributeTest.java Adds an integration test asserting duplicate DID updates are rejected with 409 CONFLICT.
tests/base/src/test/java/org/keycloak/tests/oid4vc/OID4VCIssuerEndpointTest.java Adjusts test user-profile configuration for DID permissions/validation.
services/src/main/resources/META-INF/services/org.keycloak.validate.ValidatorFactory Registers DuplicateDidValidator for validator discovery.
services/src/main/java/org/keycloak/userprofile/validator/DuplicateDidValidator.java Introduces DID uniqueness validator using attribute-based user search.
services/src/main/java/org/keycloak/userprofile/DeclarativeUserProfileProviderFactory.java Updates built-in DID attribute metadata (pattern validation, uniqueness validator, and write restrictions).

Awambeng added 2 commits June 18, 2026 12:37
- Add DuplicateDidValidator to prevent duplicate DID values across users,
restrict DID editing to admin-only in the account console, and fix
pattern validation to use ignore.empty.value for optional DID attribute.

Closes keycloak#46524

Signed-off-by: Awambeng Rodrick <awambengrodrick@gmail.com>
Signed-off-by: Awambeng Rodrick <awambengrodrick@gmail.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Signed-off-by: Awambeng Rodrick <awambengrodrick@gmail.com>

Copilot AI 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.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment on lines +47 to +65
KeycloakSession session = context.getSession();
RealmModel realm = session.getContext().getRealm();
UserModel user = UserProfileAttributeValidationContext.from(context).getAttributeContext().getUser();

// Skip validation if the DID value hasn't changed for an existing user
if (user != null && Objects.equals(user.getFirstAttribute(UserModel.DID), value)) {
return context;
}

// Search for existing users with the same DID attribute value
session.users().searchForUserByUserAttributeStream(realm, UserModel.DID, value)
.filter(existing -> user == null || !Objects.equals(existing.getId(), user.getId()))
.findFirst()
.ifPresent(existing -> {
context.addError(new ValidationError(ID, inputHint, Messages.DID_EXISTS)
.setStatusCode(Response.Status.CONFLICT));
});

return context;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OID4VCI] Review did attribute on user's profile

3 participants