mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
[auth] UserRegistryImpl: Allow registering additional ManagedProviders & Allow field access for subclasses of GenericUser (#5328)
Signed-off-by: Florian Hotze <dev@florianhotze.com>
This commit is contained in:
@@ -21,13 +21,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
* Represents a generic {@link User} with a set of roles
|
||||
*
|
||||
* @author Yannick Schaus - initial contribution
|
||||
*
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class GenericUser implements User {
|
||||
|
||||
private String name;
|
||||
private Set<String> roles;
|
||||
protected String name;
|
||||
protected Set<String> roles;
|
||||
|
||||
/**
|
||||
* Constructs a user attributed with a set of roles.
|
||||
@@ -63,4 +61,9 @@ public class GenericUser implements User {
|
||||
public Set<String> getRoles() {
|
||||
return roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User (name=" + name + ", roles=" + String.join(", ", roles) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -26,6 +26,7 @@ import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.PBEKeySpec;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.auth.AuthenticatedUser;
|
||||
import org.openhab.core.auth.Authentication;
|
||||
import org.openhab.core.auth.AuthenticationException;
|
||||
@@ -39,6 +40,8 @@ import org.openhab.core.auth.UserRegistry;
|
||||
import org.openhab.core.auth.UserSession;
|
||||
import org.openhab.core.auth.UsernamePasswordCredentials;
|
||||
import org.openhab.core.common.registry.AbstractRegistry;
|
||||
import org.openhab.core.common.registry.ManagedProvider;
|
||||
import org.openhab.core.common.registry.Provider;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
@@ -256,6 +259,19 @@ public class UserRegistryImpl extends AbstractRegistry<User, String, UserProvide
|
||||
update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable User update(User element) {
|
||||
String key = element.getName();
|
||||
Provider<User> provider = getProvider(key);
|
||||
// If the provider of this element is a ManagedProvider,
|
||||
// invoke the update method of that provider instead of the default one
|
||||
// This allows for registering additional ManagedProviders, e.g., for providing LDAP users
|
||||
if (provider instanceof ManagedProvider<User, ?> managedProvider) {
|
||||
return managedProvider.update(element);
|
||||
}
|
||||
return super.update(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<? extends Credentials> type) {
|
||||
return (UsernamePasswordCredentials.class.isAssignableFrom(type));
|
||||
|
||||
Reference in New Issue
Block a user