diff --git a/src/main/java/fi/vm/yti/security/YtiUser.java b/src/main/java/fi/vm/yti/security/YtiUser.java index 7e6a7cc..5496fd9 100644 --- a/src/main/java/fi/vm/yti/security/YtiUser.java +++ b/src/main/java/fi/vm/yti/security/YtiUser.java @@ -30,7 +30,7 @@ public final class YtiUser implements UserDetails { private final String email; private final String firstName; private final String lastName; - private final UUID id; + private final String id; private final boolean superuser; private final boolean newlyCreated; private final Map> rolesInOrganizations; @@ -43,7 +43,7 @@ public final class YtiUser implements UserDetails { public YtiUser(final String email, final String firstName, final String lastName, - final UUID id, + final String id, final boolean superuser, final boolean newlyCreated, final LocalDateTime tokenCreatedAt, @@ -58,7 +58,7 @@ private YtiUser(final boolean anonymous, final String email, final String firstName, final String lastName, - final UUID id, + final String id, final boolean superuser, final boolean newlyCreated, final LocalDateTime tokenCreatedAt, @@ -118,7 +118,7 @@ public String getLastName() { return lastName; } - public UUID getId() { + public String getId() { return id; } diff --git a/src/main/java/fi/vm/yti/security/config/TokenUserLogin.java b/src/main/java/fi/vm/yti/security/config/TokenUserLogin.java index 59b7133..5f3e895 100644 --- a/src/main/java/fi/vm/yti/security/config/TokenUserLogin.java +++ b/src/main/java/fi/vm/yti/security/config/TokenUserLogin.java @@ -6,7 +6,7 @@ public final class TokenUserLogin { - private final UUID id; + private final String id; private final String email; private final String firstName; private final String lastName; @@ -18,7 +18,7 @@ public TokenUserLogin(final YtiUser ytiUser) { this.lastName = ytiUser.getLastName(); } - UUID getId() { + String getId() { return id; } diff --git a/src/main/java/fi/vm/yti/security/config/YtiAuthenticationUserDetailsService.java b/src/main/java/fi/vm/yti/security/config/YtiAuthenticationUserDetailsService.java index 8d6e614..bc809cf 100644 --- a/src/main/java/fi/vm/yti/security/config/YtiAuthenticationUserDetailsService.java +++ b/src/main/java/fi/vm/yti/security/config/YtiAuthenticationUserDetailsService.java @@ -23,7 +23,6 @@ import fi.vm.yti.security.YtiUser; import fi.vm.yti.security.util.RoleUtil; import static fi.vm.yti.security.config.RestTemplateConfig.httpClient; -import static org.springframework.util.StringUtils.isEmpty; public class YtiAuthenticationUserDetailsService implements AuthenticationUserDetailsService { @@ -45,13 +44,13 @@ public UserDetails loadUserDetails(final PreAuthenticatedAuthenticationToken tok .path("/private-api/user"); newUser.email = shibbolethDetails.getEmail(); - if (!isEmpty(shibbolethDetails.getFirstName()) && !isEmpty(shibbolethDetails.getLastName())) { + if (hasValue(shibbolethDetails.getFirstName()) && hasValue(shibbolethDetails.getLastName())) { newUser.firstName = shibbolethDetails.getFirstName(); newUser.lastName = shibbolethDetails.getLastName(); } - if (!isEmpty(shibbolethDetails.getId())) { - newUser.id = UUID.fromString(shibbolethDetails.getId()); + if (hasValue(shibbolethDetails.getId())) { + newUser.id = shibbolethDetails.getId(); } final String getUserUri = uriBuilder.build().toUriString(); @@ -60,21 +59,29 @@ public UserDetails loadUserDetails(final PreAuthenticatedAuthenticationToken tok final User user = response.getBody(); final Map> rolesInOrganizations = new HashMap<>(); - for (final Organization organization : user.organization) { - final Set roles = organization.role.stream() - .filter(RoleUtil::isRoleMappableToEnum) - .map(Role::valueOf) - .collect(Collectors.toSet()); - rolesInOrganizations.put(organization.uuid, roles); + if (user != null) { + for (final Organization organization : user.organization) { + final Set roles = organization.role.stream() + .filter(RoleUtil::isRoleMappableToEnum) + .map(Role::valueOf) + .collect(Collectors.toSet()); + rolesInOrganizations.put(organization.uuid, roles); + } + return new YtiUser(user.email, user.firstName, user.lastName, user.id, + user.superuser, user.newlyCreated, user.tokenCreatedAt, + user.tokenInvalidationAt, rolesInOrganizations, user.containerUri, user.tokenRole); } + return YtiUser.ANONYMOUS_USER; + } - return new YtiUser(user.email, user.firstName, user.lastName, user.id, user.superuser, user.newlyCreated, user.tokenCreatedAt, user.tokenInvalidationAt, rolesInOrganizations, user.containerUri, user.tokenRole); + private boolean hasValue(String value) { + return value != null && !value.isEmpty(); } } class NewUser { - public UUID id; + public String id; public String email; public String firstName; public String lastName; @@ -88,7 +95,7 @@ class User { public boolean superuser; public boolean newlyCreated; public List organization; - public UUID id; + public String id; public LocalDateTime removalDateTime; public LocalDateTime tokenCreatedAt; public LocalDateTime tokenInvalidationAt;