From 235512efc0fa6cc7994b6e7dc6153831b358e084 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 16 Apr 2024 14:21:37 +0300 Subject: [PATCH 1/5] keycloak changes --- .../data/UserContactInfoEntity.java | 125 ---------- .../annotation/model/UserContactInfo.java | 76 ------ .../model/deleter/UserContactInfoDeleter.java | 68 ----- .../annotation/model/deleter/UserDeleter.java | 7 - .../query/UserContactInfoQuery.java | 236 ------------------ .../service/user/UserServiceImpl.java | 36 --- dmp-backend/core/pom.xml | 2 +- .../KeycloakResourcesConfiguration.java | 4 +- .../service/keycloak/KeycloakServiceImpl.java | 67 ++--- dmp-backend/pom.xml | 2 +- 10 files changed, 27 insertions(+), 596 deletions(-) delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/data/UserContactInfoEntity.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/model/UserContactInfo.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserContactInfoDeleter.java delete mode 100644 annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserContactInfoQuery.java diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/UserContactInfoEntity.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/data/UserContactInfoEntity.java deleted file mode 100644 index f360d53de..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/data/UserContactInfoEntity.java +++ /dev/null @@ -1,125 +0,0 @@ -package gr.cite.annotation.data; - -import gr.cite.annotation.common.enums.ContactInfoType; -import gr.cite.annotation.common.enums.IsActive; -import gr.cite.annotation.data.conventers.ContactInfoTypeConverter; -import gr.cite.annotation.data.conventers.IsActiveConverter; -import gr.cite.annotation.data.tenant.TenantScopedBaseEntity; -import jakarta.persistence.*; - -import java.time.Instant; -import java.util.UUID; - -@Entity -@Table(name = "\"UserContactInfo\"") -public class UserContactInfoEntity { - - @Id - @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false) - private UUID id; - - public static final String _id = "id"; - - @Column(name = "\"user\"", nullable = false) - private UUID userId; - - public static final String _userId = "userId"; - - @Column(name = "\"ordinal\"", nullable = false) - private Integer ordinal; - - public static final String _ordinal = "ordinal"; - - @Column(name = "type", length = 100, nullable = false) - @Convert(converter = ContactInfoTypeConverter.class) - private ContactInfoType type; - - public static final String _type = "type"; - - @Column(name = "value", nullable = false) - private String value; - - public static final String _value = "value"; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - public static final String _createdAt = "createdAt"; - - @Column(name = "updated_at", nullable = false) - private Instant updatedAt; - - public static final String _updatedAt = "updatedAt"; - - @Column(name = "\"is_active\"", nullable = false) - @Convert(converter = IsActiveConverter.class) - private IsActive isActive; - - public static final String _isActive = "isActive"; - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public ContactInfoType getType() { - return type; - } - - public void setType(ContactInfoType type) { - this.type = type; - } - - public String getValue() { - return value; - } - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public Integer getOrdinal() { - return ordinal; - } - - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; - } - - public void setValue(String value) { - this.value = value; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public Instant getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Instant updatedAt) { - this.updatedAt = updatedAt; - } - - public IsActive getIsActive() { - return isActive; - } - - public void setIsActive(IsActive isActive) { - this.isActive = isActive; - } - -} - diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/UserContactInfo.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/UserContactInfo.java deleted file mode 100644 index 0bde01f50..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/UserContactInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -package gr.cite.annotation.model; - - -import gr.cite.annotation.common.enums.ContactInfoType; - -import java.time.Instant; -import java.util.UUID; - -public class UserContactInfo { - private UUID id; - public static final String _id = "id"; - - private String value; - public static final String _value = "value"; - - private ContactInfoType type; - public static final String _type = "type"; - - private int ordinal; - public static final String _ordinal = "ordinal"; - - private User user; - public static final String _user = "user"; - - private Instant createdAt; - - public static final String _createdAt = "createdAt"; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public ContactInfoType getType() { - return type; - } - - public void setType(ContactInfoType type) { - this.type = type; - } - - public int getOrdinal() { - return ordinal; - } - - public void setOrdinal(int ordinal) { - this.ordinal = ordinal; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserContactInfoDeleter.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserContactInfoDeleter.java deleted file mode 100644 index 54a4224b7..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserContactInfoDeleter.java +++ /dev/null @@ -1,68 +0,0 @@ -package gr.cite.annotation.model.deleter; - -import gr.cite.annotation.data.TenantEntityManager; -import gr.cite.annotation.data.UserContactInfoEntity; -import gr.cite.annotation.query.UserContactInfoQuery; -import gr.cite.tools.data.deleter.Deleter; -import gr.cite.tools.data.query.QueryFactory; -import gr.cite.tools.logging.LoggerService; -import gr.cite.tools.logging.MapLogEntry; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import javax.management.InvalidApplicationException; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class UserContactInfoDeleter implements Deleter { - - private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoDeleter.class)); - private final TenantEntityManager entityManager; - - protected final QueryFactory queryFactory; - - - @Autowired - public UserContactInfoDeleter( - TenantEntityManager entityManager, - QueryFactory queryFactory - ) { - this.entityManager = entityManager; - this.queryFactory = queryFactory; - } - - public void deleteAndSaveByIds(List ids) throws InvalidApplicationException { - logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids)); - List data = this.queryFactory.query(UserContactInfoQuery.class).ids(ids).collect(); - logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0)); - this.deleteAndSave(data); - } - - public void deleteAndSave(List data) throws InvalidApplicationException { - logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); - this.delete(data); - logger.trace("saving changes"); - this.entityManager.flush(); - logger.trace("changes saved"); - } - - public void delete(List data) throws InvalidApplicationException { - logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0)); - if (data == null || data.isEmpty()) - return; - - for (UserContactInfoEntity item : data) { - logger.trace("deleting item {}", item.getId()); - logger.trace("deleting item"); - this.entityManager.remove(item); - logger.trace("deleted item"); - } - } - -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserDeleter.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserDeleter.java index 2045bfea1..046a62cab 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserDeleter.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/model/deleter/UserDeleter.java @@ -3,7 +3,6 @@ package gr.cite.annotation.model.deleter; import gr.cite.annotation.common.enums.IsActive; import gr.cite.annotation.data.*; import gr.cite.annotation.query.TenantUserQuery; -import gr.cite.annotation.query.UserContactInfoQuery; import gr.cite.annotation.query.UserCredentialQuery; import gr.cite.annotation.query.UserQuery; import gr.cite.tools.data.deleter.Deleter; @@ -76,12 +75,6 @@ public class UserDeleter implements Deleter { deleter.delete(items); } - { - logger.debug("checking related - {}", UserContactInfoEntity.class.getSimpleName()); - List items = this.queryFactory.query(UserContactInfoQuery.class).userIds(ids).collect(); - UserContactInfoDeleter deleter = this.deleterFactory.deleter(UserContactInfoDeleter.class); - deleter.delete(items); - } { logger.debug("checking related - {}", TenantUserEntity.class.getSimpleName()); List items = this.queryFactory.query(TenantUserQuery.class).userIds(ids).collect(); diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserContactInfoQuery.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserContactInfoQuery.java deleted file mode 100644 index f67e40507..000000000 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/query/UserContactInfoQuery.java +++ /dev/null @@ -1,236 +0,0 @@ -package gr.cite.annotation.query; - -import gr.cite.annotation.authorization.AuthorizationFlags; -import gr.cite.annotation.authorization.Permission; -import gr.cite.annotation.common.enums.ContactInfoType; -import gr.cite.annotation.common.scope.user.UserScope; -import gr.cite.annotation.data.UserContactInfoEntity; -import gr.cite.annotation.model.UserContactInfo; -import gr.cite.commons.web.authz.service.AuthorizationService; -import gr.cite.tools.data.query.FieldResolver; -import gr.cite.tools.data.query.QueryBase; -import gr.cite.tools.data.query.QueryContext; -import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.Predicate; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; - -import java.time.Instant; -import java.util.*; - -@Component -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class UserContactInfoQuery extends QueryBase { - private Collection ids; - private Collection excludedIds; - private Collection excludedUserIds; - private Collection userIds; - private Collection values; - private Collection types; - - private EnumSet authorize = EnumSet.of(AuthorizationFlags.None); - - private final UserScope userScope; - private final AuthorizationService authService; - public UserContactInfoQuery(UserScope userScope, AuthorizationService authService) { - this.userScope = userScope; - this.authService = authService; - } - - public UserContactInfoQuery ids(UUID value) { - this.ids = List.of(value); - return this; - } - - public UserContactInfoQuery ids(UUID... value) { - this.ids = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery ids(Collection values) { - this.ids = values; - return this; - } - - public UserContactInfoQuery excludedIds(Collection values) { - this.excludedIds = values; - return this; - } - - public UserContactInfoQuery excludedIds(UUID value) { - this.excludedIds = List.of(value); - return this; - } - - public UserContactInfoQuery excludedIds(UUID... value) { - this.excludedIds = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery excludedUserIds(Collection values) { - this.excludedUserIds = values; - return this; - } - - public UserContactInfoQuery excludedUserIds(UUID value) { - this.excludedUserIds = List.of(value); - return this; - } - - public UserContactInfoQuery excludedUserIds(UUID... value) { - this.excludedUserIds = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery userIds(UUID value) { - this.userIds = List.of(value); - return this; - } - - public UserContactInfoQuery userIds(UUID... value) { - this.userIds = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery userIds(Collection values) { - this.userIds = values; - return this; - } - - public UserContactInfoQuery values(String value) { - this.values = List.of(value); - return this; - } - - public UserContactInfoQuery values(String... value) { - this.values = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery values(Collection values) { - this.values = values; - return this; - } - - public UserContactInfoQuery types(ContactInfoType value) { - this.types = List.of(value); - return this; - } - - public UserContactInfoQuery types(ContactInfoType... value) { - this.types = Arrays.asList(value); - return this; - } - - public UserContactInfoQuery types(Collection values) { - this.types = values; - return this; - } - - public UserContactInfoQuery authorize(EnumSet values) { - this.authorize = values; - return this; - } - @Override - protected Boolean isFalseQuery() { - return - this.isEmpty(this.ids) || - this.isEmpty(this.userIds) || - this.isEmpty(this.excludedIds) || - this.isEmpty(this.values) || - this.isEmpty(this.excludedIds); - } - - @Override - protected Class entityClass() { - return UserContactInfoEntity.class; - } - - @Override - protected Predicate applyAuthZ(QueryContext queryContext) { - if (this.authorize.contains(AuthorizationFlags.None)) return null; - if (this.authorize.contains(AuthorizationFlags.Permission) && this.authService.authorize(Permission.BrowseUser)) return null; - UUID userId; - if (this.authorize.contains(AuthorizationFlags.Owner)) userId = this.userScope.getUserIdSafe(); - else userId = null; - - List predicates = new ArrayList<>(); - if (userId != null) { - predicates.add(queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)).value(userId)); - } - if (!predicates.isEmpty()) { - Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); - return queryContext.CriteriaBuilder.and(predicatesArray); - } else { - return queryContext.CriteriaBuilder.or(); //Creates a false query - } - } - - @Override - protected Predicate applyFilters(QueryContext queryContext) { - List predicates = new ArrayList<>(); - if (this.ids != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._id)); - for (UUID item : this.ids) - inClause.value(item); - predicates.add(inClause); - } - if (this.userIds != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)); - for (UUID item : this.userIds) - inClause.value(item); - predicates.add(inClause); - } - if (this.excludedIds != null) { - CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._id)); - for (UUID item : this.excludedIds) - notInClause.value(item); - predicates.add(notInClause.not()); - } - if (this.excludedUserIds != null) { - CriteriaBuilder.In notInClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._userId)); - for (UUID item : this.excludedUserIds) - notInClause.value(item); - predicates.add(notInClause.not()); - } - if (this.values != null) { - CriteriaBuilder.In inClause = queryContext.CriteriaBuilder.in(queryContext.Root.get(UserContactInfoEntity._value)); - for (String item : this.values) - inClause.value(item); - predicates.add(inClause); - } - if (!predicates.isEmpty()) { - Predicate[] predicatesArray = predicates.toArray(new Predicate[0]); - return queryContext.CriteriaBuilder.and(predicatesArray); - } else { - return null; - } - } - - @Override - protected String fieldNameOf(FieldResolver item) { - if (item.match(UserContactInfo._id)) return UserContactInfoEntity._id; - else if (item.match(UserContactInfo._value)) return UserContactInfoEntity._value; - else if (item.match(UserContactInfo._ordinal)) return UserContactInfoEntity._ordinal; - else if (item.prefix(UserContactInfo._user)) return UserContactInfoEntity._userId; - else if (item.match(UserContactInfo._user)) return UserContactInfoEntity._userId; - else if (item.match(UserContactInfo._type)) return UserContactInfoEntity._type; - else if (item.match(UserContactInfo._createdAt) ) return UserContactInfoEntity._createdAt; - else return null; - } - - @Override - protected UserContactInfoEntity convert(Tuple tuple, Set columns) { - UserContactInfoEntity item = new UserContactInfoEntity(); - item.setId(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._id, UUID.class)); - item.setValue(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._value, String.class)); - item.setType(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._type, ContactInfoType.class)); - item.setOrdinal(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._ordinal, Integer.class)); - item.setUserId(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._userId, UUID.class)); - item.setCreatedAt(QueryBase.convertSafe(tuple, columns, UserContactInfoEntity._createdAt, Instant.class)); - return item; - } - -} diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java index b6bdb0a61..880d0b479 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/service/user/UserServiceImpl.java @@ -9,17 +9,14 @@ import gr.cite.annotation.common.scope.tenant.TenantScope; import gr.cite.annotation.convention.ConventionService; import gr.cite.annotation.data.*; import gr.cite.annotation.integrationevent.inbox.usertouch.UserTouchedIntegrationEvent; -import gr.cite.annotation.model.Annotation; import gr.cite.annotation.model.Tenant; import gr.cite.annotation.model.User; import gr.cite.annotation.model.builder.UserBuilder; import gr.cite.annotation.model.deleter.TenantUserDeleter; -import gr.cite.annotation.model.deleter.UserContactInfoDeleter; import gr.cite.annotation.model.deleter.UserCredentialDeleter; import gr.cite.annotation.model.deleter.UserDeleter; import gr.cite.annotation.query.TenantQuery; import gr.cite.annotation.query.TenantUserQuery; -import gr.cite.annotation.query.UserContactInfoQuery; import gr.cite.annotation.query.UserCredentialQuery; import gr.cite.commons.web.authz.service.AuthorizationService; import gr.cite.tools.data.builder.BuilderFactory; @@ -125,7 +122,6 @@ public class UserServiceImpl implements UserService { this.entityManager.flush(); - this.persistContactInfo(model.getUserContactInfo(), data.getId()); this.persistUserCredential(model.getCredentials(), data.getId()); this.persistTenantUser(model.getTenantUsers(), data.getId()); @@ -143,38 +139,6 @@ public class UserServiceImpl implements UserService { this.deleterFactory.deleter(UserDeleter.class).deleteAndSaveByIds(List.of(id)); } - private void persistContactInfo(List models, UUID userId) throws InvalidApplicationException { - List items = this.queryFactory.query(UserContactInfoQuery.class) - .userIds(userId) - .collect(); - List updatedCreatedIds = new ArrayList<>(); - if (models != null) { - for (UserTouchedIntegrationEvent.UserContactInfo model : models) { - UserContactInfoEntity data = items.stream().filter(x -> x.getType().equals(model.getType()) && x.getValue().equals(model.getValue())).findFirst().orElse(null); - if (data == null) { - data = new UserContactInfoEntity(); - data.setId(UUID.randomUUID()); - data.setUserId(userId); - data.setType(model.getType()); - data.setValue(model.getValue()); - data.setOrdinal(model.getOrdinal()); - data.setCreatedAt(Instant.now()); - data.setUpdatedAt(Instant.now()); - data.setIsActive(IsActive.Active); - entityManager.persist(data); - } else { - data.setOrdinal(model.getOrdinal()); - entityManager.merge(data); - } - updatedCreatedIds.add(data.getId()); - } - } - List toDelete = items.stream().filter(x -> updatedCreatedIds.stream().noneMatch(y -> y.equals(x.getId()))).collect(Collectors.toList()); - deleterFactory.deleter(UserContactInfoDeleter.class).delete(toDelete); - - entityManager.flush(); - } - private void persistUserCredential(List models, UUID userId) throws InvalidApplicationException { List items = this.queryFactory.query(UserCredentialQuery.class) .userIds(userId) diff --git a/dmp-backend/core/pom.xml b/dmp-backend/core/pom.xml index 0a398b2d1..3e06193d3 100644 --- a/dmp-backend/core/pom.xml +++ b/dmp-backend/core/pom.xml @@ -88,7 +88,7 @@ gr.cite keycloak-api - 2.2.0 + 2.3.0 diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakResourcesConfiguration.java b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakResourcesConfiguration.java index 202930f43..cb9568fbf 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakResourcesConfiguration.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakResourcesConfiguration.java @@ -24,8 +24,8 @@ public class KeycloakResourcesConfiguration { .replace("{tenantCode}", tenantCode); } - public String getTenantRoleAttributeValue(String tenantCode, String key) { - return properties.getTenantAuthorities().get(key).getRoleAttributeValueStrategy() + public String getTenantRoleAttributeValue(String tenantCode, KeycloakTenantAuthorityProperties properties) { + return properties.getRoleAttributeValueStrategy() .replace("{tenantCode}", tenantCode); } diff --git a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java index 09b4fc4e7..5e24777e4 100644 --- a/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java +++ b/dmp-backend/core/src/main/java/eu/eudat/service/keycloak/KeycloakServiceImpl.java @@ -1,5 +1,6 @@ package eu.eudat.service.keycloak; +import eu.eudat.convention.ConventionService; import gr.cite.commons.web.keycloak.api.configuration.KeycloakClientConfiguration; import gr.cite.tools.logging.LoggerService; import org.jetbrains.annotations.NotNull; @@ -16,13 +17,13 @@ public class KeycloakServiceImpl implements KeycloakService { private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(KeycloakServiceImpl.class)); private final MyKeycloakAdminRestApi api; private final KeycloakResourcesConfiguration configuration; - private final KeycloakClientConfiguration clientConfiguration; + private final ConventionService conventionService; @Autowired - public KeycloakServiceImpl(MyKeycloakAdminRestApi api, KeycloakResourcesConfiguration configuration, KeycloakClientConfiguration clientConfiguration) { + public KeycloakServiceImpl(MyKeycloakAdminRestApi api, KeycloakResourcesConfiguration configuration, ConventionService conventionService) { this.api = api; this.configuration = configuration; - this.clientConfiguration = clientConfiguration; + this.conventionService = conventionService; } @Override @@ -37,72 +38,50 @@ public class KeycloakServiceImpl implements KeycloakService { @Override public void addUserToGlobalRoleGroup(String subjectId, String role) { - KeycloakAuthorityProperties properties = this.configuration.getProperties().getAuthorities().get(role); + if (this.configuration.getProperties().getAuthorities() == null) return; + KeycloakAuthorityProperties properties = this.configuration.getProperties().getAuthorities().getOrDefault(role, null); if (properties != null) addUserToGroup(subjectId, properties.getGroupId()); } @Override public void removeUserGlobalRoleGroup(@NotNull String subjectId, String role) { - KeycloakAuthorityProperties properties = this.configuration.getProperties().getAuthorities().get(role); - if (properties != null) - removeUserFromGroup(subjectId, properties.getGroupId()); + if (this.configuration.getProperties().getAuthorities() == null) return; + KeycloakAuthorityProperties properties = this.configuration.getProperties().getAuthorities().getOrDefault(role, null); + if (properties != null) removeUserFromGroup(subjectId, properties.getGroupId()); } -// -// @Override -// public void assignClientRoleToUser(UUID subjectId, String clientId, KeycloakRole role) { -// if (clientId == null) -// clientId = clientConfiguration.getProperties().getClientId(); -// UserRepresentation user = api.users().findUserById(subjectId.toString()); -// user.getClientRoles().computeIfAbsent(clientId, k -> new ArrayList<>()); -// Set clientRoles = new HashSet<>(Set.copyOf(user.getClientRoles().get(clientId))); -// clientRoles.add(role.name()); -// user.getClientRoles().get(clientId).clear(); -// user.getClientRoles().get(clientId).addAll(clientRoles); -// api.users().updateUser(subjectId.toString(), user); -// } -// -// @Override -// public void removeClientRoleFromUser(UUID subjectId, String clientId, KeycloakRole role) { -// if (clientId == null) clientId = clientConfiguration.getProperties().getClientId(); -// UserRepresentation user = api.users().findUserById(subjectId.toString()); -// user.getClientRoles().computeIfAbsent(clientId, k -> new ArrayList<>()); -// Set clientRoles = new HashSet<>(Set.copyOf(user.getClientRoles().get(clientId))); -// clientRoles.remove(role.name()); -// user.getClientRoles().get(clientId).clear(); -// user.getClientRoles().get(clientId).addAll(clientRoles); -// api.users().updateUser(subjectId.toString(), user); -// } -// -// public List getUserGroups(UUID subjectId) { -// return api.users().getGroups(subjectId.toString()); -// } @Override public void addUserToTenantRoleGroup(String subjectId, String tenantCode, String tenantRole) { - GroupRepresentation group = api.groups().findGroupByPath(getTenantAuthorityParentPath(tenantRole) + "/" + configuration.getTenantGroupName(tenantCode)); - addUserToGroup(subjectId, group.getId()); + if (this.configuration.getProperties().getAuthorities() == null) return; + KeycloakTenantAuthorityProperties properties = this.configuration.getProperties().getTenantAuthorities().getOrDefault(tenantRole, null); + if (properties == null) return; + GroupRepresentation group = api.groups().findGroupByPath(getTenantAuthorityParentPath(properties) + "/" + configuration.getTenantGroupName(tenantCode)); + if (group != null) addUserToGroup(subjectId, group.getId()); } @Override public void removeUserTenantRoleGroup(String subjectId, String tenantCode, String tenantRole) { - GroupRepresentation group = api.groups().findGroupByPath(getTenantAuthorityParentPath(tenantRole) + "/" + configuration.getTenantGroupName(tenantCode)); - removeUserFromGroup(subjectId, group.getId()); + KeycloakTenantAuthorityProperties properties = this.configuration.getProperties().getTenantAuthorities().getOrDefault(tenantRole, null); + if (properties == null) return; + GroupRepresentation group = api.groups().findGroupByPath(getTenantAuthorityParentPath(properties) + "/" + configuration.getTenantGroupName(tenantCode)); + if (group != null) removeUserFromGroup(subjectId, group.getId()); } - private String getTenantAuthorityParentPath(String tenantRole) { - GroupRepresentation parent = api.groups().findGroupById(configuration.getProperties().getTenantAuthorities().get(tenantRole).getParent()); + private String getTenantAuthorityParentPath(KeycloakTenantAuthorityProperties keycloakTenantAuthorityProperties) { + GroupRepresentation parent = api.groups().findGroupById(keycloakTenantAuthorityProperties.getParent()); return parent.getPath(); } @Override public void createTenantGroups(String tenantCode) { + if (this.configuration.getProperties().getTenantAuthorities() == null) return; for (Map.Entry entry :configuration.getProperties().getTenantAuthorities().entrySet()){ GroupRepresentation group = new GroupRepresentation(); group.setName(configuration.getTenantGroupName(tenantCode)); HashMap> user_attributes = new HashMap<>(); - user_attributes.put(this.configuration.getProperties().getTenantRoleAttributeName(), List.of(configuration.getTenantRoleAttributeValue(tenantCode, entry.getKey()))); + if (!this.conventionService.isNullOrEmpty(this.configuration.getProperties().getTenantRoleAttributeName())) user_attributes.put(this.configuration.getProperties().getTenantRoleAttributeName(), List.of(configuration.getTenantRoleAttributeValue(tenantCode, entry.getValue()))); group.setAttributes(user_attributes); - api.groups().addGroupWithParent(group, configuration.getProperties().getTenantAuthorities().get(entry.getKey()).getParent()); + api.groups().addGroupWithParent(group, entry.getValue().getParent()); } } } diff --git a/dmp-backend/pom.xml b/dmp-backend/pom.xml index 8c21353a4..2acb6d109 100644 --- a/dmp-backend/pom.xml +++ b/dmp-backend/pom.xml @@ -242,7 +242,7 @@ gr.cite keycloak-api - 2.2.0 + 2.3.0 From 3c9844abb63867e38a72209e3c9df4cf533dee1c Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 16 Apr 2024 14:21:52 +0300 Subject: [PATCH 2/5] fix script --- dmp-db-scema/updates/00.01.056_Add_ant_EntityUser_table.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dmp-db-scema/updates/00.01.056_Add_ant_EntityUser_table.sql b/dmp-db-scema/updates/00.01.056_Add_ant_EntityUser_table.sql index 4845b1b2c..9e64fefe3 100644 --- a/dmp-db-scema/updates/00.01.056_Add_ant_EntityUser_table.sql +++ b/dmp-db-scema/updates/00.01.056_Add_ant_EntityUser_table.sql @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS public."ant_EntityUser" "id" uuid NOT NULL, "entity_id" uuid NOT NULL, "user_id" uuid NOT NULL, - "tenant" uuid NOT NULL, + "tenant" uuid NULL, "created_at" timestamp without time zone NOT NULL, "updated_at" timestamp without time zone NOT NULL, "is_active" smallint NOT NULL, From af52c4aa8d1d8cccf5adce03b09054cd1d5e1d75 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Tue, 16 Apr 2024 15:25:10 +0300 Subject: [PATCH 3/5] ui and guided tour fixes --- .../app/ui/dashboard/dashboard.component.html | 12 ++++++---- .../app/ui/dashboard/dashboard.component.ts | 2 +- .../start-new-dmp-dialog.component.html | 24 +++++++++++-------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/dmp-frontend/src/app/ui/dashboard/dashboard.component.html b/dmp-frontend/src/app/ui/dashboard/dashboard.component.html index 50d088c26..b2900a9e7 100644 --- a/dmp-frontend/src/app/ui/dashboard/dashboard.component.html +++ b/dmp-frontend/src/app/ui/dashboard/dashboard.component.html @@ -39,11 +39,15 @@

-
- +
+
+ +
-
- +
+
+ +
diff --git a/dmp-frontend/src/app/ui/dashboard/dashboard.component.ts b/dmp-frontend/src/app/ui/dashboard/dashboard.component.ts index 3ba3583b3..2a360b5ec 100644 --- a/dmp-frontend/src/app/ui/dashboard/dashboard.component.ts +++ b/dmp-frontend/src/app/ui/dashboard/dashboard.component.ts @@ -186,7 +186,7 @@ export class DashboardComponent extends BaseComponent implements OnInit { closeAction: () => this.dialog.closeAll() }, { - selector: '.new-description-tour', + selector: '.new-dataset-tour', content: 'Step 4', orientation: Orientation.BottomLeft, isStepUnique: false, diff --git a/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html b/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html index bc05a9175..5aa490554 100644 --- a/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html +++ b/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html @@ -15,20 +15,24 @@
-
- +
+
+ +

{{ 'START-NEW-PLAN-DIALOG.OR' | translate }}

-
- +
+
+ +
From 0672a60494db9037f3cf1fa240e73a6a8c201eb9 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Tue, 16 Apr 2024 15:32:08 +0300 Subject: [PATCH 4/5] ui fix --- .../start-new-dmp-dialog.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html b/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html index 5aa490554..b849f4509 100644 --- a/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html +++ b/dmp-frontend/src/app/ui/dmp/new/start-new-dmp-dialogue/start-new-dmp-dialog.component.html @@ -17,13 +17,13 @@
-
-
+

{{ 'START-NEW-PLAN-DIALOG.OR' | translate }}

From 05980676088f0a3015944b1127abb937e39e2b2f Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Tue, 16 Apr 2024 15:35:44 +0300 Subject: [PATCH 5/5] tenant scope fix --- .../common/scope/tenant/TenantScope.java | 22 +++++++++++++++---- .../common/scope/tenant/TenantScope.java | 22 +++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java index 3c0ac7095..e42eaebcf 100644 --- a/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java +++ b/annotation-service/annotation/src/main/java/gr/cite/annotation/common/scope/tenant/TenantScope.java @@ -11,8 +11,6 @@ import javax.management.InvalidApplicationException; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; -@Component -@RequestScope public class TenantScope { public static final String TenantReplaceParameter = "::TenantCode::"; private final MultitenancyProperties multitenancy; @@ -66,7 +64,14 @@ public class TenantScope { this.tenant.set(tenant); this.tenantCode.set(tenantCode); - if (this.tenant.get() != null && !this.isDefaultTenant()) { + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.tenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) @@ -83,7 +88,16 @@ public class TenantScope { public void removeTempTenant(EntityManager entityManager) { this.tenant.set(this.initialTenant.get()); this.tenantCode.set(this.initialTenantCode.get()); - if (this.initialTenant.get() != null && !this.isDefaultTenant()) { + + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.initialTenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) diff --git a/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java b/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java index 473fa321a..0a27d4cc6 100644 --- a/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java +++ b/notification-service/notification/src/main/java/gr/cite/notification/common/scope/tenant/TenantScope.java @@ -11,8 +11,6 @@ import javax.management.InvalidApplicationException; import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; -@Component -@RequestScope public class TenantScope { public static final String TenantReplaceParameter = "::TenantCode::"; private final MultitenancyProperties multitenancy; @@ -66,7 +64,14 @@ public class TenantScope { this.tenant.set(tenant); this.tenantCode.set(tenantCode); - if (this.tenant.get() != null && !this.isDefaultTenant()) { + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.tenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class) @@ -83,7 +88,16 @@ public class TenantScope { public void removeTempTenant(EntityManager entityManager) { this.tenant.set(this.initialTenant.get()); this.tenantCode.set(this.initialTenantCode.get()); - if (this.initialTenant.get() != null && !this.isDefaultTenant()) { + + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.TENANT_FILTER); + + entityManager + .unwrap(Session.class) + .disableFilter(TenantScopedBaseEntity.DEFAULT_TENANT_FILTER); + if (this.initialTenant.get() != null || this.isDefaultTenant()) { if(!this.isDefaultTenant()) { entityManager .unwrap(Session.class)