Yair Zaslavsky has uploaded a new change for review. Change subject: 5. [WIP] core: Introducing AuthenticationProfileRepository ......................................................................
5. [WIP] core: Introducing AuthenticationProfileRepository This class will replace AuthenticationProfileManager in loading the profiles. The class will construct a profile based on two separate configurations - one of authenticator (authn) and one of directory (authz) Change-Id: If375fccea98544c64d9ec41cc9dbcb855bf02fb7 Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com> --- A backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/AuthenticationProfileRepository.java 1 file changed, 98 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/66/24366/1 diff --git a/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/AuthenticationProfileRepository.java b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/AuthenticationProfileRepository.java new file mode 100644 index 0000000..68b0c40 --- /dev/null +++ b/backend/manager/modules/aaa/src/main/java/org/ovirt/engine/core/aaa/AuthenticationProfileRepository.java @@ -0,0 +1,98 @@ +package org.ovirt.engine.core.aaa; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ovirt.engine.core.extensions.mgr.Configuration; +import org.ovirt.engine.core.extensions.mgr.ExtensionManagerKeys; + +public class AuthenticationProfileRepository { + + private static final String AUTHZ_PROFILE_NAME = "ovirt.engine.aaa.authz.profile.name"; + private static final String AUTHN_PROFILE_NAME = "ovirt.engine.aaa.authn.profile.name"; + private static final String AUTHZ_SERVICE_NAME = "org.ovirt.engine.core.authorization"; + private static final String AUTHN_SERVICE_NAME = "org.ovirt.engine.core.authentication"; + + + private static AuthenticationProfileRepository instance = null; + private Map<String, Directory> directoryMap = new HashMap<>(); + private Map<String, Authenticator> authenticatorMap = new HashMap<String, Authenticator>(); + private Map<String, AuthenticationProfile> profiles = new HashMap<String, AuthenticationProfile>(); + + static { + instance = new AuthenticationProfileRepository(); + } + + public static AuthenticationProfileRepository getInstance() { + return instance; + } + + public void parseConfigurations(List<Configuration> configurations) { + for (Configuration config: configurations) { + String name = null; + if (isAuthenticationConfig(config)) { + name = config.getString(AUTHN_PROFILE_NAME); + Directory directory = DirectoryManager.getInstance().parseDirectory(config); + directoryMap.put(name, directory); + + } else if (isAuthorizationConfig(config)) { + name = config.getString(AUTHZ_PROFILE_NAME); + Authenticator authenticator = AuthenticatorManager.getInstance().parseAuthenticator(config); + authenticatorMap.put(name, authenticator); + } + } + + for (Map.Entry<String, Authenticator> entry : authenticatorMap.entrySet()) { + String name = entry.getKey(); + Directory directory = directoryMap.get(name); + if (directory != null) { + AuthenticationProfile profile = new AuthenticationProfile(name, entry.getValue(), directory); + profiles.put(name, profile); + } + entry.getValue(); + } + } + + private boolean isAuthorizationConfig(Configuration config) { + String serviceValue = config.getString(ExtensionManagerKeys.service.getKeyName()); + return serviceValue != null && serviceValue.equalsIgnoreCase(AUTHZ_SERVICE_NAME); + } + + private boolean isAuthenticationConfig(Configuration config) { + String serviceValue = config.getString(ExtensionManagerKeys.service.getKeyName()); + return serviceValue != null && serviceValue.equalsIgnoreCase(AUTHN_SERVICE_NAME); + } + + /** + * Returns an unmodifiable list containing all the authentication profiles that have been previously loaded. + */ + public List<AuthenticationProfile> getProfiles() { + return new ArrayList<>(profiles.values()); + } + + /** + * Gets the authentication profile for the given name. + * + * @param name + * the name of the profile + * @return the requested profile or {@code null} if no such profile can be found + */ + public AuthenticationProfile getProfile(String name) { + return profiles.get(name); + } + + /** + * Register an authentication profile. + * + * @param name + * the name of the profile + * @param profile + * the profile to register + */ + public void registerProfile(String name, AuthenticationProfile profile) { + profiles.put(name, profile); + } + +} -- To view, visit http://gerrit.ovirt.org/24366 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If375fccea98544c64d9ec41cc9dbcb855bf02fb7 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