Search in sources :

Example 1 with PageMounter

use of com.evolveum.midpoint.web.application.PageMounter in project midpoint by Evolveum.

the class TestPageMounter method testDescriptorLoader.

@Test(enabled = false)
public void testDescriptorLoader() {
    MidPointApplication midPointApplication = new MidPointApplication();
    ServletContext mockServletContext = new ServletContext() {

        @Override
        public int getEffectiveMajorVersion() {
            return 0;
        }

        @Override
        public int getEffectiveMinorVersion() {
            return 0;
        }

        @Override
        public boolean setInitParameter(String name, String value) {
            return false;
        }

        @Override
        public ServletRegistration.Dynamic addServlet(String servletName, String className) {
            return null;
        }

        @Override
        public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) {
            return null;
        }

        @Override
        public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) {
            return null;
        }

        @Override
        public ServletRegistration.Dynamic addJspFile(String s, String s1) {
            return null;
        }

        @Override
        public <T extends Servlet> T createServlet(Class<T> c) {
            return null;
        }

        @Override
        public ServletRegistration getServletRegistration(String servletName) {
            return null;
        }

        @Override
        public Map<String, ? extends ServletRegistration> getServletRegistrations() {
            return null;
        }

        @Override
        public FilterRegistration.Dynamic addFilter(String filterName, String className) {
            return null;
        }

        @Override
        public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) {
            return null;
        }

        @Override
        public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) {
            return null;
        }

        @Override
        public <T extends Filter> T createFilter(Class<T> c) {
            return null;
        }

        @Override
        public FilterRegistration getFilterRegistration(String filterName) {
            return null;
        }

        @Override
        public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
            return null;
        }

        @Override
        public SessionCookieConfig getSessionCookieConfig() {
            return null;
        }

        @Override
        public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) {
        }

        @Override
        public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
            return null;
        }

        @Override
        public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
            return null;
        }

        @Override
        public void addListener(String className) {
        }

        @Override
        public <T extends EventListener> void addListener(T t) {
        }

        @Override
        public void addListener(Class<? extends EventListener> listenerClass) {
        }

        @Override
        public <T extends EventListener> T createListener(Class<T> c) {
            return null;
        }

        @Override
        public JspConfigDescriptor getJspConfigDescriptor() {
            return null;
        }

        @Override
        public ClassLoader getClassLoader() {
            return null;
        }

        @Override
        public void declareRoles(String... roleNames) {
        }

        @Override
        public String getVirtualServerName() {
            return null;
        }

        @Override
        public int getSessionTimeout() {
            return 0;
        }

        @Override
        public void setSessionTimeout(int i) {
        }

        @Override
        public String getRequestCharacterEncoding() {
            return null;
        }

        @Override
        public void setRequestCharacterEncoding(String s) {
        }

        @Override
        public String getResponseCharacterEncoding() {
            return null;
        }

        @Override
        public void setResponseCharacterEncoding(String s) {
        }

        @Override
        public void setAttribute(String arg0, Object arg1) {
        }

        @Override
        public void removeAttribute(String arg0) {
        }

        @Override
        public void log(String msg, Throwable e) {
            logger.error("{}", msg, e);
        }

        @Override
        public void log(Exception e, String msg) {
            logger.error("{}", msg, e);
        }

        @Override
        public void log(String msg) {
            logger.trace("{}", msg);
        }

        @Override
        public Enumeration<Servlet> getServlets() {
            return null;
        }

        @Override
        public Enumeration<String> getServletNames() {
            return null;
        }

        @Override
        public String getServletContextName() {
            return "mock";
        }

        @Override
        public Servlet getServlet(String arg0) {
            return null;
        }

        @Override
        public String getServerInfo() {
            return null;
        }

        @Override
        public Set<String> getResourcePaths(String arg0) {
            return null;
        }

        @Override
        public InputStream getResourceAsStream(String name) {
            return this.getClass().getClassLoader().getResourceAsStream(name);
        }

        @Override
        public URL getResource(String name) {
            return this.getClass().getClassLoader().getResource(name);
        }

        @Override
        public RequestDispatcher getRequestDispatcher(String arg0) {
            return null;
        }

        @Override
        public String getRealPath(String arg0) {
            return null;
        }

        @Override
        public RequestDispatcher getNamedDispatcher(String arg0) {
            return null;
        }

        @Override
        public int getMinorVersion() {
            return 2;
        }

        @Override
        public String getMimeType(String arg0) {
            return null;
        }

        @Override
        public int getMajorVersion() {
            return 4;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return null;
        }

        @Override
        public String getInitParameter(String arg0) {
            return null;
        }

        @Override
        public String getContextPath() {
            return null;
        }

        @Override
        public ServletContext getContext(String arg0) {
            return this;
        }

        @Override
        public Enumeration<String> getAttributeNames() {
            return null;
        }

        @Override
        public Object getAttribute(String arg0) {
            return null;
        }
    };
    midPointApplication.setServletContext(mockServletContext);
    PageMounter pageMounter = new PageMounter();
    // TODO: this test does not really work. This needs to be cleaned up
    // to make it testable
    // WHEN
    pageMounter.loadData(midPointApplication);
    // THEN
    displayDumpable("initialized loader", pageMounter);
}
Also used : Set(java.util.Set) PageMounter(com.evolveum.midpoint.web.application.PageMounter) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) EventListener(java.util.EventListener) Test(org.testng.annotations.Test)

Example 2 with PageMounter

use of com.evolveum.midpoint.web.application.PageMounter in project midpoint by Evolveum.

the class MidPointApplication method init.

@Override
public void init() {
    super.init();
    getCspSettings().blocking().disabled();
    getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(MidPointApplication.class, // todo no jquery.js is found
    "../../../../../webjars/AdminLTE/2.4.18/bower_components/jquery/dist/jquery.min.js"));
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContext, true));
    systemConfigurationChangeDispatcher.registerListener(new DeploymentInformationChangeListener(this));
    SystemConfigurationType config = getSystemConfigurationIfAvailable();
    if (config != null) {
        deploymentInfo = config.getDeploymentInformation();
    }
    ResourceSettings resourceSettings = getResourceSettings();
    resourceSettings.setParentFolderPlaceholder("$-$");
    resourceSettings.setHeaderItemComparator(new PriorityFirstComparator(true));
    SecurePackageResourceGuard guard = (SecurePackageResourceGuard) resourceSettings.getPackageResourceGuard();
    guard.addPattern("+*.woff2");
    List<IStringResourceLoader> resourceLoaders = resourceSettings.getStringResourceLoaders();
    resourceLoaders.add(0, new MidPointStringResourceLoader(localizationService));
    IResourceStreamLocator locator = new CachingResourceStreamLocator(new MidPointResourceStreamLocator(resourceSettings.getResourceFinders()));
    resourceSettings.setResourceStreamLocator(locator);
    resourceSettings.setThrowExceptionOnMissingResource(false);
    getMarkupSettings().setStripWicketTags(true);
    getMarkupSettings().setStripComments(true);
    if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) {
        getDebugSettings().setAjaxDebugModeEnabled(true);
        getDebugSettings().setDevelopmentUtilitiesEnabled(true);
        initializeDevelopmentSerializers();
        mount(new MountedMapper("/inspector", InspectorPage.class, new PageParametersEncoder()));
        mount(new MountedMapper("/liveSession", LiveSessionsPage.class, new PageParametersEncoder()));
        mount(new MountedMapper("/pageStore", PageStorePage.class, new PageParametersEncoder()));
    }
    // pretty url for resources (e.g. images)
    mountFiles(ImgResources.BASE_PATH, ImgResources.class);
    // exception handling an error pages
    ApplicationSettings appSettings = getApplicationSettings();
    appSettings.setAccessDeniedPage(PageError401.class);
    appSettings.setInternalErrorPage(PageError.class);
    appSettings.setPageExpiredErrorPage(PageError.class);
    mount(new MountedMapper(MOUNT_INTERNAL_SERVER_ERROR, PageError.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_UNAUTHORIZED_ERROR, PageError401.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_FORBIDEN_ERROR, PageError403.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_NOT_FOUND_ERROR, PageError404.class, new PageParametersEncoder()));
    mount(new MountedMapper(MOUNT_GONE_ERROR, PageError410.class, new PageParametersEncoder()));
    getRequestCycleListeners().add(new LoggingRequestCycleListener(this));
    getAjaxRequestTargetListeners().add(new AjaxRequestTarget.IListener() {

        @Override
        public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
            // check whether behavior will use POST method, if not then don't put CSRF token there
            if (!isPostMethodTypeBehavior(behavior, attributes)) {
                return;
            }
            CsrfToken csrfToken = SecurityUtils.getCsrfToken();
            if (csrfToken == null) {
                return;
            }
            String parameterName = csrfToken.getParameterName();
            String value = csrfToken.getToken();
            attributes.getExtraParameters().put(parameterName, value);
        }
    });
    getSessionListeners().add((ISessionListener) asyncWebProcessManager);
    // descriptor loader, used for customization
    new PageMounter().loadData(this);
    descriptorLoader.loadData();
    if (applicationContext != null) {
        Map<String, MidPointApplicationConfiguration> map = applicationContext.getBeansOfType(MidPointApplicationConfiguration.class);
        if (map != null) {
            map.forEach((key, value) -> value.init(this));
        }
    }
    // for schrodinger selenide library
    initializeSchrodinger();
    ServletContext servletContext = getServletContext();
    if (servletContext != null) {
        taskManager.setWebContextPath(servletContext.getContextPath());
    }
}
Also used : CachingResourceStreamLocator(org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator) MountedMapper(org.apache.wicket.core.request.mapper.MountedMapper) MidPointResourceStreamLocator(com.evolveum.midpoint.web.util.MidPointResourceStreamLocator) IResourceStreamLocator(org.apache.wicket.core.util.resource.locator.IResourceStreamLocator) InspectorPage(org.apache.wicket.devutils.inspector.InspectorPage) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PriorityFirstComparator(org.apache.wicket.markup.head.PriorityFirstComparator) MidPointStringResourceLoader(com.evolveum.midpoint.web.util.MidPointStringResourceLoader) AbstractDefaultAjaxBehavior(org.apache.wicket.ajax.AbstractDefaultAjaxBehavior) PackageResourceReference(org.apache.wicket.request.resource.PackageResourceReference) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) ServletContext(javax.servlet.ServletContext) LiveSessionsPage(org.apache.wicket.devutils.inspector.LiveSessionsPage) MidPointApplicationConfiguration(com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration) PageStorePage(org.apache.wicket.devutils.pagestore.PageStorePage) CsrfToken(org.springframework.security.web.csrf.CsrfToken) PageMounter(com.evolveum.midpoint.web.application.PageMounter) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) ApplicationSettings(org.apache.wicket.settings.ApplicationSettings) SecurePackageResourceGuard(org.apache.wicket.markup.html.SecurePackageResourceGuard) ResourceSettings(org.apache.wicket.settings.ResourceSettings) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) PageParametersEncoder(org.apache.wicket.request.mapper.parameter.PageParametersEncoder) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector)

Aggregations

PageMounter (com.evolveum.midpoint.web.application.PageMounter)2 MidPointApplicationConfiguration (com.evolveum.midpoint.gui.api.util.MidPointApplicationConfiguration)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)1 MidPointResourceStreamLocator (com.evolveum.midpoint.web.util.MidPointResourceStreamLocator)1 MidPointStringResourceLoader (com.evolveum.midpoint.web.util.MidPointStringResourceLoader)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 EventListener (java.util.EventListener)1 Set (java.util.Set)1 ServletContext (javax.servlet.ServletContext)1 AbstractDefaultAjaxBehavior (org.apache.wicket.ajax.AbstractDefaultAjaxBehavior)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)1 MountedMapper (org.apache.wicket.core.request.mapper.MountedMapper)1 IResourceStreamLocator (org.apache.wicket.core.util.resource.locator.IResourceStreamLocator)1 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)1 InspectorPage (org.apache.wicket.devutils.inspector.InspectorPage)1 LiveSessionsPage (org.apache.wicket.devutils.inspector.LiveSessionsPage)1 PageStorePage (org.apache.wicket.devutils.pagestore.PageStorePage)1 PriorityFirstComparator (org.apache.wicket.markup.head.PriorityFirstComparator)1