You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2023/09/29 10:26:17 UTC

[causeway] branch spring6 updated (8df61b11a0 -> d3ed079f9e)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a change to branch spring6
in repository https://gitbox.apache.org/repos/asf/causeway.git


    from 8df61b11a0 Merge remote-tracking branch 'origin/master' into spring6
     add 2dd5898cc8 CAUSEWAY-3618 : refactored to preserve any original roles in the UserMemento
     add fd81e68e95 CAUSEWAY-3618 : refactored to preserve any original roles in the UserMemento - reorg imports
     new d3ed079f9e Merge remote-tracking branch 'origin/master' into spring6

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../UserMementoRefinerFromApplicationUser.java     | 48 ++++++++--------------
 1 file changed, 18 insertions(+), 30 deletions(-)


[causeway] 01/01: Merge remote-tracking branch 'origin/master' into spring6

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch spring6
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit d3ed079f9e12e1aaf613202aee1539c21f96dee0
Merge: 8df61b11a0 fd81e68e95
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Sep 29 12:26:13 2023 +0200

    Merge remote-tracking branch 'origin/master' into spring6

 .../UserMementoRefinerFromApplicationUser.java     | 48 ++++++++--------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --cc extensions/security/secman/integration/src/main/java/org/apache/causeway/extensions/secman/integration/usermementorefiner/UserMementoRefinerFromApplicationUser.java
index d7d5c90101,cb78b3b76c..bc80dd2d4e
--- a/extensions/security/secman/integration/src/main/java/org/apache/causeway/extensions/secman/integration/usermementorefiner/UserMementoRefinerFromApplicationUser.java
+++ b/extensions/security/secman/integration/src/main/java/org/apache/causeway/extensions/secman/integration/usermementorefiner/UserMementoRefinerFromApplicationUser.java
@@@ -18,11 -18,8 +18,8 @@@
   */
  package org.apache.causeway.extensions.secman.integration.usermementorefiner;
  
- import java.util.Set;
- import java.util.stream.Collectors;
- 
 -import javax.inject.Inject;
 -import javax.inject.Provider;
 +import jakarta.inject.Inject;
 +import jakarta.inject.Provider;
  
  import org.springframework.stereotype.Service;
  
@@@ -44,29 -39,22 +39,22 @@@ public class UserMementoRefinerFromAppl
  
      @Override
      public UserMemento refine(final UserMemento userMemento) {
-         return applicationUserRepositoryProvider.get().findByUsername(userMemento.getName())
-                 .map(applicationUser ->
-                     userMemento.asBuilder()
-                     .multiTenancyToken(applicationUser.getAtPath())
-                     .languageLocale(applicationUser.getLanguage())
-                     .numberFormatLocale(applicationUser.getNumberFormat())
-                     .timeFormatLocale(applicationUser.getTimeFormat())
-                     .roles(convert(applicationUser.getRoles()))
-                     .build()
-                 )
-                 .orElse(userMemento);
-     }
- 
-     private static Can<RoleMemento> convert(Set<ApplicationRole> roles) {
-         return Can.ofCollection(roles.stream()
-                 .map(UserMementoRefinerFromApplicationUser::convert)
-                 .collect(Collectors.toList()));
-     }
- 
-     private static RoleMemento convert(ApplicationRole applicationRole) {
-         return RoleMemento.builder()
-                 .name(applicationRole.getName())
-                 .description(applicationRole.getDescription())
-                 .build();
+         val applicationUserIfAny = applicationUserRepositoryProvider.get().findByUsername(userMemento.getName());
+         if (applicationUserIfAny.isEmpty()) {
+             return userMemento;
+         }
+         val applicationUser = applicationUserIfAny.get();
+ 
+         UserMemento refinedUserMemento =
+                 userMemento.withMultiTenancyToken(applicationUser.getAtPath())
+                            .withLanguageLocale(applicationUser.getLanguage())
+                            .withNumberFormatLocale(applicationUser.getNumberFormat())
+                            .withTimeFormatLocale(applicationUser.getTimeFormat());
+ 
+         for (val role : applicationUser.getRoles()) {
+             refinedUserMemento = refinedUserMemento.withRoleAdded(role.getName());
+         }
+ 
+         return refinedUserMemento;
      }
 -}
 +}