diff --git a/distribution/server-dist/src/main/docs/examples/map-storage-concurrenthashmap.cli b/distribution/server-dist/src/main/docs/examples/map-storage-concurrenthashmap.cli
index fcbc3c30d1..edcc742199 100644
--- a/distribution/server-dist/src/main/docs/examples/map-storage-concurrenthashmap.cli
+++ b/distribution/server-dist/src/main/docs/examples/map-storage-concurrenthashmap.cli
@@ -30,6 +30,6 @@ embed-server
/subsystem=keycloak-server/spi=userSessions:add(default-provider=map)
/subsystem=keycloak-server/spi=mapStorage:add(default-provider=concurrenthashmap)
-/subsystem=keycloak-server/spi=mapStorage/provider=concurrenthashmap:add(properties={dir="${jboss.server.data.dir}/map"},enabled=true)
+/subsystem=keycloak-server/spi=mapStorage/provider=concurrenthashmap:add(properties={dir="${jboss.server.data.dir}/map",keyType.realms=string,keyType.authz-resource-servers=string},enabled=true)
quit
\ No newline at end of file
diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java
index 4ac224ee85..765a00b58c 100755
--- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java
+++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/InfinispanUserSessionProvider.java
@@ -276,6 +276,11 @@ public class InfinispanUserSessionProvider implements UserSessionProvider {
.map(entity -> this.wrap(realm, entity, offline));
}
+ @Override
+ public AuthenticatedClientSessionAdapter getClientSession(UserSessionModel userSession, ClientModel client, String clientSessionId, boolean offline) {
+ return getClientSession(userSession, client, clientSessionId == null ? null : UUID.fromString(clientSessionId), offline);
+ }
+
@Override
public AuthenticatedClientSessionAdapter getClientSession(UserSessionModel userSession, ClientModel client, UUID clientSessionId, boolean offline) {
AuthenticatedClientSessionEntity entity = getClientSessionEntity(clientSessionId, offline);
diff --git a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserLoginFailureAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserLoginFailureAdapter.java
index 658de000af..44838957ae 100755
--- a/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserLoginFailureAdapter.java
+++ b/model/infinispan/src/main/java/org/keycloak/models/sessions/infinispan/UserLoginFailureAdapter.java
@@ -136,4 +136,9 @@ public class UserLoginFailureAdapter implements UserLoginFailureModel {
provider.getLoginFailuresTx().addTask(key, task);
}
+ @Override
+ public String getId() {
+ return key.toString();
+ }
+
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/AbstractRootAuthenticationSessionEntity.java b/model/map/src/main/java/org/keycloak/models/map/authSession/AbstractRootAuthenticationSessionEntity.java
deleted file mode 100644
index 859a112206..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/AbstractRootAuthenticationSessionEntity.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2020 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.keycloak.models.map.authSession;
-
-import org.keycloak.models.map.common.AbstractEntity;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @author Martin Kanis
- */
-public abstract class AbstractRootAuthenticationSessionEntity implements AbstractEntity {
-
- private K id;
- private String realmId;
-
- /**
- * Flag signalizing that any of the setters has been meaningfully used.
- */
- protected boolean updated;
- private int timestamp;
- private Map authenticationSessions = new ConcurrentHashMap<>();
-
- protected AbstractRootAuthenticationSessionEntity() {
- this.id = null;
- this.realmId = null;
- }
-
- public AbstractRootAuthenticationSessionEntity(K id, String realmId) {
- Objects.requireNonNull(id, "id");
- Objects.requireNonNull(realmId, "realmId");
-
- this.id = id;
- this.realmId = realmId;
- }
-
- @Override
- public K getId() {
- return this.id;
- }
-
- @Override
- public boolean isUpdated() {
- return this.updated;
- }
-
- public String getRealmId() {
- return realmId;
- }
-
- 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 getAuthenticationSessions() {
- return authenticationSessions;
- }
-
- public void setAuthenticationSessions(Map 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();
- }
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAdapter.java
index f2ca89580f..09a5b6fa24 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAdapter.java
@@ -37,7 +37,7 @@ public class MapAuthenticationSessionAdapter implements AuthenticationSessionMod
private final KeycloakSession session;
private final MapRootAuthenticationSessionAdapter parent;
private final String tabId;
- private MapAuthenticationSessionEntity entity;
+ private final MapAuthenticationSessionEntity entity;
public MapAuthenticationSessionAdapter(KeycloakSession session, MapRootAuthenticationSessionAdapter parent,
String tabId, MapAuthenticationSessionEntity entity) {
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAuthNoteUpdateEvent.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAuthNoteUpdateEvent.java
index a28ec028cb..3307b28f62 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAuthNoteUpdateEvent.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapAuthenticationSessionAuthNoteUpdateEvent.java
@@ -81,6 +81,6 @@ public class MapAuthenticationSessionAuthNoteUpdateEvent implements ClusterEvent
@Override
public String toString() {
return String.format("AuthenticationSessionAuthNoteUpdateEvent [ authSessionId=%s, tabId=%s, clientUUID=%s, authNotesFragment=%s ]",
- authSessionId, clientUUID, authNotesFragment);
+ authSessionId, tabId, clientUUID, authNotesFragment);
}
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java
index 4b5dca1316..670ff08a48 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionAdapter.java
@@ -31,17 +31,12 @@ import java.util.stream.Collectors;
/**
* @author Martin Kanis
*/
-public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticationSessionModel {
+public abstract class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticationSessionModel> {
- public MapRootAuthenticationSessionAdapter(KeycloakSession session, RealmModel realm, MapRootAuthenticationSessionEntity entity) {
+ public MapRootAuthenticationSessionAdapter(KeycloakSession session, RealmModel realm, MapRootAuthenticationSessionEntity entity) {
super(session, realm, entity);
}
- @Override
- public String getId() {
- return entity.getId().toString();
- }
-
@Override
public RealmModel getRealm() {
return session.realms().getRealm(entity.getRealmId());
@@ -102,9 +97,7 @@ public class MapRootAuthenticationSessionAdapter extends AbstractRootAuthenticat
public void removeAuthenticationSessionByTabId(String tabId) {
if (entity.removeAuthenticationSession(tabId) != null) {
if (entity.getAuthenticationSessions().isEmpty()) {
- MapRootAuthenticationSessionProvider authenticationSessionProvider =
- (MapRootAuthenticationSessionProvider) session.authenticationSessions();
- authenticationSessionProvider.tx.delete(entity.getId());
+ session.authenticationSessions().removeRootAuthenticationSession(realm, this);
} else {
entity.setTimestamp(Time.currentTime());
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionEntity.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionEntity.java
index 055ec41944..60e4efa8ed 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionEntity.java
@@ -16,18 +16,89 @@
*/
package org.keycloak.models.map.authSession;
-import java.util.UUID;
+import org.keycloak.models.map.common.AbstractEntity;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
/**
* @author Martin Kanis
*/
-public class MapRootAuthenticationSessionEntity extends AbstractRootAuthenticationSessionEntity {
+public class MapRootAuthenticationSessionEntity implements AbstractEntity {
+
+ private K id;
+ private String realmId;
+
+ /**
+ * Flag signalizing that any of the setters has been meaningfully used.
+ */
+ protected boolean updated;
+ private int timestamp;
+ private Map authenticationSessions = new ConcurrentHashMap<>();
protected MapRootAuthenticationSessionEntity() {
- super();
+ this.id = null;
+ this.realmId = null;
}
- public MapRootAuthenticationSessionEntity(UUID id, String realmId) {
- super(id, realmId);
+ public MapRootAuthenticationSessionEntity(K id, String realmId) {
+ Objects.requireNonNull(id, "id");
+ Objects.requireNonNull(realmId, "realmId");
+
+ this.id = id;
+ this.realmId = realmId;
+ }
+
+ @Override
+ public K getId() {
+ return this.id;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return this.updated;
+ }
+
+ public String getRealmId() {
+ return realmId;
+ }
+
+ 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 getAuthenticationSessions() {
+ return authenticationSessions;
+ }
+
+ public void setAuthenticationSessions(Map 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();
}
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java
index 587f8d2c51..80864992ab 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProvider.java
@@ -36,7 +36,6 @@ import org.keycloak.sessions.RootAuthenticationSessionModel;
import org.keycloak.sessions.RootAuthenticationSessionModel.SearchableFields;
import java.util.Map;
import java.util.Objects;
-import java.util.UUID;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -45,17 +44,16 @@ import static org.keycloak.common.util.StackUtil.getShortStackTrace;
/**
* @author Martin Kanis
*/
-public class MapRootAuthenticationSessionProvider implements AuthenticationSessionProvider {
+public class MapRootAuthenticationSessionProvider implements AuthenticationSessionProvider {
private static final Logger LOG = Logger.getLogger(MapRootAuthenticationSessionProvider.class);
private final KeycloakSession session;
- protected final MapKeycloakTransaction tx;
- private final MapStorage sessionStore;
+ protected final MapKeycloakTransaction, RootAuthenticationSessionModel> tx;
+ private final MapStorage, RootAuthenticationSessionModel> sessionStore;
- private static final Predicate ALWAYS_FALSE = role -> false;
private static final String AUTHENTICATION_SESSION_EVENTS = "AUTHENTICATION_SESSION_EVENTS";
- public MapRootAuthenticationSessionProvider(KeycloakSession session, MapStorage sessionStore) {
+ public MapRootAuthenticationSessionProvider(KeycloakSession session, MapStorage, RootAuthenticationSessionModel> sessionStore) {
this.session = session;
this.sessionStore = sessionStore;
this.tx = sessionStore.createTransaction(session);
@@ -63,21 +61,26 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
session.getTransactionManager().enlistAfterCompletion(tx);
}
- private Function entityToAdapterFunc(RealmModel realm) {
+ private Function, RootAuthenticationSessionModel> entityToAdapterFunc(RealmModel realm) {
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return origEntity -> new MapRootAuthenticationSessionAdapter(session, realm, registerEntityForChanges(origEntity));
+ return origEntity -> new MapRootAuthenticationSessionAdapter(session, realm, registerEntityForChanges(origEntity)) {
+ @Override
+ public String getId() {
+ return sessionStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
- private MapRootAuthenticationSessionEntity registerEntityForChanges(MapRootAuthenticationSessionEntity origEntity) {
- MapRootAuthenticationSessionEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapRootAuthenticationSessionEntity::isUpdated);
+ private MapRootAuthenticationSessionEntity registerEntityForChanges(MapRootAuthenticationSessionEntity origEntity) {
+ MapRootAuthenticationSessionEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapRootAuthenticationSessionEntity::isUpdated);
return res;
}
- private Predicate entityRealmFilter(String realmId) {
+ private Predicate> entityRealmFilter(String realmId) {
if (realmId == null) {
- return MapRootAuthenticationSessionProvider.ALWAYS_FALSE;
+ return c -> false;
}
return entity -> Objects.equals(realmId, entity.getRealmId());
}
@@ -92,12 +95,12 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
public RootAuthenticationSessionModel createRootAuthenticationSession(RealmModel realm, String id) {
Objects.requireNonNull(realm, "The provided realm can't be null!");
- final UUID entityId = id == null ? UUID.randomUUID() : UUID.fromString(id);
+ final K entityId = id == null ? sessionStore.getKeyConvertor().yieldNewUniqueKey() : sessionStore.getKeyConvertor().fromString(id);
LOG.tracef("createRootAuthenticationSession(%s)%s", realm.getName(), getShortStackTrace());
// create map authentication session entity
- MapRootAuthenticationSessionEntity entity = new MapRootAuthenticationSessionEntity(entityId, realm.getId());
+ MapRootAuthenticationSessionEntity entity = new MapRootAuthenticationSessionEntity<>(entityId, realm.getId());
entity.setRealmId(realm.getId());
entity.setTimestamp(Time.currentTime());
@@ -119,7 +122,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
LOG.tracef("getRootAuthenticationSession(%s, %s)%s", realm.getName(), authenticationSessionId, getShortStackTrace());
- MapRootAuthenticationSessionEntity entity = tx.read(UUID.fromString(authenticationSessionId));
+ MapRootAuthenticationSessionEntity entity = tx.read(sessionStore.getKeyConvertor().fromStringSafe(authenticationSessionId));
return (entity == null || !entityRealmFilter(realm.getId()).test(entity))
? null
: entityToAdapterFunc(realm).apply(entity);
@@ -128,7 +131,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
@Override
public void removeRootAuthenticationSession(RealmModel realm, RootAuthenticationSessionModel authenticationSession) {
Objects.requireNonNull(authenticationSession, "The provided root authentication session can't be null!");
- tx.delete(UUID.fromString(authenticationSession.getId()));
+ tx.delete(sessionStore.getKeyConvertor().fromString(authenticationSession.getId()));
}
@Override
@@ -147,7 +150,7 @@ public class MapRootAuthenticationSessionProvider implements AuthenticationSessi
.compare(SearchableFields.REALM_ID, Operator.EQ, realm.getId())
.compare(SearchableFields.TIMESTAMP, Operator.LT, expired);
- long deletedCount = tx.delete(UUID.randomUUID(), mcb);
+ long deletedCount = tx.delete(sessionStore.getKeyConvertor().yieldNewUniqueKey(), mcb);
LOG.debugf("Removed %d expired authentication sessions for realm '%s'", deletedCount, realm.getName());
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProviderFactory.java b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProviderFactory.java
index d7fc635c99..1d2f1d15ef 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProviderFactory.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authSession/MapRootAuthenticationSessionProviderFactory.java
@@ -17,33 +17,30 @@
package org.keycloak.models.map.authSession;
import org.keycloak.models.KeycloakSession;
-import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.map.common.AbstractMapProviderFactory;
-import org.keycloak.models.map.storage.MapStorage;
-import org.keycloak.models.map.storage.MapStorageProvider;
-import org.keycloak.models.map.storage.MapStorageProviderFactory;
import org.keycloak.sessions.AuthenticationSessionProvider;
import org.keycloak.sessions.AuthenticationSessionProviderFactory;
import org.keycloak.sessions.RootAuthenticationSessionModel;
-import java.util.UUID;
/**
* @author Martin Kanis
*/
-public class MapRootAuthenticationSessionProviderFactory extends AbstractMapProviderFactory
+public class MapRootAuthenticationSessionProviderFactory extends AbstractMapProviderFactory, RootAuthenticationSessionModel>
implements AuthenticationSessionProviderFactory {
- private MapStorage store;
-
- @Override
- public void postInit(KeycloakSessionFactory factory) {
- MapStorageProviderFactory sp = (MapStorageProviderFactory) factory.getProviderFactory(MapStorageProvider.class);
- this.store = sp.getStorage("sessions", UUID.class, MapRootAuthenticationSessionEntity.class, RootAuthenticationSessionModel.class);
+ public MapRootAuthenticationSessionProviderFactory() {
+ super(MapRootAuthenticationSessionEntity.class, RootAuthenticationSessionModel.class);
}
@Override
public AuthenticationSessionProvider create(KeycloakSession session) {
- return new MapRootAuthenticationSessionProvider(session, store);
+ return new MapRootAuthenticationSessionProvider<>(session, getStorage(session));
}
+
+ @Override
+ public String getHelpText() {
+ return "Authentication session provider";
+ }
+
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStore.java
index 833901ad8d..418a3148ff 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStore.java
@@ -18,11 +18,6 @@
package org.keycloak.models.map.authorization;
import org.keycloak.authorization.AuthorizationProvider;
-import org.keycloak.authorization.model.PermissionTicket;
-import org.keycloak.authorization.model.Policy;
-import org.keycloak.authorization.model.Resource;
-import org.keycloak.authorization.model.ResourceServer;
-import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.PermissionTicketStore;
import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.authorization.store.ResourceServerStore;
@@ -30,14 +25,8 @@ import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.authorization.store.ScopeStore;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.KeycloakSession;
-import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
-import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
-import org.keycloak.models.map.authorization.entity.MapResourceEntity;
-import org.keycloak.models.map.authorization.entity.MapResourceServerEntity;
-import org.keycloak.models.map.authorization.entity.MapScopeEntity;
import org.keycloak.models.map.storage.MapStorage;
-import java.util.UUID;
/**
* @author mhajas
@@ -51,7 +40,7 @@ public class MapAuthorizationStore implements StoreFactory {
private final PermissionTicketStore permissionTicketStore;
private boolean readOnly;
- public MapAuthorizationStore(KeycloakSession session, MapStorage permissionTicketStore, MapStorage policyStore, MapStorage resourceServerStore, MapStorage resourceStore, MapStorage scopeStore, AuthorizationProvider provider) {
+ public MapAuthorizationStore(KeycloakSession session, MapStorage permissionTicketStore, MapStorage policyStore, MapStorage resourceServerStore, MapStorage resourceStore, MapStorage scopeStore, AuthorizationProvider provider) {
this.permissionTicketStore = new MapPermissionTicketStore(session, permissionTicketStore, provider);
this.policyStore = new MapPolicyStore(session, policyStore, provider);
this.resourceServerStore = new MapResourceServerStore(session, resourceServerStore, provider);
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStoreFactory.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStoreFactory.java
index 64fce0bf1a..0c6c12990c 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStoreFactory.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapAuthorizationStoreFactory.java
@@ -26,32 +26,49 @@ import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.AuthorizationStoreFactory;
import org.keycloak.authorization.store.StoreFactory;
+import org.keycloak.component.AmphibianProviderFactory;
import org.keycloak.models.KeycloakSession;
-import org.keycloak.models.KeycloakSessionFactory;
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
import org.keycloak.models.map.authorization.entity.MapResourceEntity;
import org.keycloak.models.map.authorization.entity.MapResourceServerEntity;
import org.keycloak.models.map.authorization.entity.MapScopeEntity;
+import org.keycloak.models.map.common.AbstractMapProviderFactory;
import org.keycloak.models.map.storage.MapStorage;
import org.keycloak.models.map.storage.MapStorageProvider;
import org.keycloak.models.map.storage.MapStorageProviderFactory;
-import java.util.UUID;
+import org.keycloak.models.map.storage.MapStorageSpi;
+import static org.keycloak.models.utils.KeycloakModelUtils.getComponentFactory;
/**
* @author mhajas
*/
-public class MapAuthorizationStoreFactory implements AuthorizationStoreFactory {
+public class MapAuthorizationStoreFactory implements AmphibianProviderFactory, AuthorizationStoreFactory {
- private MapStorage permissionTicketStore;
- private MapStorage policyStore;
- private MapStorage resourceServerStore;
- private MapStorage resourceStore;
- private MapStorage scopeStore;
+ public static final String PROVIDER_ID = AbstractMapProviderFactory.PROVIDER_ID;
+
+ private Config.Scope storageConfigScope;
@Override
public StoreFactory create(KeycloakSession session) {
+ MapStorageProviderFactory storageProviderFactory = (MapStorageProviderFactory) getComponentFactory(session.getKeycloakSessionFactory(),
+ MapStorageProvider.class, storageConfigScope, MapStorageSpi.NAME);
+ final MapStorageProvider mapStorageProvider = storageProviderFactory.create(session);
AuthorizationProvider provider = session.getProvider(AuthorizationProvider.class);
+
+
+ MapStorage permissionTicketStore;
+ MapStorage policyStore;
+ MapStorage resourceServerStore;
+ MapStorage resourceStore;
+ MapStorage scopeStore;
+
+ permissionTicketStore = mapStorageProvider.getStorage(MapPermissionTicketEntity.class, PermissionTicket.class);
+ policyStore = mapStorageProvider.getStorage(MapPolicyEntity.class, Policy.class);
+ resourceServerStore = mapStorageProvider.getStorage(MapResourceServerEntity.class, ResourceServer.class);
+ resourceStore = mapStorageProvider.getStorage(MapResourceEntity.class, Resource.class);
+ scopeStore = mapStorageProvider.getStorage(MapScopeEntity.class, Scope.class);
+
return new MapAuthorizationStore(session,
permissionTicketStore,
policyStore,
@@ -63,21 +80,8 @@ public class MapAuthorizationStoreFactory implements AuthorizationStoreFactory {
}
@Override
- public void init(Config.Scope config) {
-
- }
-
- @Override
- public void postInit(KeycloakSessionFactory factory) {
- AuthorizationStoreFactory.super.postInit(factory);
-
- MapStorageProviderFactory mapStorageProvider = (MapStorageProviderFactory) factory.getProviderFactory(MapStorageProvider.class);
- permissionTicketStore = mapStorageProvider.getStorage("authzPermissionTickets", UUID.class, MapPermissionTicketEntity.class, PermissionTicket.class);
- policyStore = mapStorageProvider.getStorage("authzPolicies", UUID.class, MapPolicyEntity.class, Policy.class);
- resourceServerStore = mapStorageProvider.getStorage("authzResourceServers", String.class, MapResourceServerEntity.class, ResourceServer.class);
- resourceStore = mapStorageProvider.getStorage("authzResources", UUID.class, MapResourceEntity.class, Resource.class);
- scopeStore = mapStorageProvider.getStorage("authzScopes", UUID.class, MapScopeEntity.class, Scope.class);
-
+ public void init(org.keycloak.Config.Scope config) {
+ this.storageConfigScope = config.scope("storage");
}
@Override
@@ -87,6 +91,11 @@ public class MapAuthorizationStoreFactory implements AuthorizationStoreFactory {
@Override
public String getId() {
- return "map";
+ return PROVIDER_ID;
+ }
+
+ @Override
+ public String getHelpText() {
+ return "Authorization store provider";
}
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java
index 07c99632c7..3633522c53 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPermissionTicketStore.java
@@ -28,7 +28,6 @@ import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.map.authorization.adapter.MapPermissionTicketAdapter;
-import org.keycloak.models.map.authorization.entity.AbstractPermissionTicketEntity;
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
import org.keycloak.models.map.common.Serialization;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
@@ -37,11 +36,11 @@ import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import java.util.Collections;
+import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -49,30 +48,35 @@ import static org.keycloak.common.util.StackUtil.getShortStackTrace;
import static org.keycloak.utils.StreamsUtil.distinctByKey;
import static org.keycloak.utils.StreamsUtil.paginatedStream;
-public class MapPermissionTicketStore implements PermissionTicketStore {
+public class MapPermissionTicketStore> implements PermissionTicketStore {
private static final Logger LOG = Logger.getLogger(MapPermissionTicketStore.class);
private final AuthorizationProvider authorizationProvider;
- final MapKeycloakTransaction tx;
- private final MapStorage permissionTicketStore;
+ final MapKeycloakTransaction, PermissionTicket> tx;
+ private final MapStorage, PermissionTicket> permissionTicketStore;
- public MapPermissionTicketStore(KeycloakSession session, MapStorage permissionTicketStore, AuthorizationProvider provider) {
+ public MapPermissionTicketStore(KeycloakSession session, MapStorage, PermissionTicket> permissionTicketStore, AuthorizationProvider provider) {
this.authorizationProvider = provider;
this.permissionTicketStore = permissionTicketStore;
this.tx = permissionTicketStore.createTransaction(session);
session.getTransactionManager().enlist(tx);
}
- private MapPermissionTicketEntity registerEntityForChanges(MapPermissionTicketEntity origEntity) {
- final MapPermissionTicketEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapPermissionTicketEntity::isUpdated);
+ private MapPermissionTicketEntity registerEntityForChanges(MapPermissionTicketEntity origEntity) {
+ final MapPermissionTicketEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapPermissionTicketEntity::isUpdated);
return res;
}
- private PermissionTicket entityToAdapter(MapPermissionTicketEntity origEntity) {
+ private PermissionTicket entityToAdapter(MapPermissionTicketEntity origEntity) {
if (origEntity == null) return null;
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return new MapPermissionTicketAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory());
+ return new MapPermissionTicketAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory()) {
+ @Override
+ public String getId() {
+ return permissionTicketStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
private ModelCriteriaBuilder forResourceServer(String resourceServerId) {
@@ -116,13 +120,14 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
+ ", Resource: " + resourceId + ", owner: " + owner + ", scopeId: " + scopeId + " already exists.");
}
- MapPermissionTicketEntity entity = new MapPermissionTicketEntity(UUID.randomUUID());
- entity.setResourceId(UUID.fromString(resourceId));
+ final K newId = permissionTicketStore.getKeyConvertor().yieldNewUniqueKey();
+ MapPermissionTicketEntity entity = new MapPermissionTicketEntity<>(newId);
+ entity.setResourceId(resourceId);
entity.setRequester(requester);
entity.setCreatedTimestamp(System.currentTimeMillis());
if (scopeId != null) {
- entity.setScopeId(UUID.fromString(scopeId));
+ entity.setScopeId(scopeId);
}
entity.setOwner(owner);
@@ -136,7 +141,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
@Override
public void delete(String id) {
LOG.tracef("delete(%s)%s", id, getShortStackTrace());
- tx.delete(UUID.fromString(id));
+ tx.delete(permissionTicketStore.getKeyConvertor().fromString(id));
}
@Override
@@ -204,7 +209,7 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
if (r == null || r.isEmpty()) {
return Collections.emptyList();
}
- mcb = mcb.compare(SearchableFields.RESOURCE_ID, Operator.IN, r.stream().map(Resource::getId).collect(Collectors.toList()));
+ mcb = mcb.compare(SearchableFields.RESOURCE_ID, Operator.IN, r.stream().map(Resource::getId));
}
mcb = mcb.and(
@@ -213,8 +218,9 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
.toArray(ModelCriteriaBuilder[]::new)
);
+ Comparator super MapPermissionTicketEntity> c = Comparator.comparing(MapPermissionTicketEntity::getId);
return paginatedStream(tx.getUpdatedNotRemoved(mcb)
- .sorted(MapPermissionTicketEntity.COMPARE_BY_ID), firstResult, maxResult)
+ .sorted(c), firstResult, maxResult)
.map(this::entityToAdapter)
.collect(Collectors.toList());
}
@@ -278,14 +284,14 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
.compare(SearchableFields.REQUESTER, Operator.EQ, requester)
.compare(SearchableFields.GRANTED_TIMESTAMP, Operator.EXISTS);
- Function ticketResourceMapper;
+ Function, Resource> ticketResourceMapper;
ResourceStore resourceStore = authorizationProvider.getStoreFactory().getResourceStore();
if (name != null) {
ticketResourceMapper = ticket -> {
Map filterOptionMap = new EnumMap<>(Resource.FilterOption.class);
- filterOptionMap.put(Resource.FilterOption.ID, new String[] {ticket.getResourceId().toString()});
+ filterOptionMap.put(Resource.FilterOption.ID, new String[] {ticket.getResourceId()});
filterOptionMap.put(Resource.FilterOption.NAME, new String[] {name});
List resource = resourceStore.findByResourceServer(filterOptionMap, ticket.getResourceServerId(), -1, 1);
@@ -294,11 +300,11 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
};
} else {
ticketResourceMapper = ticket -> resourceStore
- .findById(ticket.getResourceId().toString(), ticket.getResourceServerId());
+ .findById(ticket.getResourceId(), ticket.getResourceServerId());
}
return paginatedStream(tx.getUpdatedNotRemoved(mcb)
- .filter(distinctByKey(AbstractPermissionTicketEntity::getResourceId))
+ .filter(distinctByKey(MapPermissionTicketEntity::getResourceId))
.sorted(MapPermissionTicketEntity.COMPARE_BY_RESOURCE_ID)
.map(ticketResourceMapper)
.filter(Objects::nonNull), first, max)
@@ -311,10 +317,10 @@ public class MapPermissionTicketStore implements PermissionTicketStore {
.compare(SearchableFields.OWNER, Operator.EQ, owner);
return paginatedStream(tx.getUpdatedNotRemoved(mcb)
- .filter(distinctByKey(AbstractPermissionTicketEntity::getResourceId))
+ .filter(distinctByKey(MapPermissionTicketEntity::getResourceId))
.sorted(MapPermissionTicketEntity.COMPARE_BY_RESOURCE_ID), first, max)
.map(ticket -> authorizationProvider.getStoreFactory().getResourceStore()
- .findById(ticket.getResourceId().toString(), ticket.getResourceServerId()))
+ .findById(ticket.getResourceId(), ticket.getResourceServerId()))
.collect(Collectors.toList());
}
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java
index b4e56417b2..1abfee600c 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapPolicyStore.java
@@ -26,7 +26,6 @@ import org.keycloak.authorization.store.PolicyStore;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.map.authorization.adapter.MapPolicyAdapter;
-import org.keycloak.models.map.authorization.entity.AbstractPolicyEntity;
import org.keycloak.models.map.authorization.entity.MapPolicyEntity;
import org.keycloak.models.map.common.Serialization;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
@@ -38,37 +37,41 @@ import org.keycloak.representations.idm.authorization.AbstractPolicyRepresentati
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
import static org.keycloak.utils.StreamsUtil.paginatedStream;
-public class MapPolicyStore implements PolicyStore {
+public class MapPolicyStore implements PolicyStore {
private static final Logger LOG = Logger.getLogger(MapPolicyStore.class);
private final AuthorizationProvider authorizationProvider;
- final MapKeycloakTransaction tx;
- private final MapStorage policyStore;
+ final MapKeycloakTransaction, Policy> tx;
+ private final MapStorage, Policy> policyStore;
- public MapPolicyStore(KeycloakSession session, MapStorage policyStore, AuthorizationProvider provider) {
+ public MapPolicyStore(KeycloakSession session, MapStorage, Policy> policyStore, AuthorizationProvider provider) {
this.authorizationProvider = provider;
this.policyStore = policyStore;
this.tx = policyStore.createTransaction(session);
session.getTransactionManager().enlist(tx);
}
- private MapPolicyEntity registerEntityForChanges(MapPolicyEntity origEntity) {
- final MapPolicyEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapPolicyEntity::isUpdated);
+ private MapPolicyEntity registerEntityForChanges(MapPolicyEntity origEntity) {
+ final MapPolicyEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapPolicyEntity::isUpdated);
return res;
}
- private Policy entityToAdapter(MapPolicyEntity origEntity) {
+ private Policy entityToAdapter(MapPolicyEntity origEntity) {
if (origEntity == null) return null;
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return new MapPolicyAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory());
+ return new MapPolicyAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory()) {
+ @Override
+ public String getId() {
+ return policyStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
private ModelCriteriaBuilder forResourceServer(String resourceServerId) {
@@ -92,8 +95,8 @@ public class MapPolicyStore implements PolicyStore {
throw new ModelDuplicateException("Policy with name '" + representation.getName() + "' for " + resourceServer.getId() + " already exists");
}
- UUID uid = representation.getId() == null ? UUID.randomUUID() : UUID.fromString(representation.getId());
- MapPolicyEntity entity = new MapPolicyEntity(uid);
+ K uid = representation.getId() == null ? policyStore.getKeyConvertor().yieldNewUniqueKey() : policyStore.getKeyConvertor().fromString(representation.getId());
+ MapPolicyEntity entity = new MapPolicyEntity<>(uid);
entity.setType(representation.getType());
entity.setName(representation.getName());
entity.setResourceServerId(resourceServer.getId());
@@ -106,7 +109,7 @@ public class MapPolicyStore implements PolicyStore {
@Override
public void delete(String id) {
LOG.tracef("delete(%s)%s", id, getShortStackTrace());
- tx.delete(UUID.fromString(id));
+ tx.delete(policyStore.getKeyConvertor().fromString(id));
}
@Override
@@ -155,9 +158,9 @@ public class MapPolicyStore implements PolicyStore {
}
return paginatedStream(tx.getUpdatedNotRemoved(mcb)
- .sorted(AbstractPolicyEntity.COMPARE_BY_NAME), firstResult, maxResult)
- .map(MapPolicyEntity::getId)
- .map(UUID::toString)
+ .sorted(MapPolicyEntity.COMPARE_BY_NAME), firstResult, maxResult)
+ .map(MapPolicyEntity::getId)
+ .map(K::toString)
.map(id -> authorizationProvider.getStoreFactory().getPolicyStore().findById(id, resourceServerId)) // We need to go through cache
.collect(Collectors.toList());
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java
index ef0a12002d..7ea4ae2a03 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceServerStore.java
@@ -41,30 +41,35 @@ import org.keycloak.storage.StorageId;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
-public class MapResourceServerStore implements ResourceServerStore {
+public class MapResourceServerStore implements ResourceServerStore {
private static final Logger LOG = Logger.getLogger(MapResourceServerStore.class);
private final AuthorizationProvider authorizationProvider;
- final MapKeycloakTransaction tx;
- private final MapStorage resourceServerStore;
+ final MapKeycloakTransaction, ResourceServer> tx;
+ private final MapStorage, ResourceServer> resourceServerStore;
- public MapResourceServerStore(KeycloakSession session, MapStorage resourceServerStore, AuthorizationProvider provider) {
+ public MapResourceServerStore(KeycloakSession session, MapStorage, ResourceServer> resourceServerStore, AuthorizationProvider provider) {
this.resourceServerStore = resourceServerStore;
this.tx = resourceServerStore.createTransaction(session);
this.authorizationProvider = provider;
session.getTransactionManager().enlist(tx);
}
- private MapResourceServerEntity registerEntityForChanges(MapResourceServerEntity origEntity) {
- final MapResourceServerEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapResourceServerEntity::isUpdated);
+ private MapResourceServerEntity registerEntityForChanges(MapResourceServerEntity origEntity) {
+ final MapResourceServerEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapResourceServerEntity::isUpdated);
return res;
}
- private ResourceServer entityToAdapter(MapResourceServerEntity origEntity) {
+ private ResourceServer entityToAdapter(MapResourceServerEntity origEntity) {
if (origEntity == null) return null;
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return new MapResourceServerAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory());
+ return new MapResourceServerAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory()) {
+ @Override
+ public String getId() {
+ return resourceServerStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
@Override
@@ -77,11 +82,11 @@ public class MapResourceServerStore implements ResourceServerStore {
throw new ModelException("Creating resource server from federated ClientModel not supported");
}
- if (tx.read(clientId) != null) {
+ if (tx.read(resourceServerStore.getKeyConvertor().fromString(clientId)) != null) {
throw new ModelDuplicateException("Resource server already exists: " + clientId);
}
- MapResourceServerEntity entity = new MapResourceServerEntity(clientId);
+ MapResourceServerEntity entity = new MapResourceServerEntity<>(resourceServerStore.getKeyConvertor().fromString(clientId));
tx.create(entity.getId(), entity);
@@ -113,7 +118,7 @@ public class MapResourceServerStore implements ResourceServerStore {
.map(Scope::getId)
.forEach(scopeStore::delete);
- tx.delete(id);
+ tx.delete(resourceServerStore.getKeyConvertor().fromString(id));
}
@Override
@@ -125,7 +130,7 @@ public class MapResourceServerStore implements ResourceServerStore {
}
- MapResourceServerEntity entity = tx.read(id);
+ MapResourceServerEntity entity = tx.read(resourceServerStore.getKeyConvertor().fromStringSafe(id));
return entityToAdapter(entity);
}
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java
index 4fbea321a8..728fc88ea1 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapResourceStore.java
@@ -26,7 +26,6 @@ import org.keycloak.authorization.store.ResourceStore;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelDuplicateException;
import org.keycloak.models.map.authorization.adapter.MapResourceAdapter;
-import org.keycloak.models.map.authorization.entity.AbstractResourceEntity;
import org.keycloak.models.map.authorization.entity.MapResourceEntity;
import org.keycloak.models.map.common.Serialization;
import org.keycloak.models.map.storage.MapKeycloakTransaction;
@@ -35,40 +34,45 @@ import org.keycloak.models.map.storage.ModelCriteriaBuilder;
import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import java.util.Arrays;
+import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
import static org.keycloak.utils.StreamsUtil.paginatedStream;
-public class MapResourceStore implements ResourceStore {
+public class MapResourceStore> implements ResourceStore {
private static final Logger LOG = Logger.getLogger(MapResourceStore.class);
private final AuthorizationProvider authorizationProvider;
- final MapKeycloakTransaction tx;
- private final MapStorage resourceStore;
+ final MapKeycloakTransaction, Resource> tx;
+ private final MapStorage, Resource> resourceStore;
- public MapResourceStore(KeycloakSession session, MapStorage resourceStore, AuthorizationProvider provider) {
+ public MapResourceStore(KeycloakSession session, MapStorage, Resource> resourceStore, AuthorizationProvider provider) {
this.resourceStore = resourceStore;
this.tx = resourceStore.createTransaction(session);
session.getTransactionManager().enlist(tx);
authorizationProvider = provider;
}
- private MapResourceEntity registerEntityForChanges(MapResourceEntity origEntity) {
- final MapResourceEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapResourceEntity::isUpdated);
+ private MapResourceEntity registerEntityForChanges(MapResourceEntity origEntity) {
+ final MapResourceEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapResourceEntity::isUpdated);
return res;
}
- private Resource entityToAdapter(MapResourceEntity origEntity) {
+ private Resource entityToAdapter(MapResourceEntity origEntity) {
if (origEntity == null) return null;
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return new MapResourceAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory());
+ return new MapResourceAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory()) {
+ @Override
+ public String getId() {
+ return resourceStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
private ModelCriteriaBuilder forResourceServer(String resourceServerId) {
@@ -92,8 +96,8 @@ public class MapResourceStore implements ResourceStore {
throw new ModelDuplicateException("Resource with name '" + name + "' for " + resourceServer.getId() + " already exists for request owner " + owner);
}
- UUID uid = id == null ? UUID.randomUUID() : UUID.fromString(id);
- MapResourceEntity entity = new MapResourceEntity(uid);
+ K uid = id == null ? resourceStore.getKeyConvertor().yieldNewUniqueKey(): resourceStore.getKeyConvertor().fromString(id);
+ MapResourceEntity entity = new MapResourceEntity<>(uid);
entity.setName(name);
entity.setResourceServerId(resourceServer.getId());
@@ -108,7 +112,7 @@ public class MapResourceStore implements ResourceStore {
public void delete(String id) {
LOG.tracef("delete(%s)%s", id, getShortStackTrace());
- tx.delete(UUID.fromString(id));
+ tx.delete(resourceStore.getKeyConvertor().fromString(id));
}
@Override
@@ -129,9 +133,10 @@ public class MapResourceStore implements ResourceStore {
private void findByOwnerFilter(String ownerId, String resourceServerId, Consumer consumer, int firstResult, int maxResult) {
LOG.tracef("findByOwnerFilter(%s, %s, %s, %d, %d)%s", ownerId, resourceServerId, consumer, firstResult, maxResult, getShortStackTrace());
+ Comparator super MapResourceEntity> c = Comparator.comparing(MapResourceEntity::getId);
paginatedStream(tx.getUpdatedNotRemoved(forResourceServer(resourceServerId)
.compare(SearchableFields.OWNER, Operator.EQ, ownerId))
- .sorted(MapResourceEntity.COMPARE_BY_ID), firstResult, maxResult)
+ .sorted(c), firstResult, maxResult)
.map(this::entityToAdapter)
.forEach(consumer);
}
@@ -174,7 +179,7 @@ public class MapResourceStore implements ResourceStore {
);
return paginatedStream(tx.getUpdatedNotRemoved(mcb)
- .sorted(AbstractResourceEntity.COMPARE_BY_NAME), firstResult, maxResult)
+ .sorted(MapResourceEntity.COMPARE_BY_NAME), firstResult, maxResult)
.map(this::entityToAdapter)
.collect(Collectors.toList());
}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java b/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java
index feaf37813c..4f5707043d 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/MapScopeStore.java
@@ -36,36 +36,40 @@ import org.keycloak.models.map.storage.ModelCriteriaBuilder.Operator;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.stream.Collectors;
import static org.keycloak.common.util.StackUtil.getShortStackTrace;
import static org.keycloak.utils.StreamsUtil.paginatedStream;
-public class MapScopeStore implements ScopeStore {
+public class MapScopeStore implements ScopeStore {
private static final Logger LOG = Logger.getLogger(MapScopeStore.class);
private final AuthorizationProvider authorizationProvider;
- final MapKeycloakTransaction tx;
- private final MapStorage scopeStore;
+ final MapKeycloakTransaction, Scope> tx;
+ private final MapStorage, Scope> scopeStore;
- public MapScopeStore(KeycloakSession session, MapStorage scopeStore, AuthorizationProvider provider) {
+ public MapScopeStore(KeycloakSession session, MapStorage, Scope> scopeStore, AuthorizationProvider provider) {
this.authorizationProvider = provider;
this.scopeStore = scopeStore;
this.tx = scopeStore.createTransaction(session);
session.getTransactionManager().enlist(tx);
}
- private MapScopeEntity registerEntityForChanges(MapScopeEntity origEntity) {
- final MapScopeEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
- tx.updateIfChanged(origEntity.getId(), res, MapScopeEntity::isUpdated);
+ private MapScopeEntity registerEntityForChanges(MapScopeEntity origEntity) {
+ final MapScopeEntity res = tx.read(origEntity.getId(), id -> Serialization.from(origEntity));
+ tx.updateIfChanged(origEntity.getId(), res, MapScopeEntity::isUpdated);
return res;
}
- private Scope entityToAdapter(MapScopeEntity origEntity) {
+ private Scope entityToAdapter(MapScopeEntity origEntity) {
if (origEntity == null) return null;
// Clone entity before returning back, to avoid giving away a reference to the live object to the caller
- return new MapScopeAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory());
+ return new MapScopeAdapter(registerEntityForChanges(origEntity), authorizationProvider.getStoreFactory()) {
+ @Override
+ public String getId() {
+ return scopeStore.getKeyConvertor().keyToString(entity.getId());
+ }
+ };
}
private ModelCriteriaBuilder forResourceServer(String resourceServerId) {
@@ -90,8 +94,8 @@ public class MapScopeStore implements ScopeStore {
throw new ModelDuplicateException("Scope with name '" + name + "' for " + resourceServer.getId() + " already exists");
}
- UUID uid = id == null ? UUID.randomUUID() : UUID.fromString(id);
- MapScopeEntity entity = new MapScopeEntity(uid);
+ K uid = id == null ? scopeStore.getKeyConvertor().yieldNewUniqueKey(): scopeStore.getKeyConvertor().fromString(id);
+ MapScopeEntity entity = new MapScopeEntity<>(uid);
entity.setName(name);
entity.setResourceServerId(resourceServer.getId());
@@ -104,7 +108,7 @@ public class MapScopeStore implements ScopeStore {
@Override
public void delete(String id) {
LOG.tracef("delete(%s)%s", id, getShortStackTrace());
- tx.delete(UUID.fromString(id));
+ tx.delete(scopeStore.getKeyConvertor().fromString(id));
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/AbstractResourceModel.java b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/AbstractResourceModel.java
index fb3301bfb1..9ff1da8f56 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/AbstractResourceModel.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/AbstractResourceModel.java
@@ -24,7 +24,7 @@ import org.keycloak.models.map.common.AbstractEntity;
import java.util.Objects;
-public abstract class AbstractResourceModel extends AbstractAuthorizationModel implements Resource {
+public abstract class AbstractResourceModel> extends AbstractAuthorizationModel implements Resource {
protected final E entity;
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapPermissionTicketAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapPermissionTicketAdapter.java
index 3f349ce2b4..1a02bdeb91 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapPermissionTicketAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapPermissionTicketAdapter.java
@@ -23,23 +23,17 @@ import org.keycloak.authorization.model.Resource;
import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.StoreFactory;
+
+
import org.keycloak.models.map.authorization.entity.MapPermissionTicketEntity;
-
-import java.util.UUID;
-
import static org.keycloak.authorization.UserManagedPermissionUtil.updatePolicy;
-public class MapPermissionTicketAdapter extends AbstractPermissionTicketModel {
+public abstract class MapPermissionTicketAdapter> extends AbstractPermissionTicketModel> {
- public MapPermissionTicketAdapter(MapPermissionTicketEntity entity, StoreFactory storeFactory) {
+ public MapPermissionTicketAdapter(MapPermissionTicketEntity entity, StoreFactory storeFactory) {
super(entity, storeFactory);
}
- @Override
- public String getId() {
- return entity.getId().toString();
- }
-
@Override
public String getOwner() {
return entity.getOwner();
@@ -52,13 +46,13 @@ public class MapPermissionTicketAdapter extends AbstractPermissionTicketModel {
+public abstract class MapPolicyAdapter extends AbstractPolicyModel> {
- public MapPolicyAdapter(MapPolicyEntity entity, StoreFactory storeFactory) {
+ public MapPolicyAdapter(MapPolicyEntity entity, StoreFactory storeFactory) {
super(entity, storeFactory);
}
- @Override
- public String getId() {
- return entity.getId().toString();
- }
-
@Override
public String getType() {
return entity.getType();
@@ -123,7 +117,7 @@ public class MapPolicyAdapter extends AbstractPolicyModel {
public Set getAssociatedPolicies() {
String resourceServerId = entity.getResourceServerId();
return entity.getAssociatedPoliciesIds().stream()
- .map(policyId -> storeFactory.getPolicyStore().findById(policyId.toString(), resourceServerId))
+ .map(policyId -> storeFactory.getPolicyStore().findById(policyId, resourceServerId))
.collect(Collectors.toSet());
}
@@ -131,7 +125,7 @@ public class MapPolicyAdapter extends AbstractPolicyModel {
public Set getResources() {
String resourceServerId = entity.getResourceServerId();
return entity.getResourceIds().stream()
- .map(resourceId -> storeFactory.getResourceStore().findById(resourceId.toString(), resourceServerId))
+ .map(resourceId -> storeFactory.getResourceStore().findById(resourceId, resourceServerId))
.collect(Collectors.toSet());
}
@@ -139,7 +133,7 @@ public class MapPolicyAdapter extends AbstractPolicyModel {
public Set getScopes() {
String resourceServerId = entity.getResourceServerId();
return entity.getScopeIds().stream()
- .map(scopeId -> storeFactory.getScopeStore().findById(scopeId.toString(), resourceServerId))
+ .map(scopeId -> storeFactory.getScopeStore().findById(scopeId, resourceServerId))
.collect(Collectors.toSet());
}
@@ -157,37 +151,37 @@ public class MapPolicyAdapter extends AbstractPolicyModel {
@Override
public void addScope(Scope scope) {
throwExceptionIfReadonly();
- entity.addScope(UUID.fromString(scope.getId()));
+ entity.addScope(scope.getId());
}
@Override
public void removeScope(Scope scope) {
throwExceptionIfReadonly();
- entity.removeScope(UUID.fromString(scope.getId()));
+ entity.removeScope(scope.getId());
}
@Override
public void addAssociatedPolicy(Policy associatedPolicy) {
throwExceptionIfReadonly();
- entity.addAssociatedPolicy(UUID.fromString(associatedPolicy.getId()));
+ entity.addAssociatedPolicy(associatedPolicy.getId());
}
@Override
public void removeAssociatedPolicy(Policy associatedPolicy) {
throwExceptionIfReadonly();
- entity.removeAssociatedPolicy(UUID.fromString(associatedPolicy.getId()));
+ entity.removeAssociatedPolicy(associatedPolicy.getId());
}
@Override
public void addResource(Resource resource) {
throwExceptionIfReadonly();
- entity.addResource(UUID.fromString(resource.getId()));
+ entity.addResource(resource.getId());
}
@Override
public void removeResource(Resource resource) {
throwExceptionIfReadonly();
- entity.removeResource(UUID.fromString(resource.getId()));
+ entity.removeResource(resource.getId());
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceAdapter.java
index 21987877bb..00b3f80465 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceAdapter.java
@@ -19,27 +19,21 @@ package org.keycloak.models.map.authorization.adapter;
import org.keycloak.authorization.model.Scope;
import org.keycloak.authorization.store.StoreFactory;
-import org.keycloak.models.map.authorization.entity.MapResourceEntity;
+import org.keycloak.models.map.authorization.entity.MapResourceEntity;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.UUID;
import java.util.stream.Collectors;
-public class MapResourceAdapter extends AbstractResourceModel {
+public abstract class MapResourceAdapter extends AbstractResourceModel> {
- public MapResourceAdapter(MapResourceEntity entity, StoreFactory storeFactory) {
+ public MapResourceAdapter(MapResourceEntity entity, StoreFactory storeFactory) {
super(entity, storeFactory);
}
- @Override
- public String getId() {
- return entity.getId().toString();
- }
-
@Override
public String getName() {
return entity.getName();
@@ -88,7 +82,7 @@ public class MapResourceAdapter extends AbstractResourceModel
public List getScopes() {
return entity.getScopeIds().stream()
.map(id -> storeFactory
- .getScopeStore().findById(id.toString(), entity.getResourceServerId()))
+ .getScopeStore().findById(id, entity.getResourceServerId()))
.collect(Collectors.toList());
}
@@ -127,7 +121,7 @@ public class MapResourceAdapter extends AbstractResourceModel
@Override
public void updateScopes(Set scopes) {
throwExceptionIfReadonly();
- entity.setScopeIds(scopes.stream().map(Scope::getId).map(UUID::fromString).collect(Collectors.toSet()));
+ entity.setScopeIds(scopes.stream().map(Scope::getId).collect(Collectors.toSet()));
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceServerAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceServerAdapter.java
index 7aa5b8932c..e1aa858392 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceServerAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapResourceServerAdapter.java
@@ -23,17 +23,12 @@ import org.keycloak.models.map.authorization.entity.MapResourceServerEntity;
import org.keycloak.representations.idm.authorization.DecisionStrategy;
import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
-public class MapResourceServerAdapter extends AbstractResourceServerModel {
+public abstract class MapResourceServerAdapter extends AbstractResourceServerModel> {
- public MapResourceServerAdapter(MapResourceServerEntity entity, StoreFactory storeFactory) {
+ public MapResourceServerAdapter(MapResourceServerEntity entity, StoreFactory storeFactory) {
super(entity, storeFactory);
}
- @Override
- public String getId() {
- return entity.getId();
- }
-
@Override
public boolean isAllowRemoteResourceManagement() {
return entity.isAllowRemoteResourceManagement();
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapScopeAdapter.java b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapScopeAdapter.java
index 21080939d9..ce8a6ddc63 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapScopeAdapter.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/adapter/MapScopeAdapter.java
@@ -22,17 +22,12 @@ import org.keycloak.authorization.model.ResourceServer;
import org.keycloak.authorization.store.StoreFactory;
import org.keycloak.models.map.authorization.entity.MapScopeEntity;
-public class MapScopeAdapter extends AbstractScopeModel {
+public abstract class MapScopeAdapter extends AbstractScopeModel> {
- public MapScopeAdapter(MapScopeEntity entity, StoreFactory storeFactory) {
+ public MapScopeAdapter(MapScopeEntity entity, StoreFactory storeFactory) {
super(entity, storeFactory);
}
- @Override
- public String getId() {
- return entity.getId().toString();
- }
-
@Override
public String getName() {
return entity.getName();
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPermissionTicketEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPermissionTicketEntity.java
deleted file mode 100644
index 9f9c4afaa1..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPermissionTicketEntity.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.keycloak.models.map.authorization.entity;
-
-import org.keycloak.models.map.common.AbstractEntity;
-
-import java.util.Objects;
-
-public abstract class AbstractPermissionTicketEntity implements AbstractEntity {
-
- private final K id;
- private String owner;
- private String requester;
- private Long createdTimestamp;
- private Long grantedTimestamp;
- private K resourceId;
- private K scopeId;
- private String resourceServerId;
- private K policyId;
- private boolean updated = false;
-
- protected AbstractPermissionTicketEntity(K id) {
- this.id = id;
- }
-
- public AbstractPermissionTicketEntity() {
- this.id = null;
- }
-
- @Override
- public K getId() {
- return id;
- }
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.updated |= !Objects.equals(this.owner, owner);
- this.owner = owner;
- }
-
- public String getRequester() {
- return requester;
- }
-
- public void setRequester(String requester) {
- this.updated |= !Objects.equals(this.requester, requester);
- this.requester = requester;
- }
-
- public Long getCreatedTimestamp() {
- return createdTimestamp;
- }
-
- public void setCreatedTimestamp(Long createdTimestamp) {
- this.updated |= !Objects.equals(this.createdTimestamp, createdTimestamp);
- this.createdTimestamp = createdTimestamp;
- }
-
- public Long getGrantedTimestamp() {
- return grantedTimestamp;
- }
-
- public void setGrantedTimestamp(Long grantedTimestamp) {
- this.updated |= !Objects.equals(this.grantedTimestamp, grantedTimestamp);
- this.grantedTimestamp = grantedTimestamp;
- }
-
- public K getResourceId() {
- return resourceId;
- }
-
- public void setResourceId(K resourceId) {
- this.updated |= !Objects.equals(this.resourceId, resourceId);
- this.resourceId = resourceId;
- }
-
- public K getScopeId() {
- return scopeId;
- }
-
- public void setScopeId(K scopeId) {
- this.updated |= !Objects.equals(this.scopeId, scopeId);
- this.scopeId = scopeId;
- }
-
- public String getResourceServerId() {
- return resourceServerId;
- }
-
- public void setResourceServerId(String resourceServerId) {
- this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
- this.resourceServerId = resourceServerId;
- }
-
- public K getPolicyId() {
- return policyId;
- }
-
- public void setPolicyId(K policyId) {
- this.updated |= !Objects.equals(this.policyId, policyId);
- this.policyId = policyId;
- }
-
- @Override
- public boolean isUpdated() {
- return updated;
- }
-
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPolicyEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPolicyEntity.java
deleted file mode 100644
index e75afcb611..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractPolicyEntity.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.keycloak.models.map.authorization.entity;
-
-import org.keycloak.models.map.common.AbstractEntity;
-import org.keycloak.representations.idm.authorization.DecisionStrategy;
-import org.keycloak.representations.idm.authorization.Logic;
-
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Map;
-import java.util.Objects;
-
-public abstract class AbstractPolicyEntity implements AbstractEntity {
-
- public static final Comparator> COMPARE_BY_NAME = Comparator.comparing(AbstractPolicyEntity::getName);
-
- private final K id;
- private String name;
- private String description;
- private String type;
- private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
- private Logic logic = Logic.POSITIVE;
- private final Map config = new HashMap<>();
- private String resourceServerId;
- private final Set associatedPoliciesIds = new HashSet<>();
- private final Set resourceIds = new HashSet<>();
- private final Set scopeIds = new HashSet<>();
- private String owner;
- private boolean updated = false;
-
- protected AbstractPolicyEntity(K id) {
- this.id = id;
- }
-
- public AbstractPolicyEntity() {
- this.id = null;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.updated |= !Objects.equals(this.name, name);
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.updated |= !Objects.equals(this.description, description);
- this.description = description;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.updated |= !Objects.equals(this.type, type);
- this.type = type;
- }
-
- public DecisionStrategy getDecisionStrategy() {
- return decisionStrategy;
- }
-
- public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
- this.updated |= !Objects.equals(this.decisionStrategy, decisionStrategy);
- this.decisionStrategy = decisionStrategy;
- }
-
- public Logic getLogic() {
- return logic;
- }
-
- public void setLogic(Logic logic) {
- this.updated |= !Objects.equals(this.logic, logic);
- this.logic = logic;
- }
-
- public Map getConfig() {
- return config;
- }
-
- public String getConfigValue(String name) {
- return config.get(name);
- }
-
- public void setConfig(Map config) {
- if (Objects.equals(this.config, config)) return;
-
- this.updated = true;
- this.config.clear();
- if (config != null) {
- this.config.putAll(config);
- }
- }
-
- public void removeConfig(String name) {
- this.updated |= this.config.remove(name) != null;
- }
-
- public void putConfig(String name, String value) {
- this.updated |= !Objects.equals(value, this.config.put(name, value));
- }
-
- public String getResourceServerId() {
- return resourceServerId;
- }
-
- public void setResourceServerId(String resourceServerId) {
- this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
- this.resourceServerId = resourceServerId;
- }
-
- public Set getAssociatedPoliciesIds() {
- return associatedPoliciesIds;
- }
-
- public void addAssociatedPolicy(K policyId) {
- this.updated |= this.associatedPoliciesIds.add(policyId);
- }
-
- public void removeAssociatedPolicy(K policyId) {
- this.updated |= this.associatedPoliciesIds.remove(policyId);
- }
-
- public Set getResourceIds() {
- return resourceIds;
- }
-
- public void addResource(K resourceId) {
- this.updated |= this.resourceIds.add(resourceId);
- }
-
- public void removeResource(K resourceId) {
- this.updated |= this.resourceIds.remove(resourceId);
- }
-
- public Set getScopeIds() {
- return scopeIds;
- }
-
- public void addScope(K scopeId) {
- this.updated |= this.scopeIds.add(scopeId);
- }
-
- public void removeScope(K scopeId) {
- this.updated |= this.scopeIds.remove(scopeId);
- }
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.updated |= !Objects.equals(this.owner, owner);
- this.owner = owner;
- }
-
- @Override
- public K getId() {
- return id;
- }
-
- @Override
- public boolean isUpdated() {
- return updated;
- }
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceEntity.java
deleted file mode 100644
index be8f19366e..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceEntity.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.keycloak.models.map.authorization.entity;
-
-import org.keycloak.models.map.common.AbstractEntity;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-
-public abstract class AbstractResourceEntity implements AbstractEntity {
-
- public static final Comparator> COMPARE_BY_NAME = Comparator.comparing(AbstractResourceEntity::getName);
-
- private final K id;
- private String name;
- private String displayName;
- private final Set uris = new HashSet<>();
- private String type;
- private String iconUri;
- private String owner;
- private boolean ownerManagedAccess;
- private String resourceServerId;
- private final Set scopeIds = new HashSet<>();
- private final Set policyIds = new HashSet<>();
- private final Map> attributes = new HashMap<>();
- private boolean updated = false;
-
- protected AbstractResourceEntity(K id) {
- this.id = id;
- }
-
- public AbstractResourceEntity() {
- this.id = null;
- }
-
- @Override
- public K getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.updated |= !Objects.equals(this.name, name);
- this.name = name;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.updated |= !Objects.equals(this.displayName, displayName);
- this.displayName = displayName;
- }
-
- public Set getUris() {
- return uris;
- }
-
- public void setUris(Set uris) {
- if (Objects.equals(this.uris, uris)) return;
-
- this.updated = true;
- this.uris.clear();
-
- if (uris != null) {
- this.uris.addAll(uris);
- }
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.updated |= !Objects.equals(this.type, type);
- this.type = type;
- }
-
- public String getIconUri() {
- return iconUri;
- }
-
- public void setIconUri(String iconUri) {
- this.updated |= !Objects.equals(this.iconUri, iconUri);
- this.iconUri = iconUri;
- }
-
- public String getOwner() {
- return owner;
- }
-
- public void setOwner(String owner) {
- this.updated |= !Objects.equals(this.owner, owner);
- this.owner = owner;
- }
-
- public boolean isOwnerManagedAccess() {
- return ownerManagedAccess;
- }
-
- public void setOwnerManagedAccess(boolean ownerManagedAccess) {
- this.updated |= this.ownerManagedAccess != ownerManagedAccess;
- this.ownerManagedAccess = ownerManagedAccess;
- }
-
- public String getResourceServerId() {
- return resourceServerId;
- }
-
- public void setResourceServerId(String resourceServerId) {
- this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
- this.resourceServerId = resourceServerId;
- }
-
- public Set getScopeIds() {
- return scopeIds;
- }
-
- public void setScopeIds(Set scopeIds) {
- if (Objects.equals(this.scopeIds, scopeIds)) return;
-
- this.updated = true;
- this.scopeIds.clear();
- if (scopeIds != null) {
- this.scopeIds.addAll(scopeIds);
- }
- }
-
- public Set getPolicyIds() {
- return policyIds;
- }
-
- public Map> getAttributes() {
- return attributes;
- }
-
- public List getAttribute(String name) {
- return attributes.get(name);
- }
-
- public String getSingleAttribute(String name) {
- List attributeValues = attributes.get(name);
- return attributeValues == null || attributeValues.isEmpty() ? null : attributeValues.get(0);
- }
-
- public void setAttribute(String name, List value) {
- this.updated |= !Objects.equals(this.attributes.put(name, value), value);
- }
-
- public void removeAttribute(String name) {
- this.updated |= this.attributes.remove(name) != null;
- }
-
- @Override
- public boolean isUpdated() {
- return updated;
- }
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceServerEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceServerEntity.java
deleted file mode 100644
index f8bbacb897..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractResourceServerEntity.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.keycloak.models.map.authorization.entity;
-
-import org.keycloak.models.map.common.AbstractEntity;
-import org.keycloak.representations.idm.authorization.DecisionStrategy;
-import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
-
-import java.util.Objects;
-
-public abstract class AbstractResourceServerEntity implements AbstractEntity {
-
- private final K id;
- private boolean updated = false;
-
- private boolean allowRemoteResourceManagement;
- private PolicyEnforcementMode policyEnforcementMode = PolicyEnforcementMode.ENFORCING;
- private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
-
- protected AbstractResourceServerEntity(K id) {
- this.id = id;
- }
-
- public AbstractResourceServerEntity() {
- this.id = null;
- }
-
- @Override
- public K getId() {
- return id;
- }
-
- public boolean isAllowRemoteResourceManagement() {
- return allowRemoteResourceManagement;
- }
-
- public void setAllowRemoteResourceManagement(boolean allowRemoteResourceManagement) {
- this.updated |= this.allowRemoteResourceManagement != allowRemoteResourceManagement;
- this.allowRemoteResourceManagement = allowRemoteResourceManagement;
- }
-
- public PolicyEnforcementMode getPolicyEnforcementMode() {
- return policyEnforcementMode;
- }
-
- public void setPolicyEnforcementMode(PolicyEnforcementMode policyEnforcementMode) {
- this.updated |= !Objects.equals(this.policyEnforcementMode, policyEnforcementMode);
- this.policyEnforcementMode = policyEnforcementMode;
- }
-
- public DecisionStrategy getDecisionStrategy() {
- return decisionStrategy;
- }
-
- public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
- this.updated |= !Objects.equals(this.decisionStrategy, decisionStrategy);
- this.decisionStrategy = decisionStrategy;
- }
-
- @Override
- public boolean isUpdated() {
- return updated;
- }
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractScopeEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractScopeEntity.java
deleted file mode 100644
index cfcb202ce6..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/AbstractScopeEntity.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2021 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.keycloak.models.map.authorization.entity;
-
-import org.keycloak.models.map.common.AbstractEntity;
-
-import java.util.Objects;
-
-public abstract class AbstractScopeEntity implements AbstractEntity {
-
- private final K id;
- private String name;
- private String displayName;
- private String iconUri;
- private String resourceServerId;
- private boolean updated = false;
-
- protected AbstractScopeEntity(K id) {
- this.id = id;
- }
-
- public AbstractScopeEntity() {
- this.id = null;
- }
-
- @Override
- public K getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.updated |= !Objects.equals(this.name, name);
- this.name = name;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.updated |= !Objects.equals(this.displayName, displayName);
- this.displayName = displayName;
- }
-
- public String getIconUri() {
- return iconUri;
- }
-
- public void setIconUri(String iconUri) {
- this.updated |= !Objects.equals(this.iconUri, iconUri);
- this.iconUri = iconUri;
- }
-
- public String getResourceServerId() {
- return resourceServerId;
- }
-
- public void setResourceServerId(String resourceServerId) {
- this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
- this.resourceServerId = resourceServerId;
- }
-
- @Override
- public boolean isUpdated() {
- return updated;
- }
-}
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPermissionTicketEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPermissionTicketEntity.java
index 8932d5273e..f6e383b07e 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPermissionTicketEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPermissionTicketEntity.java
@@ -17,21 +17,114 @@
package org.keycloak.models.map.authorization.entity;
+import org.keycloak.models.map.common.AbstractEntity;
+
import java.util.Comparator;
-import java.util.UUID;
+import java.util.Objects;
-public class MapPermissionTicketEntity extends AbstractPermissionTicketEntity {
+public class MapPermissionTicketEntity implements AbstractEntity {
- public static final Comparator> COMPARE_BY_ID = Comparator.comparing(AbstractPermissionTicketEntity::getId);
- public static final Comparator> COMPARE_BY_RESOURCE_ID = Comparator.comparing(AbstractPermissionTicketEntity::getResourceId);
+ public static final Comparator> COMPARE_BY_RESOURCE_ID = Comparator.comparing(MapPermissionTicketEntity::getResourceId);
+ private final K id;
+ private String owner;
+ private String requester;
+ private Long createdTimestamp;
+ private Long grantedTimestamp;
+ private String resourceId;
+ private String scopeId;
+ private String resourceServerId;
+ private String policyId;
+ private boolean updated = false;
- protected MapPermissionTicketEntity() {
- super();
+ public MapPermissionTicketEntity(K id) {
+ this.id = id;
}
- public MapPermissionTicketEntity(UUID id) {
- super(id);
+ public MapPermissionTicketEntity() {
+ this.id = null;
+ }
+
+ @Override
+ public K getId() {
+ return id;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.updated |= !Objects.equals(this.owner, owner);
+ this.owner = owner;
+ }
+
+ public String getRequester() {
+ return requester;
+ }
+
+ public void setRequester(String requester) {
+ this.updated |= !Objects.equals(this.requester, requester);
+ this.requester = requester;
+ }
+
+ public Long getCreatedTimestamp() {
+ return createdTimestamp;
+ }
+
+ public void setCreatedTimestamp(Long createdTimestamp) {
+ this.updated |= !Objects.equals(this.createdTimestamp, createdTimestamp);
+ this.createdTimestamp = createdTimestamp;
+ }
+
+ public Long getGrantedTimestamp() {
+ return grantedTimestamp;
+ }
+
+ public void setGrantedTimestamp(Long grantedTimestamp) {
+ this.updated |= !Objects.equals(this.grantedTimestamp, grantedTimestamp);
+ this.grantedTimestamp = grantedTimestamp;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.updated |= !Objects.equals(this.resourceId, resourceId);
+ this.resourceId = resourceId;
+ }
+
+ public String getScopeId() {
+ return scopeId;
+ }
+
+ public void setScopeId(String scopeId) {
+ this.updated |= !Objects.equals(this.scopeId, scopeId);
+ this.scopeId = scopeId;
+ }
+
+ public String getResourceServerId() {
+ return resourceServerId;
+ }
+
+ public void setResourceServerId(String resourceServerId) {
+ this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
+ this.resourceServerId = resourceServerId;
+ }
+
+ public String getPolicyId() {
+ return policyId;
+ }
+
+ public void setPolicyId(String policyId) {
+ this.updated |= !Objects.equals(this.policyId, policyId);
+ this.policyId = policyId;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return updated;
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPolicyEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPolicyEntity.java
index 240d8a7644..73a9c21a4b 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPolicyEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapPolicyEntity.java
@@ -17,15 +17,176 @@
package org.keycloak.models.map.authorization.entity;
-import java.util.UUID;
+import org.keycloak.models.map.common.AbstractEntity;
+import org.keycloak.representations.idm.authorization.DecisionStrategy;
+import org.keycloak.representations.idm.authorization.Logic;
-public class MapPolicyEntity extends AbstractPolicyEntity {
- protected MapPolicyEntity() {
- super();
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Map;
+import java.util.Objects;
+
+public class MapPolicyEntity implements AbstractEntity {
+
+ public static final Comparator> COMPARE_BY_NAME = Comparator.comparing(MapPolicyEntity::getName);
+
+ private final K id;
+ private String name;
+ private String description;
+ private String type;
+ private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
+ private Logic logic = Logic.POSITIVE;
+ private final Map config = new HashMap<>();
+ private String resourceServerId;
+ private final Set associatedPoliciesIds = new HashSet<>();
+ private final Set resourceIds = new HashSet<>();
+ private final Set scopeIds = new HashSet<>();
+ private String owner;
+ private boolean updated = false;
+
+ public MapPolicyEntity(K id) {
+ this.id = id;
}
- public MapPolicyEntity(UUID id) {
- super(id);
+ public MapPolicyEntity() {
+ this.id = null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.updated |= !Objects.equals(this.name, name);
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.updated |= !Objects.equals(this.description, description);
+ this.description = description;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.updated |= !Objects.equals(this.type, type);
+ this.type = type;
+ }
+
+ public DecisionStrategy getDecisionStrategy() {
+ return decisionStrategy;
+ }
+
+ public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
+ this.updated |= !Objects.equals(this.decisionStrategy, decisionStrategy);
+ this.decisionStrategy = decisionStrategy;
+ }
+
+ public Logic getLogic() {
+ return logic;
+ }
+
+ public void setLogic(Logic logic) {
+ this.updated |= !Objects.equals(this.logic, logic);
+ this.logic = logic;
+ }
+
+ public Map getConfig() {
+ return config;
+ }
+
+ public String getConfigValue(String name) {
+ return config.get(name);
+ }
+
+ public void setConfig(Map config) {
+ if (Objects.equals(this.config, config)) return;
+
+ this.updated = true;
+ this.config.clear();
+ if (config != null) {
+ this.config.putAll(config);
+ }
+ }
+
+ public void removeConfig(String name) {
+ this.updated |= this.config.remove(name) != null;
+ }
+
+ public void putConfig(String name, String value) {
+ this.updated |= !Objects.equals(value, this.config.put(name, value));
+ }
+
+ public String getResourceServerId() {
+ return resourceServerId;
+ }
+
+ public void setResourceServerId(String resourceServerId) {
+ this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
+ this.resourceServerId = resourceServerId;
+ }
+
+ public Set getAssociatedPoliciesIds() {
+ return associatedPoliciesIds;
+ }
+
+ public void addAssociatedPolicy(String policyId) {
+ this.updated |= this.associatedPoliciesIds.add(policyId);
+ }
+
+ public void removeAssociatedPolicy(String policyId) {
+ this.updated |= this.associatedPoliciesIds.remove(policyId);
+ }
+
+ public Set getResourceIds() {
+ return resourceIds;
+ }
+
+ public void addResource(String resourceId) {
+ this.updated |= this.resourceIds.add(resourceId);
+ }
+
+ public void removeResource(String resourceId) {
+ this.updated |= this.resourceIds.remove(resourceId);
+ }
+
+ public Set getScopeIds() {
+ return scopeIds;
+ }
+
+ public void addScope(String scopeId) {
+ this.updated |= this.scopeIds.add(scopeId);
+ }
+
+ public void removeScope(String scopeId) {
+ this.updated |= this.scopeIds.remove(scopeId);
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.updated |= !Objects.equals(this.owner, owner);
+ this.owner = owner;
+ }
+
+ @Override
+ public K getId() {
+ return id;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return updated;
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceEntity.java
index c41c65ee38..41e2c32922 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceEntity.java
@@ -17,18 +17,167 @@
package org.keycloak.models.map.authorization.entity;
+import org.keycloak.models.map.common.AbstractEntity;
+
import java.util.Comparator;
-import java.util.UUID;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
-public class MapResourceEntity extends AbstractResourceEntity {
- public static final Comparator> COMPARE_BY_ID = Comparator.comparing(AbstractResourceEntity::getId);
+public class MapResourceEntity implements AbstractEntity {
+
+ public static final Comparator> COMPARE_BY_NAME = Comparator.comparing(MapResourceEntity::getName);
- protected MapResourceEntity() {
- super();
+ private final K id;
+ private String name;
+ private String displayName;
+ private final Set uris = new HashSet<>();
+ private String type;
+ private String iconUri;
+ private String owner;
+ private boolean ownerManagedAccess;
+ private String resourceServerId;
+ private final Set scopeIds = new HashSet<>();
+ private final Set policyIds = new HashSet<>();
+ private final Map> attributes = new HashMap<>();
+ private boolean updated = false;
+
+ public MapResourceEntity(K id) {
+ this.id = id;
}
- public MapResourceEntity(UUID id) {
- super(id);
+ public MapResourceEntity() {
+ this.id = null;
+ }
+
+ @Override
+ public K getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.updated |= !Objects.equals(this.name, name);
+ this.name = name;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.updated |= !Objects.equals(this.displayName, displayName);
+ this.displayName = displayName;
+ }
+
+ public Set getUris() {
+ return uris;
+ }
+
+ public void setUris(Set uris) {
+ if (Objects.equals(this.uris, uris)) return;
+
+ this.updated = true;
+ this.uris.clear();
+
+ if (uris != null) {
+ this.uris.addAll(uris);
+ }
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.updated |= !Objects.equals(this.type, type);
+ this.type = type;
+ }
+
+ public String getIconUri() {
+ return iconUri;
+ }
+
+ public void setIconUri(String iconUri) {
+ this.updated |= !Objects.equals(this.iconUri, iconUri);
+ this.iconUri = iconUri;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.updated |= !Objects.equals(this.owner, owner);
+ this.owner = owner;
+ }
+
+ public boolean isOwnerManagedAccess() {
+ return ownerManagedAccess;
+ }
+
+ public void setOwnerManagedAccess(boolean ownerManagedAccess) {
+ this.updated |= this.ownerManagedAccess != ownerManagedAccess;
+ this.ownerManagedAccess = ownerManagedAccess;
+ }
+
+ public String getResourceServerId() {
+ return resourceServerId;
+ }
+
+ public void setResourceServerId(String resourceServerId) {
+ this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
+ this.resourceServerId = resourceServerId;
+ }
+
+ public Set getScopeIds() {
+ return scopeIds;
+ }
+
+ public void setScopeIds(Set scopeIds) {
+ if (Objects.equals(this.scopeIds, scopeIds)) return;
+
+ this.updated = true;
+ this.scopeIds.clear();
+ if (scopeIds != null) {
+ this.scopeIds.addAll(scopeIds);
+ }
+ }
+
+ public Set getPolicyIds() {
+ return policyIds;
+ }
+
+ public Map> getAttributes() {
+ return attributes;
+ }
+
+ public List getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ public String getSingleAttribute(String name) {
+ List attributeValues = attributes.get(name);
+ return attributeValues == null || attributeValues.isEmpty() ? null : attributeValues.get(0);
+ }
+
+ public void setAttribute(String name, List value) {
+ this.updated |= !Objects.equals(this.attributes.put(name, value), value);
+ }
+
+ public void removeAttribute(String name) {
+ this.updated |= this.attributes.remove(name) != null;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return updated;
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceServerEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceServerEntity.java
index a78ca804c4..00776bf771 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceServerEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapResourceServerEntity.java
@@ -17,13 +17,64 @@
package org.keycloak.models.map.authorization.entity;
-public class MapResourceServerEntity extends AbstractResourceServerEntity {
- protected MapResourceServerEntity() {
- super();
+import org.keycloak.models.map.common.AbstractEntity;
+import org.keycloak.representations.idm.authorization.DecisionStrategy;
+import org.keycloak.representations.idm.authorization.PolicyEnforcementMode;
+
+import java.util.Objects;
+
+public class MapResourceServerEntity implements AbstractEntity {
+
+ private final K id;
+ private boolean updated = false;
+
+ private boolean allowRemoteResourceManagement;
+ private PolicyEnforcementMode policyEnforcementMode = PolicyEnforcementMode.ENFORCING;
+ private DecisionStrategy decisionStrategy = DecisionStrategy.UNANIMOUS;
+
+ public MapResourceServerEntity(K id) {
+ this.id = id;
}
- public MapResourceServerEntity(String id) {
- super(id);
+ public MapResourceServerEntity() {
+ this.id = null;
+ }
+
+ @Override
+ public K getId() {
+ return id;
+ }
+
+ public boolean isAllowRemoteResourceManagement() {
+ return allowRemoteResourceManagement;
+ }
+
+ public void setAllowRemoteResourceManagement(boolean allowRemoteResourceManagement) {
+ this.updated |= this.allowRemoteResourceManagement != allowRemoteResourceManagement;
+ this.allowRemoteResourceManagement = allowRemoteResourceManagement;
+ }
+
+ public PolicyEnforcementMode getPolicyEnforcementMode() {
+ return policyEnforcementMode;
+ }
+
+ public void setPolicyEnforcementMode(PolicyEnforcementMode policyEnforcementMode) {
+ this.updated |= !Objects.equals(this.policyEnforcementMode, policyEnforcementMode);
+ this.policyEnforcementMode = policyEnforcementMode;
+ }
+
+ public DecisionStrategy getDecisionStrategy() {
+ return decisionStrategy;
+ }
+
+ public void setDecisionStrategy(DecisionStrategy decisionStrategy) {
+ this.updated |= !Objects.equals(this.decisionStrategy, decisionStrategy);
+ this.decisionStrategy = decisionStrategy;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return updated;
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapScopeEntity.java b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapScopeEntity.java
index 52776ae439..b32461c4b5 100644
--- a/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapScopeEntity.java
+++ b/model/map/src/main/java/org/keycloak/models/map/authorization/entity/MapScopeEntity.java
@@ -17,15 +17,71 @@
package org.keycloak.models.map.authorization.entity;
-import java.util.UUID;
+import org.keycloak.models.map.common.AbstractEntity;
-public class MapScopeEntity extends AbstractScopeEntity {
- protected MapScopeEntity() {
- super();
+import java.util.Objects;
+
+public class MapScopeEntity implements AbstractEntity {
+
+ private final K id;
+ private String name;
+ private String displayName;
+ private String iconUri;
+ private String resourceServerId;
+ private boolean updated = false;
+
+ public MapScopeEntity(K id) {
+ this.id = id;
}
- public MapScopeEntity(UUID id) {
- super(id);
+ public MapScopeEntity() {
+ this.id = null;
+ }
+
+ @Override
+ public K getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.updated |= !Objects.equals(this.name, name);
+ this.name = name;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public void setDisplayName(String displayName) {
+ this.updated |= !Objects.equals(this.displayName, displayName);
+ this.displayName = displayName;
+ }
+
+ public String getIconUri() {
+ return iconUri;
+ }
+
+ public void setIconUri(String iconUri) {
+ this.updated |= !Objects.equals(this.iconUri, iconUri);
+ this.iconUri = iconUri;
+ }
+
+ public String getResourceServerId() {
+ return resourceServerId;
+ }
+
+ public void setResourceServerId(String resourceServerId) {
+ this.updated |= !Objects.equals(this.resourceServerId, resourceServerId);
+ this.resourceServerId = resourceServerId;
+ }
+
+ @Override
+ public boolean isUpdated() {
+ return updated;
}
@Override
diff --git a/model/map/src/main/java/org/keycloak/models/map/client/AbstractClientEntity.java b/model/map/src/main/java/org/keycloak/models/map/client/AbstractClientEntity.java
deleted file mode 100644
index 5ba50aa490..0000000000
--- a/model/map/src/main/java/org/keycloak/models/map/client/AbstractClientEntity.java
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- * Copyright 2020 Red Hat, Inc. and/or its affiliates
- * and other contributors as indicated by the @author tags.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.keycloak.models.map.client;
-
-import org.keycloak.models.ProtocolMapperModel;
-import org.keycloak.models.map.common.AbstractEntity;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-/**
- *
- * @author hmlnarik
- */
-public abstract class AbstractClientEntity implements AbstractEntity {
-
- private K id;
- private String realmId;
-
- private String clientId;
- private String name;
- private String description;
- private Set redirectUris = new HashSet<>();
- private boolean enabled;
- private boolean alwaysDisplayInConsole;
- private String clientAuthenticatorType;
- private String secret;
- private String registrationToken;
- private String protocol;
- private Map attributes = new HashMap<>();
- private Map authFlowBindings = new HashMap<>();
- private boolean publicClient;
- private boolean fullScopeAllowed;
- private boolean frontchannelLogout;
- private int notBefore;
- private Set scope = new HashSet<>();
- private Set webOrigins = new HashSet<>();
- private Map protocolMappers = new HashMap<>();
- private Map clientScopes = new HashMap<>();
- private Set scopeMappings = new LinkedHashSet<>();
- private boolean surrogateAuthRequired;
- private String managementUrl;
- private String rootUrl;
- private String baseUrl;
- private boolean bearerOnly;
- private boolean consentRequired;
- private boolean standardFlowEnabled;
- private boolean implicitFlowEnabled;
- private boolean directAccessGrantsEnabled;
- private boolean serviceAccountsEnabled;
- private int nodeReRegistrationTimeout;
-
- /**
- * Flag signalizing that any of the setters has been meaningfully used.
- */
- protected boolean updated;
-
- protected AbstractClientEntity() {
- this.id = null;
- this.realmId = null;
- }
-
- public AbstractClientEntity(K id, String realmId) {
- Objects.requireNonNull(id, "id");
- Objects.requireNonNull(realmId, "realmId");
-
- this.id = id;
- this.realmId = realmId;
- }
-
- @Override
- public K getId() {
- return this.id;
- }
-
- @Override
- public boolean isUpdated() {
- return this.updated;
- }
-
- public String getClientId() {
- return clientId;
- }
-
- public void setClientId(String clientId) {
- this.updated |= ! Objects.equals(this.clientId, clientId);
- this.clientId = clientId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.updated |= ! Objects.equals(this.name, name);
- this.name = name;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.updated |= ! Objects.equals(this.description, description);
- this.description = description;
- }
-
- public Set getRedirectUris() {
- return redirectUris;
- }
-
- public void setRedirectUris(Set