diff --git a/server-spi-private/src/main/java/org/keycloak/userprofile/UserProfile.java b/server-spi-private/src/main/java/org/keycloak/userprofile/UserProfile.java index 1328cbfb93..125a96366f 100644 --- a/server-spi-private/src/main/java/org/keycloak/userprofile/UserProfile.java +++ b/server-spi-private/src/main/java/org/keycloak/userprofile/UserProfile.java @@ -32,8 +32,14 @@ public interface UserProfile { Map> getAttributes(); - String getFirstAttribute(String name); + String getFirstAttribute(String key); List getAttribute(String key); + void setSingleAttribute(String key, String value); + + void setAttribute(String key, List value); + + void removeAttribute(String attr); + } diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpReviewProfileAuthenticator.java b/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpReviewProfileAuthenticator.java index 81d29e2ff3..546de76344 100755 --- a/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpReviewProfileAuthenticator.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpReviewProfileAuthenticator.java @@ -37,9 +37,9 @@ import org.keycloak.services.resources.AttributeFormDataProcessor; import org.keycloak.services.validation.Validation; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfileProvider; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.IdpUserProfile; +import org.keycloak.userprofile.profile.representations.IdpUserProfile; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; diff --git a/services/src/main/java/org/keycloak/authentication/forms/RegistrationProfile.java b/services/src/main/java/org/keycloak/authentication/forms/RegistrationProfile.java index ea94e709b4..e4626ad9b6 100755 --- a/services/src/main/java/org/keycloak/authentication/forms/RegistrationProfile.java +++ b/services/src/main/java/org/keycloak/authentication/forms/RegistrationProfile.java @@ -37,10 +37,10 @@ import org.keycloak.services.validation.Validation; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfileProvider; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.UserModelUserProfile; +import org.keycloak.userprofile.profile.representations.UserModelUserProfile; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; diff --git a/services/src/main/java/org/keycloak/authentication/forms/RegistrationUserCreation.java b/services/src/main/java/org/keycloak/authentication/forms/RegistrationUserCreation.java index 603718d591..d7bf934351 100755 --- a/services/src/main/java/org/keycloak/authentication/forms/RegistrationUserCreation.java +++ b/services/src/main/java/org/keycloak/authentication/forms/RegistrationUserCreation.java @@ -40,10 +40,10 @@ import org.keycloak.services.validation.Validation; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfileProvider; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.UserModelUserProfile; +import org.keycloak.userprofile.profile.representations.UserModelUserProfile; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; diff --git a/services/src/main/java/org/keycloak/authentication/requiredactions/UpdateProfile.java b/services/src/main/java/org/keycloak/authentication/requiredactions/UpdateProfile.java index 4fb5b8db46..55a54279df 100644 --- a/services/src/main/java/org/keycloak/authentication/requiredactions/UpdateProfile.java +++ b/services/src/main/java/org/keycloak/authentication/requiredactions/UpdateProfile.java @@ -35,10 +35,10 @@ import org.keycloak.services.resources.AttributeFormDataProcessor; import org.keycloak.services.validation.Validation; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfileProvider; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.UserModelUserProfile; +import org.keycloak.userprofile.profile.representations.UserModelUserProfile; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; diff --git a/services/src/main/java/org/keycloak/services/resources/AttributeFormDataProcessor.java b/services/src/main/java/org/keycloak/services/resources/AttributeFormDataProcessor.java index ee733e2b87..15bfaafc63 100755 --- a/services/src/main/java/org/keycloak/services/resources/AttributeFormDataProcessor.java +++ b/services/src/main/java/org/keycloak/services/resources/AttributeFormDataProcessor.java @@ -19,7 +19,7 @@ package org.keycloak.services.resources; import org.keycloak.models.Constants; import org.keycloak.models.UserModel; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import javax.ws.rs.core.MultivaluedMap; import java.util.ArrayList; diff --git a/services/src/main/java/org/keycloak/services/resources/account/AccountFormService.java b/services/src/main/java/org/keycloak/services/resources/account/AccountFormService.java index ece7cc0500..5c3578a582 100755 --- a/services/src/main/java/org/keycloak/services/resources/account/AccountFormService.java +++ b/services/src/main/java/org/keycloak/services/resources/account/AccountFormService.java @@ -75,10 +75,10 @@ import org.keycloak.sessions.AuthenticationSessionModel; import org.keycloak.storage.ReadOnlyException; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfileProvider; -import org.keycloak.userprofile.profile.represenations.AttributeUserProfile; +import org.keycloak.userprofile.profile.representations.AttributeUserProfile; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.UserModelUserProfile; +import org.keycloak.userprofile.profile.representations.UserModelUserProfile; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.util.JsonSerialization; diff --git a/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java b/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java index 9cea7bb649..ceef3b8495 100755 --- a/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java +++ b/services/src/main/java/org/keycloak/services/resources/account/AccountRestService.java @@ -22,7 +22,6 @@ import org.keycloak.common.ClientConnection; import org.keycloak.common.enums.AccountRestApiVersion; import org.keycloak.common.Profile; import org.keycloak.common.util.StringPropertyReplacer; -import org.keycloak.credential.CredentialModel; import org.keycloak.events.EventBuilder; import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventType; @@ -51,13 +50,11 @@ import org.keycloak.theme.Theme; import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.UserProfileProvider; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; -import org.keycloak.userprofile.profile.represenations.AccountUserRepresentationUserProfile; +import org.keycloak.userprofile.profile.representations.AccountUserRepresentationUserProfile; import org.keycloak.userprofile.profile.DefaultUserProfileContext; -import org.keycloak.userprofile.profile.represenations.UserModelUserProfile; +import org.keycloak.userprofile.profile.representations.UserModelUserProfile; import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserUpdateEvent; -import org.keycloak.common.Profile; -import org.keycloak.theme.Theme; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java index 655ca3c2cf..864103ee65 100755 --- a/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UserResource.java @@ -72,7 +72,7 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluato import org.keycloak.services.validation.Validation; import org.keycloak.storage.ReadOnlyException; import org.keycloak.userprofile.utils.UserProfileUpdateHelper; -import org.keycloak.userprofile.profile.represenations.UserRepresentationUserProfile; +import org.keycloak.userprofile.profile.representations.UserRepresentationUserProfile; import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.utils.ProfileHelper; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/AbstractUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/AbstractUserProfile.java index 9edffd2a35..a4f95f53e3 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/AbstractUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/AbstractUserProfile.java @@ -18,7 +18,6 @@ package org.keycloak.userprofile.profile; import org.keycloak.userprofile.UserProfile; -import org.keycloak.userprofile.utils.StoredUserProfile; import java.util.Collections; import java.util.List; @@ -27,7 +26,7 @@ import java.util.Map; /** * @author Markus Till */ -public abstract class AbstractUserProfile implements UserProfile , StoredUserProfile { +public abstract class AbstractUserProfile implements UserProfile { /* @@ -53,7 +52,7 @@ public abstract class AbstractUserProfile implements UserProfile , StoredUserPro @Override public String getFirstAttribute(String key) { - return this.getAttributes() == null ? null : this.getAttributes().get(key) == null ? null : this.getAttributes().get(key).size() == 0 ? null : this.getAttributes().get(key).get(0); + return this.getAttributes() == null ? null : this.getAttributes().get(key) == null ? null : this.getAttributes().get(key).isEmpty()? null : this.getAttributes().get(key).get(0); } @Override diff --git a/services/src/main/java/org/keycloak/userprofile/profile/DefaultUserProfileContext.java b/services/src/main/java/org/keycloak/userprofile/profile/DefaultUserProfileContext.java index 5541a76603..7589cf2f6f 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/DefaultUserProfileContext.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/DefaultUserProfileContext.java @@ -17,7 +17,6 @@ package org.keycloak.userprofile.profile; -import org.keycloak.userprofile.utils.StoredUserProfile; import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfileContext; import org.keycloak.userprofile.validation.UserUpdateEvent; @@ -27,7 +26,7 @@ import org.keycloak.userprofile.validation.UserUpdateEvent; */ public class DefaultUserProfileContext implements UserProfileContext { private boolean isCreated; - private StoredUserProfile currentUserProfile; + private UserProfile currentUserProfile; private UserProfile updatedUserProfile; private UserUpdateEvent userUpdateEvent; @@ -38,7 +37,7 @@ public class DefaultUserProfileContext implements UserProfileContext { this.updatedUserProfile = updatedUserProfile; } - public DefaultUserProfileContext(UserUpdateEvent userUpdateEvent, StoredUserProfile currentUserProfile, UserProfile updatedUserProfile) { + public DefaultUserProfileContext(UserUpdateEvent userUpdateEvent, UserProfile currentUserProfile, UserProfile updatedUserProfile) { this.userUpdateEvent = userUpdateEvent; this.isCreated = true; this.currentUserProfile = currentUserProfile; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/represenations/AccountUserRepresentationUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/representations/AccountUserRepresentationUserProfile.java similarity index 97% rename from services/src/main/java/org/keycloak/userprofile/profile/represenations/AccountUserRepresentationUserProfile.java rename to services/src/main/java/org/keycloak/userprofile/profile/representations/AccountUserRepresentationUserProfile.java index aa0434ad0b..25830fed95 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/represenations/AccountUserRepresentationUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/representations/AccountUserRepresentationUserProfile.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.userprofile.profile.represenations; +package org.keycloak.userprofile.profile.representations; import org.keycloak.models.UserModel; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/represenations/AttributeUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/representations/AttributeUserProfile.java similarity index 96% rename from services/src/main/java/org/keycloak/userprofile/profile/represenations/AttributeUserProfile.java rename to services/src/main/java/org/keycloak/userprofile/profile/representations/AttributeUserProfile.java index 8524cff5df..fa1168c609 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/represenations/AttributeUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/representations/AttributeUserProfile.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.userprofile.profile.represenations; +package org.keycloak.userprofile.profile.representations; import org.keycloak.userprofile.profile.AbstractUserProfile; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/represenations/IdpUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/representations/IdpUserProfile.java similarity index 96% rename from services/src/main/java/org/keycloak/userprofile/profile/represenations/IdpUserProfile.java rename to services/src/main/java/org/keycloak/userprofile/profile/representations/IdpUserProfile.java index ad0d47ea91..a6a065d02b 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/represenations/IdpUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/representations/IdpUserProfile.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.userprofile.profile.represenations; +package org.keycloak.userprofile.profile.representations; import org.keycloak.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext; import org.keycloak.userprofile.profile.AbstractUserProfile; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/represenations/UserModelUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/representations/UserModelUserProfile.java similarity index 96% rename from services/src/main/java/org/keycloak/userprofile/profile/represenations/UserModelUserProfile.java rename to services/src/main/java/org/keycloak/userprofile/profile/representations/UserModelUserProfile.java index b457fffbfa..ebbc5bec3f 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/represenations/UserModelUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/representations/UserModelUserProfile.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.userprofile.profile.represenations; +package org.keycloak.userprofile.profile.representations; import org.keycloak.models.UserModel; import org.keycloak.userprofile.profile.AbstractUserProfile; diff --git a/services/src/main/java/org/keycloak/userprofile/profile/represenations/UserRepresentationUserProfile.java b/services/src/main/java/org/keycloak/userprofile/profile/representations/UserRepresentationUserProfile.java similarity index 97% rename from services/src/main/java/org/keycloak/userprofile/profile/represenations/UserRepresentationUserProfile.java rename to services/src/main/java/org/keycloak/userprofile/profile/representations/UserRepresentationUserProfile.java index d19eeacef4..c2370e69f0 100644 --- a/services/src/main/java/org/keycloak/userprofile/profile/represenations/UserRepresentationUserProfile.java +++ b/services/src/main/java/org/keycloak/userprofile/profile/representations/UserRepresentationUserProfile.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.keycloak.userprofile.profile.represenations; +package org.keycloak.userprofile.profile.representations; import org.keycloak.models.UserModel; import org.keycloak.representations.idm.UserRepresentation; diff --git a/services/src/main/java/org/keycloak/userprofile/utils/StoredUserProfile.java b/services/src/main/java/org/keycloak/userprofile/utils/StoredUserProfile.java deleted file mode 100644 index f1cc91e056..0000000000 --- a/services/src/main/java/org/keycloak/userprofile/utils/StoredUserProfile.java +++ /dev/null @@ -1,37 +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.userprofile.utils; - -import org.keycloak.userprofile.UserProfile; - -import java.util.List; - -/** - * Abstraction, which allows to update the user in various contexts (Required action of already existing user, or first identity provider - * login when user doesn't yet exists in Keycloak DB) - * - * @author Markus Till - */ -public interface StoredUserProfile extends UserProfile { - - void setSingleAttribute(String name, String value); - - void setAttribute(String key, List value); - - void removeAttribute(String attr); -} diff --git a/services/src/main/java/org/keycloak/userprofile/utils/UserProfileUpdateHelper.java b/services/src/main/java/org/keycloak/userprofile/utils/UserProfileUpdateHelper.java index 5195a437c3..eb6ce1fbf1 100644 --- a/services/src/main/java/org/keycloak/userprofile/utils/UserProfileUpdateHelper.java +++ b/services/src/main/java/org/keycloak/userprofile/utils/UserProfileUpdateHelper.java @@ -21,6 +21,7 @@ import org.keycloak.models.KeycloakSession; import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.keycloak.models.utils.KeycloakModelUtils; +import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.validation.UserUpdateEvent; import java.util.Collections; @@ -34,12 +35,12 @@ import java.util.Set; */ public class UserProfileUpdateHelper { - public static void update(UserUpdateEvent userUpdateEvent, KeycloakSession session, UserModel currentUser, StoredUserProfile updatedUser) { + public static void update(UserUpdateEvent userUpdateEvent, KeycloakSession session, UserModel currentUser, UserProfile updatedUser) { update(userUpdateEvent, session, currentUser, updatedUser, true); } - public static void update(UserUpdateEvent userUpdateEvent, KeycloakSession session, UserModel currentUser, StoredUserProfile updatedUser, boolean removeMissingAttributes) { + public static void update(UserUpdateEvent userUpdateEvent, KeycloakSession session, UserModel currentUser, UserProfile updatedUser, boolean removeMissingAttributes) { RealmModel realm = session.getContext().getRealm(); if (updatedUser.getAttributes() == null || updatedUser.getAttributes().size() == 0) @@ -56,7 +57,7 @@ public class UserProfileUpdateHelper { if (updatedUser.getFirstAttribute(UserModel.EMAIL) != null && updatedUser.getFirstAttribute(UserModel.EMAIL).isEmpty()) { updatedUser.removeAttribute(UserModel.EMAIL); -// updatedUser.setAttribute(UserModel.EMAIL, Collections.singletonList(null)); + updatedUser.setAttribute(UserModel.EMAIL, Collections.singletonList(null)); } if (updatedUser.getFirstAttribute(UserModel.EMAIL) != null && realm.isRegistrationEmailAsUsername()) { diff --git a/services/src/test/java/org/keycloak/userprofile/validation/ValidationChainTest.java b/services/src/test/java/org/keycloak/userprofile/validation/ValidationChainTest.java index 7e0d5e91b0..c43328e5cb 100644 --- a/services/src/test/java/org/keycloak/userprofile/validation/ValidationChainTest.java +++ b/services/src/test/java/org/keycloak/userprofile/validation/ValidationChainTest.java @@ -7,7 +7,7 @@ import org.keycloak.models.UserModel; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.userprofile.profile.DefaultUserProfileContext; import org.keycloak.userprofile.UserProfile; -import org.keycloak.userprofile.profile.represenations.UserRepresentationUserProfile; +import org.keycloak.userprofile.profile.representations.UserRepresentationUserProfile; import java.util.Collections; import java.util.stream.Collectors;