Search in sources :

Example 6 with ExtensionProxy

use of org.ovirt.engine.core.extensions.mgr.ExtensionProxy in project ovirt-engine by oVirt.

the class EngineExtensionsManager method engineInitialize.

public void engineInitialize() {
    for (File directory : EngineLocalConfig.getInstance().getExtensionsDirectories()) {
        if (!directory.exists()) {
            log.warn("The directory '{}' cotaning configuration files does not exist.", directory.getAbsolutePath());
        } else {
            // The order of the files inside the directory is relevant, as the objects are created in
            // the same order
            // that
            // the files are processed, so it is better to sort them so that objects will always be
            // created in the
            // same
            // order regardless of how the filesystem decides to store the entries of the directory:
            File[] files = directory.listFiles();
            if (files != null) {
                sort(files);
                for (File file : files) {
                    if (file.getName().endsWith(".properties")) {
                        try {
                            load(file);
                        } catch (Exception ex) {
                            log.error("Could not load extension based on configuration file '{}'. Please check the configuration file is valid. Exception message is: {}", file.getAbsolutePath(), ex.getMessage());
                            log.debug("", ex);
                        }
                    }
                }
            }
        }
    }
    Pattern pattern = Pattern.compile(EngineLocalConfig.getInstance().getProperty(ENGINE_EXTENSIONS_IGNORED));
    for (ExtensionProxy extension : getLoadedExtensions()) {
        if (EngineLocalConfig.getInstance().getBoolean(ENGINE_EXTENSION_ENABLED + normalizeName(extension.getContext().get(Base.ContextKeys.INSTANCE_NAME)), Boolean.parseBoolean(extension.getContext().<Properties>get(Base.ContextKeys.CONFIGURATION).getProperty(Base.ConfigKeys.ENABLED, "true"))) && extension.getContext().<Collection<String>>get(Base.ContextKeys.PROVIDES).stream().noneMatch(p -> pattern.matcher(p).matches())) {
            try {
                initialize(extension.getContext().get(Base.ContextKeys.INSTANCE_NAME));
            } catch (Exception ex) {
                log.error("Could not initialize extension '{}'. Exception message is: {}", extension.getContext().<String>get(Base.ContextKeys.INSTANCE_NAME), ex.getMessage());
                log.debug("", ex);
            }
        }
    }
    dump();
}
Also used : Properties(java.util.Properties) Logger(org.slf4j.Logger) ExtensionsManager(org.ovirt.engine.core.extensions.mgr.ExtensionsManager) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy) Base(org.ovirt.engine.api.extensions.Base) Pattern(java.util.regex.Pattern) EngineLocalConfig(org.ovirt.engine.core.utils.EngineLocalConfig) Arrays.sort(java.util.Arrays.sort) File(java.io.File) Pattern(java.util.regex.Pattern) ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy) Properties(java.util.Properties) File(java.io.File)

Example 7 with ExtensionProxy

use of org.ovirt.engine.core.extensions.mgr.ExtensionProxy in project ovirt-engine by oVirt.

the class LoggerHandler method publish.

@Override
public void publish(LogRecord record) {
    ExtMap publishInputMap = new ExtMap().mput(Base.InvokeKeys.COMMAND, Logger.InvokeCommands.PUBLISH).mput(Logger.InvokeKeys.LOG_RECORD, record);
    ExtMap publishOutputMap = new ExtMap();
    for (ExtensionProxy extension : extensions) {
        try {
            extension.invoke(publishInputMap, publishOutputMap);
        } catch (Exception ex) {
        // ignore, logging this exception will result in infinite loop
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy)

Example 8 with ExtensionProxy

use of org.ovirt.engine.core.extensions.mgr.ExtensionProxy in project ovirt-engine by oVirt.

the class SsoExtensionsManager method initialize.

private void initialize() {
    String path = localConfig.getExtensionsPath();
    List<File> extensionsDirectories = new ArrayList<>();
    if (path != null) {
        for (String currentPath : path.split(":")) {
            if (StringUtils.isNotBlank(currentPath)) {
                extensionsDirectories.add(new File(currentPath));
            }
        }
    }
    for (File directory : extensionsDirectories) {
        if (!directory.exists()) {
            log.warn("The directory '{}' cotaning configuration files does not exist.", directory.getAbsolutePath());
        } else {
            // The order of the files inside the directory is relevant, as the objects are created in
            // the same order
            // that
            // the files are processed, so it is better to sort them so that objects will always be
            // created in the
            // same
            // order regardless of how the filesystem decides to store the entries of the directory:
            File[] files = directory.listFiles();
            if (files != null) {
                sort(files);
                for (File file : files) {
                    if (file.getName().endsWith(".properties")) {
                        try {
                            load(file);
                        } catch (Exception ex) {
                            log.error("Could not load extension based on configuration file '{}'. " + "Please check the configuration file is valid. Exception message is: {}", file.getAbsolutePath(), ex.getMessage());
                            log.debug("Exception", ex);
                        }
                    }
                }
            }
        }
    }
    for (ExtensionProxy extension : getLoadedExtensions()) {
        if (localConfig.getBoolean(ENGINE_EXTENSION_ENABLED + normalizeName(extension.getContext().get(Base.ContextKeys.INSTANCE_NAME)), Boolean.parseBoolean(extension.getContext().<Properties>get(Base.ContextKeys.CONFIGURATION).getProperty(Base.ConfigKeys.ENABLED, "true")))) {
            try {
                initialize(extension.getContext().get(Base.ContextKeys.INSTANCE_NAME));
            } catch (Exception ex) {
                log.error("Could not initialize extension '{}'. Exception message is: {}", extension.getContext().<String>get(Base.ContextKeys.INSTANCE_NAME), ex.getMessage());
                log.debug("Exception", ex);
            }
        }
    }
    dump();
}
Also used : ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy) ArrayList(java.util.ArrayList) File(java.io.File)

Example 9 with ExtensionProxy

use of org.ovirt.engine.core.extensions.mgr.ExtensionProxy in project ovirt-engine by oVirt.

the class TokenCleanupUtility method invokeAuthnLogout.

private static void invokeAuthnLogout(SsoContext ssoContext, SsoSession ssoSession) throws Exception {
    String profileName = ssoSession.getProfile();
    String principalName = ssoSession.getUserId();
    ExtMap authRecord = null;
    ExtensionProxy authn = null;
    try {
        authRecord = ssoSession.getAuthRecord();
        if (StringUtils.isNotEmpty(profileName) && StringUtils.isNotEmpty(principalName)) {
            for (ExtensionProxy authnExtension : ssoContext.getSsoExtensionsManager().getExtensionsByService(Authn.class.getName())) {
                Properties config = authnExtension.getContext().get(Base.ContextKeys.CONFIGURATION);
                if (profileName.equals(config.getProperty(Authn.ConfigKeys.PROFILE_NAME))) {
                    authn = authnExtension;
                    break;
                }
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException(String.format("Unable to invalidate sessions for token: %s", ex.getMessage()));
    } finally {
        if (authn != null && authRecord != null && (authn.getContext().<Long>get(Authn.ContextKeys.CAPABILITIES) & Authn.Capabilities.LOGOUT) != 0) {
            authn.invoke(new ExtMap().mput(Base.InvokeKeys.COMMAND, Authn.InvokeCommands.LOGOUT).mput(Authn.InvokeKeys.AUTH_RECORD, authRecord));
        }
    }
}
Also used : ExtMap(org.ovirt.engine.api.extensions.ExtMap) ExtensionProxy(org.ovirt.engine.core.extensions.mgr.ExtensionProxy) Authn(org.ovirt.engine.api.extensions.aaa.Authn) Properties(java.util.Properties)

Aggregations

ExtensionProxy (org.ovirt.engine.core.extensions.mgr.ExtensionProxy)9 HashMap (java.util.HashMap)3 ExtMap (org.ovirt.engine.api.extensions.ExtMap)3 Authn (org.ovirt.engine.api.extensions.aaa.Authn)3 File (java.io.File)2 Properties (java.util.Properties)2 Acct (org.ovirt.engine.api.extensions.aaa.Acct)2 ConfigurationException (org.ovirt.engine.core.extensions.mgr.ConfigurationException)2 ArrayList (java.util.ArrayList)1 Arrays.sort (java.util.Arrays.sort)1 Collection (java.util.Collection)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1 Base (org.ovirt.engine.api.extensions.Base)1 ExtensionsManager (org.ovirt.engine.core.extensions.mgr.ExtensionsManager)1 EngineLocalConfig (org.ovirt.engine.core.utils.EngineLocalConfig)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1