Merge pull request #3566 from patriot1burke/master

UserBulkUpdateProvider interface
This commit is contained in:
Bill Burke 2016-11-29 20:18:07 -05:00 committed by GitHub
commit 294dc6fbd0
10 changed files with 40 additions and 35 deletions

View file

@ -155,11 +155,6 @@ public class EjbExampleUserStorageProvider implements UserStorageProvider,
return true; return true;
} }
@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {
}
@Override @Override
public void onCache(RealmModel realm, CachedUserModel user, UserModel delegate) { public void onCache(RealmModel realm, CachedUserModel user, UserModel delegate) {
String password = ((UserAdapter)delegate).getPassword(); String password = ((UserAdapter)delegate).getPassword();

View file

@ -93,11 +93,6 @@ public class FilePropertiesStorageProvider extends BasePropertiesStorageProvider
return createAdapter(realm, username); return createAdapter(realm, username);
} }
@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {
// unsupported
}
@Override @Override
public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) { public boolean updateCredential(RealmModel realm, UserModel user, CredentialInput input) {
if (!(input instanceof UserCredentialModel)) return false; if (!(input instanceof UserCredentialModel)) return false;

View file

@ -168,11 +168,6 @@ public class LDAPStorageProvider implements UserStorageProvider,
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {
}
public boolean synchronizeRegistrations() { public boolean synchronizeRegistrations() {
return "true".equalsIgnoreCase(model.getConfig().getFirst(LDAPConstants.SYNC_REGISTRATIONS)) && editMode == UserStorageProvider.EditMode.WRITABLE; return "true".equalsIgnoreCase(model.getConfig().getFirst(LDAPConstants.SYNC_REGISTRATIONS)) && editMode == UserStorageProvider.EditMode.WRITABLE;
} }

View file

@ -19,6 +19,7 @@ package org.keycloak.models;
import org.keycloak.component.ComponentModel; import org.keycloak.component.ComponentModel;
import org.keycloak.provider.Provider; import org.keycloak.provider.Provider;
import org.keycloak.storage.user.UserBulkUpdateProvider;
import org.keycloak.storage.user.UserLookupProvider; import org.keycloak.storage.user.UserLookupProvider;
import org.keycloak.storage.user.UserQueryProvider; import org.keycloak.storage.user.UserQueryProvider;
import org.keycloak.storage.user.UserRegistrationProvider; import org.keycloak.storage.user.UserRegistrationProvider;
@ -33,7 +34,8 @@ import java.util.Set;
public interface UserProvider extends Provider, public interface UserProvider extends Provider,
UserLookupProvider, UserLookupProvider,
UserQueryProvider, UserQueryProvider,
UserRegistrationProvider { UserRegistrationProvider,
UserBulkUpdateProvider {
// Note: The reason there are so many query methods here is for layering a cache on top of an persistent KeycloakSession // Note: The reason there are so many query methods here is for layering a cache on top of an persistent KeycloakSession
public void addFederatedIdentity(RealmModel realm, UserModel user, FederatedIdentityModel socialLink); public void addFederatedIdentity(RealmModel realm, UserModel user, FederatedIdentityModel socialLink);

View file

@ -33,21 +33,22 @@ public interface UserStorageProvider extends Provider {
void preRemove(RealmModel realm, RoleModel role); void preRemove(RealmModel realm, RoleModel role);
/** /**
* Optional type that can be by implementations to describe edit mode of federation storage * Optional type that can be used by implementations to
* describe edit mode of user storage
* *
*/ */
enum EditMode { enum EditMode {
/** /**
* federation storage is read-only * user storage is read-only
*/ */
READ_ONLY, READ_ONLY,
/** /**
* federation storage is writable * user storage is writable
* *
*/ */
WRITABLE, WRITABLE,
/** /**
* updates to user are stored locally and not synced with federation storage. * updates to user are stored locally and not synced with user storage.
* *
*/ */
UNSYNCED UNSYNCED

View file

@ -0,0 +1,28 @@
/*
* 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.user;
import org.keycloak.models.RealmModel;
import org.keycloak.models.RoleModel;
/**
* @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
* @version $Revision: 1 $
*/
public interface UserBulkUpdateProvider {
void grantToAllUsers(RealmModel realm, RoleModel role);
}

View file

@ -30,6 +30,5 @@ public interface UserRegistrationProvider {
boolean removeUser(RealmModel realm, UserModel user); boolean removeUser(RealmModel realm, UserModel user);
void grantToAllUsers(RealmModel realm, RoleModel role);
} }

View file

@ -37,6 +37,7 @@ import org.keycloak.models.cache.CachedUserModel;
import org.keycloak.models.cache.OnUserCache; import org.keycloak.models.cache.OnUserCache;
import org.keycloak.storage.federated.UserFederatedStorageProvider; import org.keycloak.storage.federated.UserFederatedStorageProvider;
import org.keycloak.storage.user.ImportedUserValidation; import org.keycloak.storage.user.ImportedUserValidation;
import org.keycloak.storage.user.UserBulkUpdateProvider;
import org.keycloak.storage.user.UserLookupProvider; import org.keycloak.storage.user.UserLookupProvider;
import org.keycloak.storage.user.UserQueryProvider; import org.keycloak.storage.user.UserQueryProvider;
import org.keycloak.storage.user.UserRegistrationProvider; import org.keycloak.storage.user.UserRegistrationProvider;
@ -521,12 +522,11 @@ public class UserStorageManager implements UserProvider, OnUserCache {
@Override @Override
public void grantToAllUsers(RealmModel realm, RoleModel role) { public void grantToAllUsers(RealmModel realm, RoleModel role) {
// not federation-aware for now List<UserBulkUpdateProvider> storageProviders = getStorageProviders(session, realm, UserBulkUpdateProvider.class);
List<UserRegistrationProvider> storageProviders = getStorageProviders(session, realm, UserRegistrationProvider.class); LinkedList<UserBulkUpdateProvider> providers = new LinkedList<>();
LinkedList<UserRegistrationProvider> providers = new LinkedList<>();
providers.add(localStorage()); providers.add(localStorage());
providers.addAll(storageProviders); providers.addAll(storageProviders);
for (UserRegistrationProvider provider : providers) { for (UserBulkUpdateProvider provider : providers) {
provider.grantToAllUsers(realm, role); provider.grantToAllUsers(realm, role);
} }
} }

View file

@ -85,11 +85,6 @@ public class DummyUserFederationProvider implements UserStorageProvider,
@Override @Override
public UserModel getUserByEmail(String email, RealmModel realm) { public UserModel getUserByEmail(String email, RealmModel realm) {
return null; return null;
}
@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {
} }
@Override @Override

View file

@ -149,11 +149,6 @@ public class UserMapStorage implements UserLookupProvider, UserStorageProvider,
return userPasswords.remove(user.getUsername()) != null; return userPasswords.remove(user.getUsername()) != null;
} }
@Override
public void grantToAllUsers(RealmModel realm, RoleModel role) {
}
@Override @Override
public void preRemove(RealmModel realm) { public void preRemove(RealmModel realm) {