Convert authentication session entities into interface
This commit is contained in:
parent
ebfc24d6c1
commit
6c64d465ea
7 changed files with 128 additions and 242 deletions
|
@ -102,7 +102,7 @@ public class Util {
|
||||||
public static String singularToPlural(String word) {
|
public static String singularToPlural(String word) {
|
||||||
if (word.endsWith("y")) {
|
if (word.endsWith("y")) {
|
||||||
return word.substring(0, word.length() -1) + "ies";
|
return word.substring(0, word.length() -1) + "ies";
|
||||||
} else if (word.endsWith("ss")) {
|
} else if (word.endsWith("s")) {
|
||||||
return word + "es";
|
return word + "es";
|
||||||
} else {
|
} else {
|
||||||
return word + "s";
|
return word + "s";
|
||||||
|
@ -112,7 +112,7 @@ public class Util {
|
||||||
public static String pluralToSingular(String word) {
|
public static String pluralToSingular(String word) {
|
||||||
if (word.endsWith("ies")) {
|
if (word.endsWith("ies")) {
|
||||||
return word.substring(0, word.length() - 3) + "y";
|
return word.substring(0, word.length() - 3) + "y";
|
||||||
} else if (word.endsWith("sses")) {
|
} else if (word.endsWith("ses")) {
|
||||||
return word.substring(0, word.length() - 2);
|
return word.substring(0, word.length() - 2);
|
||||||
} else {
|
} else {
|
||||||
return word.endsWith("s") ? word.substring(0, word.length() - 1) : word;
|
return word.endsWith("s") ? word.substring(0, word.length() - 1) : word;
|
||||||
|
|
|
@ -23,11 +23,10 @@ import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.sessions.AuthenticationSessionModel;
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
import org.keycloak.sessions.RootAuthenticationSessionModel;
|
import org.keycloak.sessions.RootAuthenticationSessionModel;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
||||||
|
@ -59,20 +58,20 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, ExecutionStatus> getExecutionStatus() {
|
public Map<String, ExecutionStatus> getExecutionStatus() {
|
||||||
return entity.getExecutionStatus();
|
Map<String, ExecutionStatus> executionStatus = entity.getExecutionStatuses();
|
||||||
|
return executionStatus == null ? Collections.emptyMap() : Collections.unmodifiableMap(executionStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setExecutionStatus(String authenticator, ExecutionStatus status) {
|
public void setExecutionStatus(String authenticator, ExecutionStatus status) {
|
||||||
Objects.requireNonNull(authenticator, "The provided authenticator can't be null!");
|
Objects.requireNonNull(authenticator, "The provided authenticator can't be null!");
|
||||||
Objects.requireNonNull(status, "The provided execution status can't be null!");
|
Objects.requireNonNull(status, "The provided execution status can't be null!");
|
||||||
parent.setUpdated(!Objects.equals(entity.getExecutionStatus().put(authenticator, status), status));
|
this.entity.setExecutionStatus(authenticator, status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearExecutionStatus() {
|
public void clearExecutionStatus() {
|
||||||
parent.setUpdated(!entity.getExecutionStatus().isEmpty());
|
entity.setExecutionStatuses(null);
|
||||||
entity.getExecutionStatus().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,25 +82,25 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
@Override
|
@Override
|
||||||
public void setAuthenticatedUser(UserModel user) {
|
public void setAuthenticatedUser(UserModel user) {
|
||||||
String userId = (user == null) ? null : user.getId();
|
String userId = (user == null) ? null : user.getId();
|
||||||
parent.setUpdated(!Objects.equals(userId, entity.getAuthUserId()));
|
|
||||||
entity.setAuthUserId(userId);
|
entity.setAuthUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getRequiredActions() {
|
public Set<String> getRequiredActions() {
|
||||||
return new HashSet<>(entity.getRequiredActions());
|
Set<String> requiredActions = entity.getRequiredActions();
|
||||||
|
return requiredActions == null ? Collections.emptySet() : Collections.unmodifiableSet(requiredActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addRequiredAction(String action) {
|
public void addRequiredAction(String action) {
|
||||||
Objects.requireNonNull(action, "The provided action can't be null!");
|
Objects.requireNonNull(action, "The provided action can't be null!");
|
||||||
parent.setUpdated(entity.getRequiredActions().add(action));
|
entity.addRequiredAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeRequiredAction(String action) {
|
public void removeRequiredAction(String action) {
|
||||||
Objects.requireNonNull(action, "The provided action can't be null!");
|
Objects.requireNonNull(action, "The provided action can't be null!");
|
||||||
parent.setUpdated(entity.getRequiredActions().remove(action));
|
entity.removeRequiredAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,99 +117,77 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUserSessionNote(String name, String value) {
|
public void setUserSessionNote(String name, String value) {
|
||||||
if (name != null) {
|
entity.setUserSessionNote(name, value);
|
||||||
if (value == null) {
|
|
||||||
parent.setUpdated(entity.getUserSessionNotes().remove(name) != null);
|
|
||||||
} else {
|
|
||||||
parent.setUpdated(!Objects.equals(entity.getUserSessionNotes().put(name, value), value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getUserSessionNotes() {
|
public Map<String, String> getUserSessionNotes() {
|
||||||
return new ConcurrentHashMap<>(entity.getUserSessionNotes());
|
Map<String, String> userSessionNotes = entity.getUserSessionNotes();
|
||||||
|
return userSessionNotes == null ? Collections.emptyMap() : Collections.unmodifiableMap(userSessionNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearUserSessionNotes() {
|
public void clearUserSessionNotes() {
|
||||||
parent.setUpdated(!entity.getUserSessionNotes().isEmpty());
|
entity.setUserSessionNotes(null);
|
||||||
entity.getUserSessionNotes().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAuthNote(String name) {
|
public String getAuthNote(String name) {
|
||||||
return (name != null) ? entity.getAuthNotes().get(name) : null;
|
Map<String, String> authNotes = entity.getAuthNotes();
|
||||||
|
return (name != null && authNotes != null) ? authNotes.get(name) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAuthNote(String name, String value) {
|
public void setAuthNote(String name, String value) {
|
||||||
if (name != null) {
|
entity.setAuthNote(name, value);
|
||||||
if (value == null) {
|
|
||||||
parent.setUpdated(entity.getAuthNotes().remove(name) != null);
|
|
||||||
} else {
|
|
||||||
parent.setUpdated(!Objects.equals(entity.getAuthNotes().put(name, value), value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAuthNote(String name) {
|
public void removeAuthNote(String name) {
|
||||||
if (name != null) {
|
entity.removeAuthNote(name);
|
||||||
parent.setUpdated(entity.getAuthNotes().remove(name) != null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearAuthNotes() {
|
public void clearAuthNotes() {
|
||||||
parent.setUpdated(!entity.getAuthNotes().isEmpty());
|
entity.setAuthNotes(null);
|
||||||
entity.getAuthNotes().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClientNote(String name) {
|
public String getClientNote(String name) {
|
||||||
return (name != null) ? entity.getClientNotes().get(name) : null;
|
return (name != null) ? getClientNotes().get(name) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientNote(String name, String value) {
|
public void setClientNote(String name, String value) {
|
||||||
if (name != null) {
|
entity.setClientNote(name, value);
|
||||||
if (value == null) {
|
|
||||||
parent.setUpdated(entity.getClientNotes().remove(name) != null);
|
|
||||||
} else {
|
|
||||||
parent.setUpdated(!Objects.equals(entity.getClientNotes().put(name, value), value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeClientNote(String name) {
|
public void removeClientNote(String name) {
|
||||||
if (name != null) {
|
entity.removeClientNote(name);
|
||||||
parent.setUpdated(entity.getClientNotes().remove(name) != null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getClientNotes() {
|
public Map<String, String> getClientNotes() {
|
||||||
return new ConcurrentHashMap<>(entity.getClientNotes());
|
Map<String, String> clientNotes = entity.getClientNotes();
|
||||||
|
return clientNotes == null ? Collections.emptyMap() : Collections.unmodifiableMap(clientNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearClientNotes() {
|
public void clearClientNotes() {
|
||||||
parent.setUpdated(!entity.getClientNotes().isEmpty());
|
entity.setClientNotes(null);
|
||||||
entity.getClientNotes().clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getClientScopes() {
|
public Set<String> getClientScopes() {
|
||||||
return new HashSet<>(entity.getClientScopes());
|
Set<String> clientScopes = entity.getClientScopes();
|
||||||
|
return clientScopes == null ? Collections.emptySet() : Collections.unmodifiableSet(clientScopes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientScopes(Set<String> clientScopes) {
|
public void setClientScopes(Set<String> clientScopes) {
|
||||||
Objects.requireNonNull(clientScopes, "The provided client scopes set can't be null!");
|
Objects.requireNonNull(clientScopes, "The provided client scopes set can't be null!");
|
||||||
parent.setUpdated(!Objects.equals(entity.getClientScopes(), clientScopes));
|
entity.setClientScopes(clientScopes);
|
||||||
entity.setClientScopes(new HashSet<>(clientScopes));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -220,7 +197,6 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRedirectUri(String uri) {
|
public void setRedirectUri(String uri) {
|
||||||
parent.setUpdated(!Objects.equals(entity.getRedirectUri(), uri));
|
|
||||||
entity.setRedirectUri(uri);
|
entity.setRedirectUri(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +217,6 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAction(String action) {
|
public void setAction(String action) {
|
||||||
parent.setUpdated(!Objects.equals(entity.getAction(), action));
|
|
||||||
entity.setAction(action);
|
entity.setAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +227,6 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProtocol(String method) {
|
public void setProtocol(String method) {
|
||||||
parent.setUpdated(!Objects.equals(entity.getProtocol(), method));
|
|
||||||
entity.setProtocol(method);
|
entity.setProtocol(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,129 +16,62 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.models.map.authSession;
|
package org.keycloak.models.map.authSession;
|
||||||
|
|
||||||
|
import org.keycloak.models.map.annotations.GenerateEntityImplementations;
|
||||||
|
import org.keycloak.models.map.common.DeepCloner;
|
||||||
|
import org.keycloak.models.map.common.UpdatableEntity;
|
||||||
import org.keycloak.sessions.AuthenticationSessionModel;
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
||||||
*/
|
*/
|
||||||
public class MapAuthenticationSessionEntity {
|
@GenerateEntityImplementations
|
||||||
|
@DeepCloner.Root
|
||||||
|
public interface MapAuthenticationSessionEntity extends UpdatableEntity {
|
||||||
|
|
||||||
private String clientUUID;
|
Map<String, String> getUserSessionNotes();
|
||||||
|
void setUserSessionNotes(Map<String, String> userSessionNotes);
|
||||||
|
void setUserSessionNote(String name, String value);
|
||||||
|
|
||||||
private String authUserId;
|
String getClientUUID();
|
||||||
|
void setClientUUID(String clientUUID);
|
||||||
|
|
||||||
private int timestamp;
|
String getAuthUserId();
|
||||||
|
void setAuthUserId(String authUserId);
|
||||||
|
|
||||||
private String redirectUri;
|
Integer getTimestamp();
|
||||||
private String action;
|
void setTimestamp(Integer timestamp);
|
||||||
private Set<String> clientScopes = new HashSet<>();
|
|
||||||
|
|
||||||
private Map<String, AuthenticationSessionModel.ExecutionStatus> executionStatus = new ConcurrentHashMap<>();
|
String getRedirectUri();
|
||||||
private String protocol;
|
void setRedirectUri(String redirectUri);
|
||||||
|
|
||||||
private Map<String, String> clientNotes= new ConcurrentHashMap<>();;
|
String getAction();
|
||||||
private Map<String, String> authNotes = new ConcurrentHashMap<>();;
|
void setAction(String action);
|
||||||
private Set<String> requiredActions = new HashSet<>();
|
|
||||||
private Map<String, String> userSessionNotes = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public Map<String, String> getUserSessionNotes() {
|
Set<String> getClientScopes();
|
||||||
return userSessionNotes;
|
void setClientScopes(Set<String> clientScopes);
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserSessionNotes(Map<String, String> userSessionNotes) {
|
Set<String> getRequiredActions();
|
||||||
this.userSessionNotes = userSessionNotes;
|
void setRequiredActions(Set<String> requiredActions);
|
||||||
}
|
void addRequiredAction(String requiredAction);
|
||||||
|
void removeRequiredAction(String action);
|
||||||
|
|
||||||
public String getClientUUID() {
|
String getProtocol();
|
||||||
return clientUUID;
|
void setProtocol(String protocol);
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientUUID(String clientUUID) {
|
Map<String, String> getClientNotes();
|
||||||
this.clientUUID = clientUUID;
|
void setClientNotes(Map<String, String> clientNotes);
|
||||||
}
|
void setClientNote(String name, String value);
|
||||||
|
void removeClientNote(String name);
|
||||||
|
|
||||||
public String getAuthUserId() {
|
Map<String, String> getAuthNotes();
|
||||||
return authUserId;
|
void setAuthNotes(Map<String, String> authNotes);
|
||||||
}
|
void setAuthNote(String name, String value);
|
||||||
|
void removeAuthNote(String name);
|
||||||
|
|
||||||
public void setAuthUserId(String authUserId) {
|
Map<String, AuthenticationSessionModel.ExecutionStatus> getExecutionStatuses();
|
||||||
this.authUserId = authUserId;
|
void setExecutionStatuses(Map<String, AuthenticationSessionModel.ExecutionStatus> executionStatus);
|
||||||
}
|
void setExecutionStatus(String authenticator, AuthenticationSessionModel.ExecutionStatus status);
|
||||||
|
|
||||||
public int getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimestamp(int timestamp) {
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRedirectUri() {
|
|
||||||
return redirectUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRedirectUri(String redirectUri) {
|
|
||||||
this.redirectUri = redirectUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAction() {
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAction(String action) {
|
|
||||||
this.action = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getClientScopes() {
|
|
||||||
return clientScopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientScopes(Set<String> clientScopes) {
|
|
||||||
this.clientScopes = clientScopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getRequiredActions() {
|
|
||||||
return requiredActions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRequiredActions(Set<String> requiredActions) {
|
|
||||||
this.requiredActions = requiredActions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getProtocol() {
|
|
||||||
return protocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProtocol(String protocol) {
|
|
||||||
this.protocol = protocol;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getClientNotes() {
|
|
||||||
return clientNotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientNotes(Map<String, String> clientNotes) {
|
|
||||||
this.clientNotes = clientNotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getAuthNotes() {
|
|
||||||
return authNotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthNotes(Map<String, String> authNotes) {
|
|
||||||
this.authNotes = authNotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, AuthenticationSessionModel.ExecutionStatus> getExecutionStatus() {
|
|
||||||
return executionStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExecutionStatus(Map<String, AuthenticationSessionModel.ExecutionStatus> executionStatus) {
|
|
||||||
this.executionStatus = executionStatus;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,10 @@ import org.keycloak.models.KeycloakSession;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.sessions.AuthenticationSessionModel;
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,10 +61,9 @@ public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, AuthenticationSessionModel> getAuthenticationSessions() {
|
public Map<String, AuthenticationSessionModel> getAuthenticationSessions() {
|
||||||
return entity.getAuthenticationSessions().entrySet()
|
return Optional.ofNullable(entity.getAuthenticationSessions()).orElseGet(Collections::emptyMap).entrySet().stream()
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey,
|
.collect(Collectors.toMap(Map.Entry::getKey,
|
||||||
entry -> new MapAuthenticationSessionAdapter(session, this, entry.getKey(), entry.getValue())));
|
entry -> new MapAuthenticationSessionAdapter(session, this, entry.getKey(), (MapAuthenticationSessionEntity) entry.getValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,26 +85,27 @@ public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticat
|
||||||
public AuthenticationSessionModel createAuthenticationSession(ClientModel client) {
|
public AuthenticationSessionModel createAuthenticationSession(ClientModel client) {
|
||||||
Objects.requireNonNull(client, "The provided client can't be null!");
|
Objects.requireNonNull(client, "The provided client can't be null!");
|
||||||
|
|
||||||
MapAuthenticationSessionEntity authSessionEntity = new MapAuthenticationSessionEntity();
|
MapAuthenticationSessionEntity authSessionEntity = new MapAuthenticationSessionEntityImpl();
|
||||||
authSessionEntity.setClientUUID(client.getId());
|
authSessionEntity.setClientUUID(client.getId());
|
||||||
|
|
||||||
int timestamp = Time.currentTime();
|
int timestamp = Time.currentTime();
|
||||||
authSessionEntity.setTimestamp(timestamp);
|
authSessionEntity.setTimestamp(timestamp);
|
||||||
|
|
||||||
String tabId = generateTabId();
|
String tabId = generateTabId();
|
||||||
entity.getAuthenticationSessions().put(tabId, authSessionEntity);
|
entity.setAuthenticationSession(tabId, authSessionEntity);
|
||||||
|
|
||||||
// Update our timestamp when adding new authenticationSession
|
// Update our timestamp when adding new authenticationSession
|
||||||
entity.setTimestamp(timestamp);
|
entity.setTimestamp(timestamp);
|
||||||
|
|
||||||
MapAuthenticationSessionAdapter authSession = new MapAuthenticationSessionAdapter(session, this, tabId, authSessionEntity);
|
MapAuthenticationSessionAdapter authSession = new MapAuthenticationSessionAdapter(session, this, tabId, entity.getAuthenticationSessions().get(tabId));
|
||||||
session.getContext().setAuthenticationSession(authSession);
|
session.getContext().setAuthenticationSession(authSession);
|
||||||
return authSession;
|
return authSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAuthenticationSessionByTabId(String tabId) {
|
public void removeAuthenticationSessionByTabId(String tabId) {
|
||||||
if (entity.removeAuthenticationSession(tabId) != null) {
|
Boolean result = entity.removeAuthenticationSession(tabId);
|
||||||
|
if (result == null || result) {
|
||||||
if (entity.getAuthenticationSessions().isEmpty()) {
|
if (entity.getAuthenticationSessions().isEmpty()) {
|
||||||
session.authenticationSessions().removeRootAuthenticationSession(realm, this);
|
session.authenticationSessions().removeRootAuthenticationSession(realm, this);
|
||||||
} else {
|
} else {
|
||||||
|
@ -114,14 +116,10 @@ public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void restartSession(RealmModel realm) {
|
public void restartSession(RealmModel realm) {
|
||||||
entity.clearAuthenticationSessions();
|
entity.setAuthenticationSessions(null);
|
||||||
entity.setTimestamp(Time.currentTime());
|
entity.setTimestamp(Time.currentTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdated(boolean updated) {
|
|
||||||
entity.signalUpdated(updated);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateTabId() {
|
private String generateTabId() {
|
||||||
return Base64Url.encode(SecretGenerator.getInstance().randomBytes(8));
|
return Base64Url.encode(SecretGenerator.getInstance().randomBytes(8));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,89 +16,62 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.models.map.authSession;
|
package org.keycloak.models.map.authSession;
|
||||||
|
|
||||||
|
import org.keycloak.models.map.annotations.GenerateEntityImplementations;
|
||||||
import org.keycloak.models.map.common.AbstractEntity;
|
import org.keycloak.models.map.common.AbstractEntity;
|
||||||
|
|
||||||
|
import org.keycloak.models.map.common.DeepCloner;
|
||||||
import org.keycloak.models.map.common.UpdatableEntity;
|
import org.keycloak.models.map.common.UpdatableEntity;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
* @author <a href="mailto:mkanis@redhat.com">Martin Kanis</a>
|
||||||
*/
|
*/
|
||||||
public class MapRootAuthenticationSessionEntity extends UpdatableEntity.Impl implements AbstractEntity {
|
@GenerateEntityImplementations(
|
||||||
|
inherits = "org.keycloak.models.map.authSession.MapRootAuthenticationSessionEntity.AbstractRootAuthenticationSessionEntity"
|
||||||
|
)
|
||||||
|
@DeepCloner.Root
|
||||||
|
public interface MapRootAuthenticationSessionEntity extends AbstractEntity, UpdatableEntity {
|
||||||
|
|
||||||
private String id;
|
public abstract class AbstractRootAuthenticationSessionEntity extends UpdatableEntity.Impl implements MapRootAuthenticationSessionEntity {
|
||||||
private String realmId;
|
|
||||||
|
|
||||||
/**
|
private String id;
|
||||||
* Flag signalizing that any of the setters has been meaningfully used.
|
|
||||||
*/
|
|
||||||
private int timestamp;
|
|
||||||
private Map<String, MapAuthenticationSessionEntity> authenticationSessions = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public MapRootAuthenticationSessionEntity() {}
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
public MapRootAuthenticationSessionEntity(String id, String realmId) {
|
@Override
|
||||||
this.id = id;
|
public void setId(String id) {
|
||||||
this.realmId = realmId;
|
if (this.id != null) throw new IllegalStateException("Id cannot be changed");
|
||||||
|
this.id = id;
|
||||||
|
this.updated |= id != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUpdated() {
|
||||||
|
return this.updated ||
|
||||||
|
Optional.ofNullable(getAuthenticationSessions()).orElseGet(Collections::emptyMap).values().stream().anyMatch(MapAuthenticationSessionEntity::isUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearUpdatedFlag() {
|
||||||
|
this.updated = false;
|
||||||
|
Optional.ofNullable(getAuthenticationSessions()).orElseGet(Collections::emptyMap).values().forEach(UpdatableEntity::clearUpdatedFlag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
String getRealmId();
|
||||||
public String getId() {
|
void setRealmId(String realmId);
|
||||||
return this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
Integer getTimestamp();
|
||||||
public void setId(String id) {
|
void setTimestamp(Integer timestamp);
|
||||||
if (this.id != null) throw new IllegalStateException("Id cannot be changed");
|
|
||||||
this.id = id;
|
|
||||||
this.updated |= id != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRealmId() {
|
Map<String, MapAuthenticationSessionEntity> getAuthenticationSessions();
|
||||||
return realmId;
|
void setAuthenticationSessions(Map<String, MapAuthenticationSessionEntity> authenticationSessions);
|
||||||
}
|
void setAuthenticationSession(String tabId, MapAuthenticationSessionEntity entity);
|
||||||
|
Boolean removeAuthenticationSession(String tabId);
|
||||||
public void setRealmId(String realmId) {
|
|
||||||
this.updated |= !Objects.equals(this.realmId, realmId);
|
|
||||||
this.realmId = realmId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimestamp(int timestamp) {
|
|
||||||
this.updated |= !Objects.equals(this.timestamp, timestamp);
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, MapAuthenticationSessionEntity> getAuthenticationSessions() {
|
|
||||||
return authenticationSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthenticationSessions(Map<String, MapAuthenticationSessionEntity> authenticationSessions) {
|
|
||||||
this.updated |= !Objects.equals(this.authenticationSessions, authenticationSessions);
|
|
||||||
this.authenticationSessions = authenticationSessions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MapAuthenticationSessionEntity removeAuthenticationSession(String tabId) {
|
|
||||||
MapAuthenticationSessionEntity entity = this.authenticationSessions.remove(tabId);
|
|
||||||
this.updated |= entity != null;
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAuthenticationSession(String tabId, MapAuthenticationSessionEntity entity) {
|
|
||||||
this.updated |= !Objects.equals(this.authenticationSessions.put(tabId, entity), entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearAuthenticationSessions() {
|
|
||||||
this.updated |= !this.authenticationSessions.isEmpty();
|
|
||||||
this.authenticationSessions.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void signalUpdated(boolean updated) {
|
|
||||||
this.updated |= updated;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,9 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
|
||||||
LOG.tracef("createRootAuthenticationSession(%s)%s", realm.getName(), getShortStackTrace());
|
LOG.tracef("createRootAuthenticationSession(%s)%s", realm.getName(), getShortStackTrace());
|
||||||
|
|
||||||
// create map authentication session entity
|
// create map authentication session entity
|
||||||
MapRootAuthenticationSessionEntity entity = new MapRootAuthenticationSessionEntity(id, realm.getId());
|
MapRootAuthenticationSessionEntity entity = new MapRootAuthenticationSessionEntityImpl();
|
||||||
|
entity.setId(id);
|
||||||
|
entity.setRealmId(realm.getId());
|
||||||
entity.setTimestamp(Time.currentTime());
|
entity.setTimestamp(Time.currentTime());
|
||||||
|
|
||||||
if (id != null && tx.read(id) != null) {
|
if (id != null && tx.read(id) != null) {
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.models.map.storage.chm;
|
package org.keycloak.models.map.storage.chm;
|
||||||
|
|
||||||
|
import org.keycloak.models.map.authSession.MapAuthenticationSessionEntity;
|
||||||
|
import org.keycloak.models.map.authSession.MapAuthenticationSessionEntityImpl;
|
||||||
|
import org.keycloak.models.map.authSession.MapRootAuthenticationSessionEntity;
|
||||||
|
import org.keycloak.models.map.authSession.MapRootAuthenticationSessionEntityImpl;
|
||||||
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
|
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
|
||||||
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntityImpl;
|
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntityImpl;
|
||||||
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
|
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
|
||||||
|
@ -122,6 +126,8 @@ public class ConcurrentHashMapStorageProviderFactory implements AmphibianProvide
|
||||||
.constructor(MapRequiredActionProviderEntity.class, MapRequiredActionProviderEntityImpl::new)
|
.constructor(MapRequiredActionProviderEntity.class, MapRequiredActionProviderEntityImpl::new)
|
||||||
.constructor(MapRequiredCredentialEntity.class, MapRequiredCredentialEntityImpl::new)
|
.constructor(MapRequiredCredentialEntity.class, MapRequiredCredentialEntityImpl::new)
|
||||||
.constructor(MapWebAuthnPolicyEntity.class, MapWebAuthnPolicyEntityImpl::new)
|
.constructor(MapWebAuthnPolicyEntity.class, MapWebAuthnPolicyEntityImpl::new)
|
||||||
|
.constructor(MapRootAuthenticationSessionEntity.class, MapRootAuthenticationSessionEntityImpl::new)
|
||||||
|
.constructor(MapAuthenticationSessionEntity.class, MapAuthenticationSessionEntityImpl::new)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private static final Map<String, StringKeyConvertor> KEY_CONVERTORS = new HashMap<>();
|
private static final Map<String, StringKeyConvertor> KEY_CONVERTORS = new HashMap<>();
|
||||||
|
|
Loading…
Reference in a new issue