-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...es-userprovider/src/main/java/dasniko/keycloak/user/flintstones/UserModelTransaction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dasniko.keycloak.user.flintstones; | ||
|
||
import org.keycloak.models.AbstractKeycloakTransaction; | ||
import org.keycloak.models.UserModel; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public class UserModelTransaction extends AbstractKeycloakTransaction { | ||
|
||
private final Consumer<UserModel> userConsumer; | ||
private final Map<String, UserModel> loadedUsers = new HashMap<>(); | ||
|
||
public UserModelTransaction(Consumer<UserModel> userConsumer) { | ||
this.userConsumer = userConsumer; | ||
} | ||
|
||
public void addUser(String identifier, UserModel userModel) { | ||
loadedUsers.put(identifier, userModel); | ||
} | ||
|
||
public UserModel findUser(String identifier) { | ||
return loadedUsers.get(identifier); | ||
} | ||
|
||
@Override | ||
protected void commitImpl() { | ||
loadedUsers.values().forEach(userConsumer); | ||
} | ||
|
||
@Override | ||
protected void rollbackImpl() { | ||
// maybe do some more checks on loadedUsers... | ||
loadedUsers.clear(); | ||
} | ||
} |