Yair Zaslavsky has uploaded a new change for review. Change subject: 8. [WIP] core: Introducing the extension interface ......................................................................
8. [WIP] core: Introducing the extension interface Change-Id: Ic8f583d635c059972a2a536d3c49a58cfcf3234b Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- M backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Authenticator.java M backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Directory.java M backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/internal/InternalDirectory.java M backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/nop/NopDirectory.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/aaa/provisional/ProvisionalDirectory.java A backend/manager/modules/extension-manager/src/main/java/org/ovirt/engine/core/extensions/mgr/Extension.java 6 files changed, 113 insertions(+), 62 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/11/24811/1 diff --git a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Authenticator.java b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Authenticator.java index aeee5a7..ea782f7 100644 --- a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Authenticator.java +++ b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Authenticator.java @@ -1,9 +1,13 @@ package org.ovirt.engine.core.aaa; +import java.util.Properties; + +import org.ovirt.engine.core.extensions.mgr.Extension; + /** * A authenticator is an object used to verify an identity. */ -public abstract class Authenticator { +public abstract class Authenticator implements Extension { /** * Returns the name of the profile the authenticator is associated with @@ -13,10 +17,28 @@ return profileName; } + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setConfigurationProperties(Properties props) { + this.properties = props; + } + + public Properties getConfigurationProperties() { + return properties; + } + protected Authenticator(String profileName) { this.profileName = profileName; } private String profileName; + private String name; + private Properties properties; } diff --git a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Directory.java b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Directory.java index 54132fe..cae365c 100644 --- a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Directory.java +++ b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/Directory.java @@ -2,20 +2,38 @@ import java.io.Serializable; import java.util.List; +import java.util.Properties; import org.ovirt.engine.core.common.utils.ExternalId; +import org.ovirt.engine.core.extensions.mgr.Extension; /** * A directory is an object that manages a collection of users and groups, usually stored in an external system like an * LDAP database. */ -public interface Directory extends Serializable { +public abstract class Directory implements Extension, Serializable { /** - * Returns the name of the directory. * - * @return the name of the directory */ - String getName(); + private static final long serialVersionUID = -8724317446083142917L; + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + public Properties getConfigurationProperties() { + return configruationProperties; + } + + public void setConfigurationProperties(Properties configurationProperties) { + this.configruationProperties = configurationProperties; + } /** * Retrieves a user from the directory given its name. The name is expected to be unique. @@ -23,7 +41,7 @@ * @param name the name of the user * @return the user corresponding to the given name or {@code null} if no such user can be found */ - DirectoryUser findUser(String name); + public abstract DirectoryUser findUser(String name); /** * Retrieves a user from the directory given its identifier. @@ -31,7 +49,7 @@ * @param id the identifier of the user * @return the user corresponding to the given identifier or {@code null} if no such user can be found */ - DirectoryUser findUser(ExternalId id); + public abstract DirectoryUser findUser(ExternalId id); /** * Retrieves a list of users from the directory given their identifiers. @@ -40,7 +58,7 @@ * @return a list containing at most on user for each identifier in the given set with no particular order, note * that the returned list may contain less elements than the given list of identifiers */ - List<DirectoryUser> findUsers(List<ExternalId> ids); + public abstract List<DirectoryUser> findUsers(List<ExternalId> ids); /** * Retrieves a group from the directory given its name. @@ -48,7 +66,7 @@ * @param name the name of the group * @return the group corresponding to the given name or {@code null} if no such group can be found */ - DirectoryGroup findGroup(String name); + public abstract DirectoryGroup findGroup(String name); /** * Retrieves a group from the directory given its identifier. @@ -56,7 +74,7 @@ * @param id the identifier of the group * @return the group corresponding to the given identifier or {@code null} if no such group can be found */ - DirectoryGroup findGroup(ExternalId id); + public abstract DirectoryGroup findGroup(ExternalId id); /** * Search the directory looking for users that match the given search query. Note that the query uses the LDAP query @@ -66,7 +84,7 @@ * @param query the LDAP query * @return a list containing the users that match the given query */ - List<DirectoryUser> queryUsers(String query); + public abstract List<DirectoryUser> queryUsers(String query); /** * Search the directory looking for groups that match the given search query. Note that the query uses the LDAP @@ -76,5 +94,9 @@ * @param query the LDAP query * @return a list containing the groups that match the given query */ - List<DirectoryGroup> queryGroups(String query); + public abstract List<DirectoryGroup> queryGroups(String query); + + private String name; + private Properties configruationProperties; + } diff --git a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/internal/InternalDirectory.java b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/internal/InternalDirectory.java index 592a4c2..7c2bd2a 100644 --- a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/internal/InternalDirectory.java +++ b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/internal/InternalDirectory.java @@ -14,16 +14,12 @@ /** * This directory contains only the internal user as specified in the {@code AdminUser} configuration parameter. */ -public class InternalDirectory implements Directory { +public class InternalDirectory extends Directory { /** * */ private static final long serialVersionUID = 6614140186031169227L; - /** - * The name of the directory: - */ - private String name; /** * The name of the admin user and of the internal domain come from the configuration of the engine. @@ -49,19 +45,9 @@ * @param name the name of the directory */ public InternalDirectory(String name) { - // Save the name of the domain: - this.name = name; - + setName(name); // Create the builtin user: admin = new DirectoryUser(this.getName(), ADMIN_ID, ADMIN_NAME); - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return name; } /** diff --git a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/nop/NopDirectory.java b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/nop/NopDirectory.java index f6d52d7..8ae8c32 100644 --- a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/nop/NopDirectory.java +++ b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/nop/NopDirectory.java @@ -10,15 +10,11 @@ import org.ovirt.engine.core.aaa.DirectoryUser; import org.ovirt.engine.core.common.utils.ExternalId; -public class NopDirectory implements Directory { +public class NopDirectory extends Directory { /** * */ private static final long serialVersionUID = 3719648746441818198L; - /** - * The name of the directory. - */ - private String name; /** * Create a new NOP directory. @@ -26,15 +22,7 @@ * @param name the name of the directory */ public NopDirectory(String name) { - this.name = name; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return name; + setName(name); } /** diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/aaa/provisional/ProvisionalDirectory.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/aaa/provisional/ProvisionalDirectory.java index 3870643..b6dd09e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/aaa/provisional/ProvisionalDirectory.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/aaa/provisional/ProvisionalDirectory.java @@ -26,7 +26,7 @@ * This directory implementation is a bridge between the new directory interfaces and the existing LDAP infrastructure. * It will exist only while the engine is migrated to use the new directory interfaces, then it will be removed. */ -public class ProvisionalDirectory implements Directory { +public class ProvisionalDirectory extends Directory { /** * */ @@ -35,23 +35,13 @@ private static final Log log = LogFactory.getLog(ProvisionalDirectory.class); /** - * The name of the domain. - */ - private String domain; - - /** * The reference to the LDAP broker that implements the authentication. */ private LdapBroker broker; public ProvisionalDirectory(String domain, LdapBroker broker) { - this.domain = domain; + setName(domain); this.broker = broker; - } - - @Override - public String getName() { - return domain; } @Override @@ -59,7 +49,7 @@ // Find the user with the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.GetAdUserByUserId, - new LdapSearchByIdParameters(domain, id) + new LdapSearchByIdParameters(getName(), id) ); LdapUser ldapUser = (LdapUser) ldapResult.getReturnValue(); @@ -72,7 +62,7 @@ // Find the user with the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.GetAdUserByUserName, - new LdapSearchByUserNameParameters(null, domain, name) + new LdapSearchByUserNameParameters(null, getName(), name) ); LdapUser ldapUser = (LdapUser) ldapResult.getReturnValue(); if (ldapUser == null) { @@ -88,7 +78,7 @@ // Find the users using the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.GetAdUserByUserIdList, - new LdapSearchByUserIdListParameters(domain, ids, false) + new LdapSearchByUserIdListParameters(getName(), ids, false) ); @SuppressWarnings("unchecked") List<LdapUser> ldapUsers = (List<LdapUser>) ldapResult.getReturnValue(); @@ -106,7 +96,7 @@ // Find the users using the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.SearchUserByQuery, - new LdapSearchByQueryParameters(null, domain, data) + new LdapSearchByQueryParameters(null, getName(), data) ); List<LdapUser> ldapUsers = (List<LdapUser>) ldapResult.getReturnValue(); @@ -136,12 +126,13 @@ // Populate the groups of the user (note that as we a calling a method of this directory to do so we should // first locate it using the manager, calling the method directory would bypass any decorator that may put on // top of the directory): - Directory directory = DirectoryManager.getInstance().getDirectory(domain); + Directory directory = DirectoryManager.getInstance().getDirectory(getName()); if (directory == null) { log.warnFormat( "Can't find domain \"{0}\" to retrieve groups for user \"{1}\", the groups and related permissions " + "won't be available.", - domain, ldapUser.getUserId() + getName(), + ldapUser.getUserId() ); } else { @@ -184,7 +175,7 @@ // Find the group using the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.GetAdGroupByGroupId, - new LdapSearchByIdParameters(domain, id) + new LdapSearchByIdParameters(getName(), id) ); LdapGroup ldapGroup = (LdapGroup) ldapResult.getReturnValue(); @@ -201,7 +192,7 @@ // Find the groups using the old mechanism: LdapReturnValueBase ldapResult = broker.runAdAction( AdActionType.SearchGroupsByQuery, - new LdapSearchByQueryParameters(null, domain, data) + new LdapSearchByQueryParameters(null, getName(), data) ); List<LdapGroup> ldapGroups = (List<LdapGroup>) ldapResult.getReturnValue(); diff --git a/backend/manager/modules/extension-manager/src/main/java/org/ovirt/engine/core/extensions/mgr/Extension.java b/backend/manager/modules/extension-manager/src/main/java/org/ovirt/engine/core/extensions/mgr/Extension.java new file mode 100644 index 0000000..6ebbf18 --- /dev/null +++ b/backend/manager/modules/extension-manager/src/main/java/org/ovirt/engine/core/extensions/mgr/Extension.java @@ -0,0 +1,42 @@ +package org.ovirt.engine.core.extensions.mgr; + +import java.util.Properties; + +/** + * Defines the interface for an extesnion + */ +public interface Extension { + + /** + * Sets the extension name + * + * @param name + * the name of the extension + */ + void setName(String name); + + /** + * Gets the extension name + * + * @return the extension name + */ + String getName(); + + /** + * Sets properties that can be used to configure the Extension + * + * @param properties + * the properties to be set + * @throws IllegalArgumentException + * thrown in case of configuration error + */ + void setConfigurationProperties(Properties properties) throws IllegalArgumentException; + + /** + * Gets the configuration properties + * + * @return the configuration properties + */ + Properties getConfigurationProperties(); + +} -- To view, visit http://gerrit.ovirt.org/24811 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic8f583d635c059972a2a536d3c49a58cfcf3234b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches