Search in sources :

Example 1 with GroupCustomCssResourceReference

use of org.apache.openmeetings.web.room.GroupCustomCssResourceReference in project openmeetings by apache.

the class Application method init.

@Override
protected void init() {
    setWicketApplicationName(super.getName());
    getSecuritySettings().setAuthenticationStrategy(new OmAuthenticationStrategy(rememberMeKey, rememberMeSalt));
    getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
    getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
    getExceptionSettings().setUnexpectedExceptionDisplay(ExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);
    getComponentInstantiationListeners().add(new SpringComponentInjector(this, ctx, true));
    Config cfg = new XmlConfigBuilder().build();
    cfg.setClassLoader(getClass().getClassLoader());
    hazelcast = Hazelcast.getOrCreateHazelcastInstance(cfg);
    serverId = hazelcast.getName();
    hazelcast.getCluster().getMembers().forEach(m -> cm.serverAdded(m.getAttribute(NAME_ATTR_KEY), m.getAttribute(SERVER_URL_ATTR_KEY)));
    hazelWsTopic = hazelcast.getTopic("default");
    hazelWsTopic.addMessageListener(msg -> {
        String mServerId = msg.getPublishingMember().getAttribute(NAME_ATTR_KEY);
        if (mServerId.equals(serverId)) {
            return;
        }
        IClusterWsMessage wsMsg = msg.getMessageObject();
        if (WbWebSocketHelper.send(wsMsg)) {
            return;
        }
        if (ChatWebSocketHelper.send(msg.getMessageObject())) {
            return;
        }
        WebSocketHelper.send(msg.getMessageObject());
    });
    hazelcast.getCluster().addMembershipListener(new MembershipListener() {

        @Override
        public void memberRemoved(MembershipEvent evt) {
            // server down, need to remove all online clients, process persistent addresses
            String serverId = evt.getMember().getAttribute(NAME_ATTR_KEY);
            cm.serverRemoved(serverId);
            updateJpaAddresses();
        }

        @Override
        public void memberAdded(MembershipEvent evt) {
            // no-op
            // server added, need to process persistent addresses
            updateJpaAddresses();
            // check for duplicate instance-names
            Set<String> names = new HashSet<>();
            for (Member m : evt.getMembers()) {
                if (evt.getMember().getUuid().equals(m.getUuid())) {
                    continue;
                }
                String serverId = m.getAttribute(NAME_ATTR_KEY);
                names.add(serverId);
            }
            String newServerId = evt.getMember().getAttribute(NAME_ATTR_KEY);
            log.warn("Name added: {}", newServerId);
            cm.serverAdded(newServerId, evt.getMember().getAttribute(SERVER_URL_ATTR_KEY));
            if (names.contains(newServerId)) {
                log.warn("Duplicate cluster instance with name {} found {}", newServerId, evt.getMember());
            }
        }
    });
    setPageManagerProvider(new DefaultPageManagerProvider(this) {

        @Override
        protected IPageStore newAsynchronousStore(IPageStore pageStore) {
            return new SerializingPageStore(new HazelcastDataStore(getName(), hazelcast), getFrameworkSettings().getSerializer());
        }
    });
    // Add custom resource loader at the beginning, so it will be checked first in the
    // chain of Resource Loaders, if not found it will search in Wicket's internal
    // Resource Loader for a the property key
    getResourceSettings().getStringResourceLoaders().add(0, new LabelResourceLoader());
    getRequestCycleListeners().add(new WebSocketAwareResourceIsolationRequestCycleListener() {

        @Override
        public void onBeginRequest(RequestCycle cycle) {
            String wsUrl = getWsUrl(cycle.getRequest().getUrl());
            if (wsUrl != null && !wsUrls.contains(wsUrl)) {
                wsUrls.add(wsUrl);
                cfgDao.updateCsp();
            }
        }

        @Override
        public void onEndRequest(RequestCycle cycle) {
            Response resp = cycle.getResponse();
            if (resp instanceof WebResponse) {
                WebResponse wresp = (WebResponse) resp;
                if (wresp.isHeaderSupported()) {
                    wresp.setHeader("X-XSS-Protection", "1; mode=block");
                    wresp.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
                    wresp.setHeader("X-Content-Type-Options", "nosniff");
                }
            }
        }
    });
    final WebSocketContainer sc = (WebSocketContainer) getServletContext().getAttribute(SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
    if (sc != null) {
        // should be enough, should it be configurable?
        sc.setDefaultMaxSessionIdleTimeout(60 * 1000L);
    }
    getHeaderResponseDecorators().add(FilteringHeaderResponse::new);
    super.init();
    final IBootstrapSettings settings = new BootstrapSettings();
    Bootstrap.builder().withBootstrapSettings(settings).install(this);
    WysiwygLibrarySettings.get().setBootstrapCssReference(null);
    WysiwygLibrarySettings.get().setBootstrapDropDownJavaScriptReference(null);
    // register some widgets
    final DashboardContext dashboardContext = getDashboardContext();
    dashboardContext.setDashboardPersister(new UserDashboardPersister());
    WidgetRegistry widgetRegistry = dashboardContext.getWidgetRegistry();
    widgetRegistry.registerWidget(new MyRoomsWidgetDescriptor());
    widgetRegistry.registerWidget(new RecentRoomsWidgetDescriptor());
    widgetRegistry.registerWidget(new WelcomeWidgetDescriptor());
    widgetRegistry.registerWidget(new StartWidgetDescriptor());
    widgetRegistry.registerWidget(new RssWidgetDescriptor());
    widgetRegistry.registerWidget(new AdminWidgetDescriptor());
    DashboardSettings dashboardSettings = DashboardSettings.get();
    dashboardSettings.setIncludeJQueryUI(false);
    getRootRequestMapperAsCompound().add(new NoVersionMapper(getHomePage()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(NOTINIT_MAPPING, NotInitedPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("denied", AccessDeniedPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(HASH_MAPPING, HashPage.class));
    getRootRequestMapperAsCompound().add(new NoVersionMapper(SIGNIN_MAPPING, getSignInPageClass()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("oauth/${oauthid}", getSignInPageClass()));
    getRootRequestMapperAsCompound().add(new NoVersionMapper("privacy", PrivacyPage.class));
    mountPage("install", InstallWizardPage.class);
    mountPage("activate", ActivatePage.class);
    mountPage("reset", ResetPage.class);
    mountPage("error", InternalErrorPage.class);
    mountResource("/recordings/mp4/${id}", new Mp4RecordingResourceReference());
    // should be in sync with VideoPlayer
    mountResource("/recordings/png/${id}", new PngRecordingResourceReference());
    mountResource("/room/file/${id}", new RoomResourceReference());
    mountResource("/room/preview/${id}", new RoomPreviewResourceReference());
    mountResource("/room/file/upload", new RoomFileUploadResourceReference());
    mountResource("/admin/backup/upload", new BackupUploadResourceReference());
    mountResource("/profile/${id}", new ProfileImageResourceReference());
    mountResource("/group/${id}", new GroupLogoResourceReference());
    mountResource("/group/customcss/${id}", new GroupCustomCssResourceReference());
    mountResource("/ping", new PingResourceReference());
    log.debug("Application::init");
    try {
        if (OmFileHelper.getOmHome() == null) {
            OmFileHelper.setOmHome(new File(getServletContext().getRealPath("/")));
        }
        LabelDao.initLanguageMap();
        log.debug("webAppPath : {}", OmFileHelper.getOmHome());
        // Init all global config properties
        cfgDao.reinit();
        wbManager.init();
        cm.init();
        // Init properties
        updateJpaAddresses();
        setExtProcessTtl(cfgDao.getInt(CONFIG_EXT_PROCESS_TTL, getExtProcessTtl()));
        Version.logOMStarted();
        // we are starting so all processing recordings are now errors
        recordingDao.resetProcessingStatus();
        userManager.initHttpClient();
        setInitComplete(true);
        CompletableFuture.runAsync(() -> {
            ThreadContext.setApplication(Application.this);
            ApplicationHelper.ensureRequestCycle(Application.this);
            sipManager.setUserPicture(u -> ProfileImageResourceReference.getUrl(RequestCycle.get(), u));
        });
    } catch (Exception err) {
        log.error("[appStart]", err);
    }
}
Also used : DashboardContext(org.wicketstuff.dashboard.web.DashboardContext) DashboardSettings(org.wicketstuff.dashboard.web.DashboardSettings) RecentRoomsWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.RecentRoomsWidgetDescriptor) FilteringHeaderResponse(org.apache.wicket.markup.head.filter.FilteringHeaderResponse) MyRoomsWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.MyRoomsWidgetDescriptor) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) BootstrapSettings(de.agilecoders.wicket.core.settings.BootstrapSettings) PrivacyPage(org.apache.openmeetings.web.pages.PrivacyPage) PingResourceReference(org.apache.openmeetings.web.common.PingResourceReference) Member(com.hazelcast.cluster.Member) MeetingMember(org.apache.openmeetings.db.entity.calendar.MeetingMember) RoomPreviewResourceReference(org.apache.openmeetings.web.room.RoomPreviewResourceReference) IPageStore(org.apache.wicket.pageStore.IPageStore) WelcomeWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.WelcomeWidgetDescriptor) Mp4RecordingResourceReference(org.apache.openmeetings.web.user.record.Mp4RecordingResourceReference) RoomResourceReference(org.apache.openmeetings.web.room.RoomResourceReference) SerializingPageStore(org.apache.wicket.pageStore.SerializingPageStore) RoomFileUploadResourceReference(org.apache.openmeetings.web.room.sidebar.RoomFileUploadResourceReference) GroupLogoResourceReference(org.apache.openmeetings.web.util.GroupLogoResourceReference) File(java.io.File) UserDashboardPersister(org.apache.openmeetings.web.util.UserDashboardPersister) ProfileImageResourceReference(org.apache.openmeetings.web.util.ProfileImageResourceReference) GroupCustomCssResourceReference(org.apache.openmeetings.web.room.GroupCustomCssResourceReference) Set(java.util.Set) HashSet(java.util.HashSet) Config(com.hazelcast.config.Config) MembershipEvent(com.hazelcast.cluster.MembershipEvent) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) BackupUploadResourceReference(org.apache.openmeetings.web.admin.backup.BackupUploadResourceReference) WebSocketAwareResourceIsolationRequestCycleListener(org.apache.wicket.protocol.ws.WebSocketAwareResourceIsolationRequestCycleListener) HazelcastDataStore(org.wicketstuff.datastores.hazelcast.HazelcastDataStore) XmlConfigBuilder(com.hazelcast.config.XmlConfigBuilder) WebResponse(org.apache.wicket.request.http.WebResponse) WebSocketContainer(javax.websocket.WebSocketContainer) AdminWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.admin.AdminWidgetDescriptor) RssWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.RssWidgetDescriptor) NotInitedPage(org.apache.openmeetings.web.pages.NotInitedPage) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) UnknownHostException(java.net.UnknownHostException) WebResponse(org.apache.wicket.request.http.WebResponse) Response(org.apache.wicket.request.Response) FilteringHeaderResponse(org.apache.wicket.markup.head.filter.FilteringHeaderResponse) HashPage(org.apache.openmeetings.web.pages.HashPage) StartWidgetDescriptor(org.apache.openmeetings.web.user.dashboard.StartWidgetDescriptor) IBootstrapSettings(de.agilecoders.wicket.core.settings.IBootstrapSettings) WidgetRegistry(org.wicketstuff.dashboard.WidgetRegistry) IClusterWsMessage(org.apache.openmeetings.util.ws.IClusterWsMessage) AccessDeniedPage(org.apache.openmeetings.web.pages.AccessDeniedPage) SpringComponentInjector(org.apache.wicket.spring.injection.annot.SpringComponentInjector) MembershipListener(com.hazelcast.cluster.MembershipListener) PngRecordingResourceReference(org.apache.openmeetings.web.user.record.PngRecordingResourceReference) DefaultPageManagerProvider(org.apache.wicket.DefaultPageManagerProvider)

Aggregations

Member (com.hazelcast.cluster.Member)1 MembershipEvent (com.hazelcast.cluster.MembershipEvent)1 MembershipListener (com.hazelcast.cluster.MembershipListener)1 Config (com.hazelcast.config.Config)1 XmlConfigBuilder (com.hazelcast.config.XmlConfigBuilder)1 BootstrapSettings (de.agilecoders.wicket.core.settings.BootstrapSettings)1 IBootstrapSettings (de.agilecoders.wicket.core.settings.IBootstrapSettings)1 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 WebSocketContainer (javax.websocket.WebSocketContainer)1 MeetingMember (org.apache.openmeetings.db.entity.calendar.MeetingMember)1 IClusterWsMessage (org.apache.openmeetings.util.ws.IClusterWsMessage)1 BackupUploadResourceReference (org.apache.openmeetings.web.admin.backup.BackupUploadResourceReference)1 PingResourceReference (org.apache.openmeetings.web.common.PingResourceReference)1 AccessDeniedPage (org.apache.openmeetings.web.pages.AccessDeniedPage)1 HashPage (org.apache.openmeetings.web.pages.HashPage)1 NotInitedPage (org.apache.openmeetings.web.pages.NotInitedPage)1 PrivacyPage (org.apache.openmeetings.web.pages.PrivacyPage)1