From 4d8e19eb7c702a7032c4780a1f1aeea9e9e2e888 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 10 Aug 2016 17:28:38 -0300 Subject: [PATCH] Removal of never used classes from the changeset package --- .../keycloak/storage/changeset/UserData.java | 387 ------------------ .../storage/changeset/UserDataAdapter.java | 340 --------------- 2 files changed, 727 deletions(-) delete mode 100755 server-spi/src/main/java/org/keycloak/storage/changeset/UserData.java delete mode 100644 server-spi/src/main/java/org/keycloak/storage/changeset/UserDataAdapter.java diff --git a/server-spi/src/main/java/org/keycloak/storage/changeset/UserData.java b/server-spi/src/main/java/org/keycloak/storage/changeset/UserData.java deleted file mode 100755 index 4b2813a87a..0000000000 --- a/server-spi/src/main/java/org/keycloak/storage/changeset/UserData.java +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Copyright 2016 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.storage.changeset; - -import org.keycloak.common.util.MultivaluedHashMap; -import org.keycloak.models.UserCredentialValueModel; -import org.keycloak.models.entities.AbstractIdentifiableEntity; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -/** - * @author Marek Posolda - */ -public class UserData { - - private String id; - private boolean idChanged; - private String username; - private boolean usernameChanged; - private Long createdTimestamp; - private boolean createdTimestampChanged; - private String firstName; - private boolean firstNameChanged; - private String lastName; - private boolean lastNameChanged; - private String email; - private boolean emailChanged; - private boolean emailVerified; - private boolean emailVerifiedChanged; - private boolean totp; - private boolean totpChanged; - private boolean enabled; - private boolean enabledChanged; - - private Set roleIds = new HashSet<>(); - private boolean rolesChanged; - private Set groupIds = new HashSet<>(); - private boolean groupsChanged; - - private MultivaluedHashMap attributes = new MultivaluedHashMap<>(); - private boolean attributesChanged; - private Set requiredActions = new HashSet<>(); - private boolean requiredActionsChanged; - private List credentials = new LinkedList<>(); - private boolean credentialsChanged; - - public void rememberState() { - original = new UserData(); - original.id = id; - original.username = username; - original.createdTimestamp = createdTimestamp; - original.firstName = firstName; - original.lastName = lastName; - original.email = email; - original.emailVerified = emailVerified; - original.totp = totp; - original.enabled = enabled; - original.attributes.putAll(attributes); - original.requiredActions.addAll(requiredActions); - original.credentials.addAll(credentials); - } - - private UserData original = null; - - public void clearChangeFlags() { - original = null; - idChanged = false; - usernameChanged = false; - createdTimestampChanged = false; - firstNameChanged = false; - lastNameChanged = false; - emailChanged = false; - emailVerifiedChanged = false; - totpChanged = false; - enabledChanged = false; - rolesChanged = false; - groupsChanged = false; - attributesChanged = false; - requiredActionsChanged = false; - credentialsChanged = false; - } - - public boolean isChanged() { - return !idChanged - && !usernameChanged - && !createdTimestampChanged - && !firstNameChanged - && !lastNameChanged - && !emailChanged - && !emailVerifiedChanged - && !totpChanged - && !enabledChanged - && !rolesChanged - && !groupsChanged - && !attributesChanged - && !requiredActionsChanged - && !credentialsChanged; - } - - public boolean isIdChanged() { - return idChanged; - } - - public boolean isUsernameChanged() { - return usernameChanged; - } - - public boolean isCreatedTimestampChanged() { - return createdTimestampChanged; - } - - public boolean isFirstNameChanged() { - return firstNameChanged; - } - - public boolean isLastNameChanged() { - return lastNameChanged; - } - - public boolean isEmailChanged() { - return emailChanged; - } - - public boolean isEmailVerifiedChanged() { - return emailVerifiedChanged; - } - - public boolean isTotpChanged() { - return totpChanged; - } - - public boolean isEnabledChanged() { - return enabledChanged; - } - - public boolean isRolesChanged() { - return rolesChanged; - } - - public boolean isGroupsChanged() { - return groupsChanged; - } - - public boolean isAttributesChanged() { - return attributesChanged; - } - - public boolean isRequiredActionsChanged() { - return requiredActionsChanged; - } - - public boolean isCredentialsChanged() { - return credentialsChanged; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - idChanged = true; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - usernameChanged = true; - } - - public Long getCreatedTimestamp() { - return createdTimestamp; - } - - public void setCreatedTimestamp(Long timestamp) { - this.createdTimestamp = timestamp; - createdTimestampChanged = true; - } - - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - firstNameChanged = true; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - lastNameChanged = true; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - emailChanged = true; - } - - public boolean isEmailVerified() { - return emailVerified; - } - - public void setEmailVerified(boolean emailVerified) { - this.emailVerified = emailVerified; - emailVerifiedChanged = true; - } - - public boolean isTotp() { - return totp; - } - - public void setTotp(boolean totp) { - this.totp = totp; - totpChanged = true; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - enabledChanged = true; - } - - public Set getRoleMappings() { - return Collections.unmodifiableSet(roleIds); - } - - public void grantRole(String roleId) { - if (roleIds.contains(roleId)) return; - roleIds.add(roleId); - rolesChanged = true; - } - - public void deleteRoleMapping(String roleId) { - if (!roleIds.contains(roleId)) return; - roleIds.remove(roleId); - rolesChanged = true; - } - - public MultivaluedHashMap getAttributes() { - return attributes; - } - - public void setSingleAttribute(String name, String value) { - attributes.putSingle(name, value); - attributesChanged = true; - - } - public void setAttribute(String name, List values) { - attributes.put(name, values); - attributesChanged = true; - } - public void removeAttribute(String name) { - attributes.remove(name); - attributesChanged = true; - } - - - - public Set getRequiredActions() { - return Collections.unmodifiableSet(requiredActions); - } - public void addRequiredAction(String action) { - if (requiredActions.contains(action)) return; - requiredActions.add(action); - requiredActionsChanged = true; - } - public void removeRequiredAction(String action) { - if (!requiredActions.contains(action)) return; - requiredActions.remove(action); - requiredActionsChanged = true; - } - - public List getCredentials() { - return Collections.unmodifiableList(credentials); - } - - public void removeCredentialType(String type) { - Iterator it = credentials.iterator(); - while (it.hasNext()) { - if (it.next().getType().equals(type)) { - it.remove(); - credentialsChanged = true; - } - } - - } - - public void removeCredentialDevice(String type, String device) { - Iterator it = credentials.iterator(); - while (it.hasNext()) { - UserCredentialValueModel next = it.next(); - if (next.getType().equals(type) && next.getDevice().equals(device)) { - it.remove(); - credentialsChanged = true; - } - } - - } - - public void setCredential(UserCredentialValueModel cred) { - removeCredentialType(cred.getType()); - addCredential(cred); - } - public void addCredential(UserCredentialValueModel cred) { - credentials.add(cred); - credentialsChanged = true; - } - - public Set getGroupIds() { - return Collections.unmodifiableSet(groupIds); - } - - public void joinGroup(String groupId) { - if (groupIds.contains(groupId)) return; - groupIds.add(groupId); - groupsChanged = true; - } - - public void leaveGroup(String groupId) { - if (!groupIds.contains(groupId)) return; - groupIds.remove(groupId); - groupsChanged = true; - } - - @Override - public boolean equals(Object o) { - if (o == this) return true; - - if (this.id == null) return false; - - if (o == null || getClass() != o.getClass()) return false; - - AbstractIdentifiableEntity that = (AbstractIdentifiableEntity) o; - - if (!getId().equals(that.getId())) return false; - - return true; - - } - - @Override - public int hashCode() { - return id!=null ? id.hashCode() : super.hashCode(); - } - - @Override - public String toString() { - return String.format("%s [ id=%s ]", getClass().getSimpleName(), getId()); - } - -} - diff --git a/server-spi/src/main/java/org/keycloak/storage/changeset/UserDataAdapter.java b/server-spi/src/main/java/org/keycloak/storage/changeset/UserDataAdapter.java deleted file mode 100644 index 6ec78f25b6..0000000000 --- a/server-spi/src/main/java/org/keycloak/storage/changeset/UserDataAdapter.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright 2016 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.storage.changeset; - -import org.keycloak.common.util.Time; -import org.keycloak.hash.PasswordHashManager; -import org.keycloak.models.ClientModel; -import org.keycloak.models.GroupModel; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.OTPPolicy; -import org.keycloak.models.PasswordPolicy; -import org.keycloak.models.RealmModel; -import org.keycloak.models.RoleContainerModel; -import org.keycloak.models.RoleModel; -import org.keycloak.models.UserCredentialModel; -import org.keycloak.models.UserCredentialValueModel; -import org.keycloak.models.UserModel; -import org.keycloak.models.utils.KeycloakModelUtils; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * - * - * @author Bill Burke - * @version $Revision: 1 $ - */ -public class UserDataAdapter implements UserModel { - protected UserData userData; - protected RealmModel realm; - protected KeycloakSession session; - protected Set managedCredentialTypes; - protected List updatedManagedCredentials = new LinkedList<>(); - - public UserDataAdapter(KeycloakSession session, RealmModel realm, UserData userData) { - this.session = session; - this.realm = realm; - this.userData = userData; - this.userData.rememberState(); - } - - @Override - public String getId() { - return userData.getId(); - } - - @Override - public String getUsername() { - return userData.getUsername(); - } - - @Override - public void setUsername(String username) { - userData.setUsername(username); - - } - - @Override - public Long getCreatedTimestamp() { - return userData.getCreatedTimestamp(); - } - - @Override - public void setCreatedTimestamp(Long timestamp) { - userData.setCreatedTimestamp(timestamp); - - } - - @Override - public boolean isEnabled() { - return userData.isEnabled(); - } - - @Override - public boolean isOtpEnabled() { - return userData.isTotp(); - } - - @Override - public void setEnabled(boolean enabled) { - userData.setEnabled(enabled); - - } - - @Override - public void setSingleAttribute(String name, String value) { - userData.setSingleAttribute(name, value); - - } - - @Override - public void setAttribute(String name, List values) { - userData.setAttribute(name, values); - - } - - @Override - public void removeAttribute(String name) { - userData.removeAttribute(name); - - } - - @Override - public String getFirstAttribute(String name) { - return userData.getAttributes().getFirst(name); - } - - @Override - public List getAttribute(String name) { - return userData.getAttributes().get(name); - } - - @Override - public Map> getAttributes() { - return userData.getAttributes(); - } - - @Override - public Set getRequiredActions() { - return userData.getRequiredActions(); - } - - @Override - public void addRequiredAction(String action) { - userData.addRequiredAction(action); - - } - - @Override - public void removeRequiredAction(String action) { - userData.removeRequiredAction(action); - - } - - @Override - public void addRequiredAction(RequiredAction action) { - userData.addRequiredAction(action.name()); - - } - - @Override - public void removeRequiredAction(RequiredAction action) { - userData.removeRequiredAction(action.name()); - - } - - @Override - public String getFirstName() { - return userData.getFirstName(); - } - - @Override - public void setFirstName(String firstName) { - userData.setFirstName(firstName); - - } - - @Override - public String getLastName() { - return userData.getLastName(); - } - - @Override - public void setLastName(String lastName) { - userData.setLastName(lastName); - - } - - @Override - public String getEmail() { - return userData.getEmail(); - } - - @Override - public void setEmail(String email) { - userData.setEmail(email); - - } - - @Override - public boolean isEmailVerified() { - return userData.isEmailVerified(); - } - - @Override - public void setEmailVerified(boolean verified) { - userData.setEmailVerified(verified); - - } - - @Override - public void setOtpEnabled(boolean totp) { - userData.setTotp(totp); - - } - - @Override - public void updateCredential(UserCredentialModel cred) { - - } - - @Override - public List getCredentialsDirectly() { - return null; - } - - @Override - public void updateCredentialDirectly(UserCredentialValueModel cred) { - - } - - @Override - public Set getGroups() { - Set groups = userData.getGroupIds(); - Set set = new HashSet<>(); - for (String id : groups) { - GroupModel group = realm.getGroupById(id); - if (group != null) set.add(group); - } - return set; - } - - @Override - public void joinGroup(GroupModel group) { - userData.joinGroup(group.getId()); - - } - - @Override - public void leaveGroup(GroupModel group) { - userData.leaveGroup(group.getId()); - - } - - @Override - public boolean isMemberOf(GroupModel group) { - Set roles = getGroups(); - return KeycloakModelUtils.isMember(roles, group); - } - - @Override - public String getFederationLink() { - return null; - } - - @Override - public void setFederationLink(String link) { - - } - - @Override - public String getServiceAccountClientLink() { - return null; - } - - @Override - public void setServiceAccountClientLink(String clientInternalId) { - - } - - @Override - public Set getRealmRoleMappings() { - Set roleMappings = getRoleMappings(); - - Set realmRoles = new HashSet(); - for (RoleModel role : roleMappings) { - RoleContainerModel container = role.getContainer(); - if (container instanceof RealmModel) { - realmRoles.add(role); - } - } - return realmRoles; - } - - @Override - public Set getClientRoleMappings(ClientModel app) { - Set roleMappings = getRoleMappings(); - - Set roles = new HashSet(); - for (RoleModel role : roleMappings) { - RoleContainerModel container = role.getContainer(); - if (container instanceof ClientModel) { - ClientModel appModel = (ClientModel)container; - if (appModel.getId().equals(app.getId())) { - roles.add(role); - } - } - } - return roles; - } - - @Override - public boolean hasRole(RoleModel role) { - Set roles = getRoleMappings(); - return KeycloakModelUtils.hasRole(roles, role); - } - - @Override - public void grantRole(RoleModel role) { - userData.grantRole(role.getId()); - - } - - @Override - public Set getRoleMappings() { - Set roles = userData.getRoleMappings(); - Set set = new HashSet<>(); - for (String id : roles) { - RoleModel role = realm.getRoleById(id); - if (role != null) set.add(role); - } - return set; - } - - @Override - public void deleteRoleMapping(RoleModel role) { - userData.deleteRoleMapping(role.getId()); - } -}