Skip to content

Commit

Permalink
Check for unique subject id
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeorgilakis-grnet committed Oct 23, 2024
1 parent 725c2da commit cc1cbc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

It is based on Keycloak version 22.

## [1.1.0] - 2024-10-23

### Added
- Check for unique subject id

## [1.0.0] - 2024-10-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.keycloak</groupId>
<artifactId>keycloak-idp-subjectId-mapper</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>

<properties>
<keycloak.version>22.0.5</keycloak.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;


Expand Down Expand Up @@ -67,7 +68,7 @@ public class SubjectIdIdPMapper extends AbstractIdentityProviderMapper {

}

public static final String PROVIDER_ID = "subject-id-idp-mapper";
public static final String PROVIDER_ID = "subject-id-attribute-mapper";

@Override
public boolean supportsSyncMode(IdentityProviderSyncMode syncMode) {
Expand Down Expand Up @@ -105,10 +106,14 @@ public void preprocessFederatedIdentity(KeycloakSession session, RealmModel real

String scope = mapperModel.getConfig().getOrDefault(SCOPE, DEFAULT_SCOPE);
String attribute = mapperModel.getConfig().getOrDefault(USER_ATTRIBUTE, USERNAME);
String value = KeycloakModelUtils.generateId() + "@" + scope;
while (session.users().searchForUserStream(realm, Map.of(attribute,value,UserModel.EXACT, "true")).count() >0) {
value = KeycloakModelUtils.generateId() + "@" + scope;
}
if (USERNAME.equalsIgnoreCase(attribute)) {
context.setUsername(KeycloakModelUtils.generateId() + "@" + scope);
context.setUsername(value);
} else {
context.setUserAttribute(attribute, KeycloakModelUtils.generateId() + "@" + scope);
context.setUserAttribute(attribute, value);
}
}

Expand Down

0 comments on commit cc1cbc9

Please sign in to comment.