remove StoredUserProfile interface

This commit is contained in:
Markus Till 2020-10-01 22:31:18 +02:00 committed by Pedro Igor
parent 72f73f153a
commit 21cfa54d4d
19 changed files with 35 additions and 70 deletions

View file

@ -32,8 +32,14 @@ public interface UserProfile {
Map<String, List<String>> getAttributes(); Map<String, List<String>> getAttributes();
String getFirstAttribute(String name); String getFirstAttribute(String key);
List<String> getAttribute(String key); List<String> getAttribute(String key);
void setSingleAttribute(String key, String value);
void setAttribute(String key, List<String> value);
void removeAttribute(String attr);
} }

View file

@ -37,9 +37,9 @@ import org.keycloak.services.resources.AttributeFormDataProcessor;
import org.keycloak.services.validation.Validation; import org.keycloak.services.validation.Validation;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfileProvider; 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.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.utils.UserProfileUpdateHelper;
import org.keycloak.userprofile.validation.UserProfileValidationResult; import org.keycloak.userprofile.validation.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;

View file

@ -37,10 +37,10 @@ import org.keycloak.services.validation.Validation;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfile;
import org.keycloak.userprofile.UserProfileProvider; 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.utils.UserProfileUpdateHelper;
import org.keycloak.userprofile.profile.DefaultUserProfileContext; 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.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;

View file

@ -40,10 +40,10 @@ import org.keycloak.services.validation.Validation;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfile;
import org.keycloak.userprofile.UserProfileProvider; 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.utils.UserProfileUpdateHelper;
import org.keycloak.userprofile.profile.DefaultUserProfileContext; 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.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;

View file

@ -35,10 +35,10 @@ import org.keycloak.services.resources.AttributeFormDataProcessor;
import org.keycloak.services.validation.Validation; import org.keycloak.services.validation.Validation;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfileProvider; 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.utils.UserProfileUpdateHelper;
import org.keycloak.userprofile.profile.DefaultUserProfileContext; 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.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;

View file

@ -19,7 +19,7 @@ package org.keycloak.services.resources;
import org.keycloak.models.Constants; import org.keycloak.models.Constants;
import org.keycloak.models.UserModel; 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 javax.ws.rs.core.MultivaluedMap;
import java.util.ArrayList; import java.util.ArrayList;

View file

@ -75,10 +75,10 @@ import org.keycloak.sessions.AuthenticationSessionModel;
import org.keycloak.storage.ReadOnlyException; import org.keycloak.storage.ReadOnlyException;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfileProvider; 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.utils.UserProfileUpdateHelper;
import org.keycloak.userprofile.profile.DefaultUserProfileContext; 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.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;
import org.keycloak.util.JsonSerialization; import org.keycloak.util.JsonSerialization;

View file

@ -22,7 +22,6 @@ import org.keycloak.common.ClientConnection;
import org.keycloak.common.enums.AccountRestApiVersion; import org.keycloak.common.enums.AccountRestApiVersion;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.common.util.StringPropertyReplacer; import org.keycloak.common.util.StringPropertyReplacer;
import org.keycloak.credential.CredentialModel;
import org.keycloak.events.EventBuilder; import org.keycloak.events.EventBuilder;
import org.keycloak.events.EventStoreProvider; import org.keycloak.events.EventStoreProvider;
import org.keycloak.events.EventType; import org.keycloak.events.EventType;
@ -51,13 +50,11 @@ import org.keycloak.theme.Theme;
import org.keycloak.userprofile.LegacyUserProfileProviderFactory; import org.keycloak.userprofile.LegacyUserProfileProviderFactory;
import org.keycloak.userprofile.UserProfileProvider; import org.keycloak.userprofile.UserProfileProvider;
import org.keycloak.userprofile.utils.UserProfileUpdateHelper; 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.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.UserProfileValidationResult;
import org.keycloak.userprofile.validation.UserUpdateEvent; 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.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;

View file

@ -72,7 +72,7 @@ import org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluato
import org.keycloak.services.validation.Validation; import org.keycloak.services.validation.Validation;
import org.keycloak.storage.ReadOnlyException; import org.keycloak.storage.ReadOnlyException;
import org.keycloak.userprofile.utils.UserProfileUpdateHelper; 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.userprofile.validation.UserUpdateEvent;
import org.keycloak.utils.ProfileHelper; import org.keycloak.utils.ProfileHelper;

View file

@ -18,7 +18,6 @@
package org.keycloak.userprofile.profile; package org.keycloak.userprofile.profile;
import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfile;
import org.keycloak.userprofile.utils.StoredUserProfile;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -27,7 +26,7 @@ import java.util.Map;
/** /**
* @author <a href="mailto:markus.till@bosch.io">Markus Till</a> * @author <a href="mailto:markus.till@bosch.io">Markus Till</a>
*/ */
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 @Override
public String getFirstAttribute(String key) { 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 @Override

View file

@ -17,7 +17,6 @@
package org.keycloak.userprofile.profile; package org.keycloak.userprofile.profile;
import org.keycloak.userprofile.utils.StoredUserProfile;
import org.keycloak.userprofile.UserProfile; import org.keycloak.userprofile.UserProfile;
import org.keycloak.userprofile.UserProfileContext; import org.keycloak.userprofile.UserProfileContext;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;
@ -27,7 +26,7 @@ import org.keycloak.userprofile.validation.UserUpdateEvent;
*/ */
public class DefaultUserProfileContext implements UserProfileContext { public class DefaultUserProfileContext implements UserProfileContext {
private boolean isCreated; private boolean isCreated;
private StoredUserProfile currentUserProfile; private UserProfile currentUserProfile;
private UserProfile updatedUserProfile; private UserProfile updatedUserProfile;
private UserUpdateEvent userUpdateEvent; private UserUpdateEvent userUpdateEvent;
@ -38,7 +37,7 @@ public class DefaultUserProfileContext implements UserProfileContext {
this.updatedUserProfile = updatedUserProfile; this.updatedUserProfile = updatedUserProfile;
} }
public DefaultUserProfileContext(UserUpdateEvent userUpdateEvent, StoredUserProfile currentUserProfile, UserProfile updatedUserProfile) { public DefaultUserProfileContext(UserUpdateEvent userUpdateEvent, UserProfile currentUserProfile, UserProfile updatedUserProfile) {
this.userUpdateEvent = userUpdateEvent; this.userUpdateEvent = userUpdateEvent;
this.isCreated = true; this.isCreated = true;
this.currentUserProfile = currentUserProfile; this.currentUserProfile = currentUserProfile;

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.userprofile.profile.represenations; package org.keycloak.userprofile.profile.representations;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.userprofile.profile.represenations; package org.keycloak.userprofile.profile.representations;
import org.keycloak.userprofile.profile.AbstractUserProfile; import org.keycloak.userprofile.profile.AbstractUserProfile;

View file

@ -15,7 +15,7 @@
* limitations under the License. * 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.authentication.authenticators.broker.util.SerializedBrokeredIdentityContext;
import org.keycloak.userprofile.profile.AbstractUserProfile; import org.keycloak.userprofile.profile.AbstractUserProfile;

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.userprofile.profile.represenations; package org.keycloak.userprofile.profile.representations;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.userprofile.profile.AbstractUserProfile; import org.keycloak.userprofile.profile.AbstractUserProfile;

View file

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.keycloak.userprofile.profile.represenations; package org.keycloak.userprofile.profile.representations;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;

View file

@ -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 <a href="mailto:markus.till@bosch.io">Markus Till</a>
*/
public interface StoredUserProfile extends UserProfile {
void setSingleAttribute(String name, String value);
void setAttribute(String key, List<String> value);
void removeAttribute(String attr);
}

View file

@ -21,6 +21,7 @@ import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.UserModel; import org.keycloak.models.UserModel;
import org.keycloak.models.utils.KeycloakModelUtils; import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.userprofile.UserProfile;
import org.keycloak.userprofile.validation.UserUpdateEvent; import org.keycloak.userprofile.validation.UserUpdateEvent;
import java.util.Collections; import java.util.Collections;
@ -34,12 +35,12 @@ import java.util.Set;
*/ */
public class UserProfileUpdateHelper { 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); 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(); RealmModel realm = session.getContext().getRealm();
if (updatedUser.getAttributes() == null || updatedUser.getAttributes().size() == 0) 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()) { if (updatedUser.getFirstAttribute(UserModel.EMAIL) != null && updatedUser.getFirstAttribute(UserModel.EMAIL).isEmpty()) {
updatedUser.removeAttribute(UserModel.EMAIL); 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()) { if (updatedUser.getFirstAttribute(UserModel.EMAIL) != null && realm.isRegistrationEmailAsUsername()) {

View file

@ -7,7 +7,7 @@ import org.keycloak.models.UserModel;
import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.userprofile.profile.DefaultUserProfileContext; import org.keycloak.userprofile.profile.DefaultUserProfileContext;
import org.keycloak.userprofile.UserProfile; 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.Collections;
import java.util.stream.Collectors; import java.util.stream.Collectors;