Search in sources :

Example 6 with Session

use of org.apache.wicket.Session in project webanno by webanno.

the class ApplicationPageBase method commonInit.

private void commonInit() {
    Properties settings = SettingsUtil.getSettings();
    // Override locale to be used by application
    String locale = settings.getProperty(SettingsUtil.CFG_LOCALE, "en");
    switch(locale) {
        case "auto":
            // Do nothing - locale is picked up from browser
            break;
        default:
            // Override the locale in the session
            getSession().setLocale(Locale.forLanguageTag(locale));
            break;
    }
    // Add menubar
    try {
        Class<? extends Component> menubarClass = getApplication().getMetaData(MENUBAR_CLASS);
        if (menubarClass == null) {
            menubarClass = MenuBar.class;
        }
        add(ConstructorUtils.invokeConstructor(menubarClass, "menubar"));
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e1) {
        throw new RuntimeException(e1);
    }
    feedbackPanel = new BootstrapFeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);
    feedbackPanel.setFilter((IFeedbackMessageFilter) aMessage -> {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String username = auth != null ? auth.getName() : "SYSTEM";
        if (aMessage.isFatal()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isError()) {
            LOG.error("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isWarning()) {
            LOG.warn("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isInfo()) {
            LOG.info("{}: {}", username, aMessage.getMessage());
        } else if (aMessage.isDebug()) {
            LOG.debug("{}: {}", username, aMessage.getMessage());
        }
        return true;
    });
    add(feedbackPanel);
    versionLabel = new Label("version", SettingsUtil.getVersionString());
    add(versionLabel);
    // set up warnings shown when using an embedded DB or some unsupported browser
    boolean isBrowserWarningVisible = isBrowserWarningVisible(settings);
    boolean isDatabaseWarningVisible = isDatabaseWarningVisible(settings);
    embeddedDbWarning = new Label("embeddedDbWarning", new ResourceModel("warning.database"));
    embeddedDbWarning.setVisible(isDatabaseWarningVisible);
    add(embeddedDbWarning);
    browserWarning = new Label("browserWarning", new ResourceModel("warning.browser"));
    browserWarning.setVisible(isBrowserWarningVisible);
    add(browserWarning);
    WebMarkupContainer warningsContainer = new WebMarkupContainer("warnings");
    warningsContainer.setVisible(isBrowserWarningVisible || isDatabaseWarningVisible);
    add(warningsContainer);
}
Also used : RuntimeConfigurationType(org.apache.wicket.RuntimeConfigurationType) SettingsUtil(de.tudarmstadt.ukp.clarin.webanno.support.SettingsUtil) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) LoggerFactory(org.slf4j.LoggerFactory) IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) StringUtils(org.apache.commons.lang3.StringUtils) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) DatabaseDriverService(de.tudarmstadt.ukp.clarin.webanno.support.db.DatabaseDriverService) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Locale(java.util.Locale) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) NoOpResourceCachingStrategy(org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Label(org.apache.wicket.markup.html.basic.Label) Properties(java.util.Properties) Logger(org.slf4j.Logger) Component(org.apache.wicket.Component) WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) WebSession(org.apache.wicket.protocol.http.WebSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Session(org.apache.wicket.Session) MetaDataKey(org.apache.wicket.MetaDataKey) ConstructorUtils(org.apache.commons.lang3.reflect.ConstructorUtils) WebPage(org.apache.wicket.markup.html.WebPage) ResourceModel(org.apache.wicket.model.ResourceModel) Authentication(org.springframework.security.core.Authentication) Label(org.apache.wicket.markup.html.basic.Label) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) Properties(java.util.Properties) BootstrapFeedbackPanel(de.tudarmstadt.ukp.clarin.webanno.support.bootstrap.BootstrapFeedbackPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Authentication(org.springframework.security.core.Authentication) ResourceModel(org.apache.wicket.model.ResourceModel)

Example 7 with Session

use of org.apache.wicket.Session in project wicket by apache.

the class KeyInSessionSunJceCryptFactory method newCrypt.

@Override
public ICrypt newCrypt() {
    Session session = Session.get();
    session.bind();
    // retrieve or generate encryption key from session
    String key = session.getMetaData(KEY);
    if (key == null) {
        // generate new key
        key = session.getId() + "." + UUID.randomUUID().toString();
        session.setMetaData(KEY, key);
    }
    // build the crypt based on session key
    ICrypt crypt = createCrypt();
    crypt.setKey(key);
    return crypt;
}
Also used : ICrypt(org.apache.wicket.util.crypt.ICrypt) Session(org.apache.wicket.Session)

Example 8 with Session

use of org.apache.wicket.Session in project wicket by apache.

the class SessionSizeModelTest method testToleranceOnProblematicSessions.

/**
 * @see <a href="https://issues.apache.org/jira/browse/WICKET-3355">WICKET-3355</a>
 */
@Test
public void testToleranceOnProblematicSessions() {
    new WicketTester(new MockApplication() {

        @Override
        public Session newSession(final Request request, final Response response) {
            return new TestSession(request);
        }
    });
    SessionSizeModel model = new SessionSizeModel();
    assertEquals(null, model.getObject());
}
Also used : Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) WicketTester(org.apache.wicket.util.tester.WicketTester) Session(org.apache.wicket.Session) WebSession(org.apache.wicket.protocol.http.WebSession) Test(org.junit.Test)

Example 9 with Session

use of org.apache.wicket.Session in project midpoint by Evolveum.

the class PageSelfDashboard method initLayout.

private void initLayout() {
    DashboardSearchPanel dashboardSearchPanel = new DashboardSearchPanel(ID_SEARCH_PANEL);
    List<String> searchPanelActions = Arrays.asList(AuthorizationConstants.AUTZ_UI_USERS_ALL_URL, AuthorizationConstants.AUTZ_UI_USERS_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_ALL_URL, AuthorizationConstants.AUTZ_UI_RESOURCES_URL, AuthorizationConstants.AUTZ_UI_TASKS_ALL_URL, AuthorizationConstants.AUTZ_UI_TASKS_URL);
    dashboardSearchPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.SEARCH);
            return WebComponentUtil.getElementVisibility(visibilityType, searchPanelActions);
        }
    });
    add(dashboardSearchPanel);
    LinksPanel linksPanel = new LinksPanel(ID_LINKS_PANEL, Model.ofList(loadLinksList()));
    linksPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.SHORTCUTS);
            return WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(linksPanel);
    // TODO is this correct? [med]
    application = getApplication();
    final Session session = Session.get();
    AsyncDashboardPanel<Object, List<CaseWorkItemType>> workItemsPanel = new AsyncDashboardPanel<>(ID_WORK_ITEMS_PANEL, createStringResource("PageSelfDashboard.workItems"), GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_ICON, GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<CaseWorkItemType>>> createCallable(Authentication auth, IModel callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public CallableResult<List<CaseWorkItemType>> callWithContextPrepared() {
                    // it is ignored anyway - FIXME
                    return new CallableResult<>(emptyList(), null);
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            CaseWorkItemsPanel workItemsPanel = new CaseWorkItemsPanel(markupId, CaseWorkItemsPanel.View.DASHBOARD) {

                private static final long serialVersionUID = 1L;

                @Override
                protected ObjectFilter getCaseWorkItemsFilter() {
                    return QueryUtils.filterForNotClosedStateAndAssignees(getPrismContext().queryFor(CaseWorkItemType.class), AuthUtil.getPrincipalUser(), OtherPrivilegesLimitationType.F_APPROVAL_WORK_ITEMS, getRelationRegistry()).desc(F_CREATE_TIMESTAMP).buildFilter();
                }
            };
            workItemsPanel.setOutputMarkupId(true);
            return workItemsPanel;
        }
    };
    workItemsPanel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_WORKITEMS);
            return getCaseManager().isEnabled() && WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(workItemsPanel);
    AsyncDashboardPanel<Object, List<CaseType>> myRequestsPanel = new AsyncDashboardPanel<>(ID_REQUESTS_PANEL, createStringResource("PageSelfDashboard.myRequests"), GuiStyleConstants.CLASS_SHADOW_ICON_REQUEST, GuiStyleConstants.CLASS_OBJECT_SERVICE_BOX_CSS_CLASSES, true) {

        private static final long serialVersionUID = 1L;

        @Override
        protected SecurityContextAwareCallable<CallableResult<List<CaseType>>> createCallable(Authentication auth, IModel callableParameterModel) {
            return new SecurityContextAwareCallable<>(getSecurityContextManager(), auth) {

                @Override
                public CallableResult<List<CaseType>> callWithContextPrepared() {
                    // it is ignored anyway - FIXME
                    return new CallableResult<>(emptyList(), null);
                }
            };
        }

        @Override
        protected Component getMainComponent(String markupId) {
            return new CasesTablePanel(markupId) {

                @Override
                protected ObjectFilter getCasesFilter() {
                    return QueryUtils.filterForMyRequests(getPrismContext().queryFor(CaseType.class), AuthUtil.getPrincipalUser().getOid()).desc(ItemPath.create(CaseType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP)).buildFilter();
                }

                @Override
                protected boolean isDashboard() {
                    return true;
                }

                @Override
                protected UserProfileStorage.TableId getTableId() {
                    return UserProfileStorage.TableId.PAGE_CASE_CHILD_CASES_TAB;
                }
            };
        }
    };
    myRequestsPanel.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            UserInterfaceElementVisibilityType visibilityType = getComponentVisibility(PredefinedDashboardWidgetId.MY_REQUESTS);
            return getCaseManager().isEnabled() && WebComponentUtil.getElementVisibility(visibilityType);
        }
    });
    add(myRequestsPanel);
    initMyAccounts(session);
    initAssignments();
}
Also used : IModel(org.apache.wicket.model.IModel) LinksPanel(com.evolveum.midpoint.web.page.self.component.LinksPanel) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) DashboardSearchPanel(com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel) CaseWorkItemsPanel(com.evolveum.midpoint.web.page.admin.cases.CaseWorkItemsPanel) AsyncDashboardPanel(com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) Authentication(org.springframework.security.core.Authentication) CasesTablePanel(com.evolveum.midpoint.web.page.admin.server.CasesTablePanel) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collections.emptyList(java.util.Collections.emptyList) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) CallableResult(com.evolveum.midpoint.web.component.util.CallableResult) AccountCallableResult(com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult) Session(org.apache.wicket.Session)

Example 10 with Session

use of org.apache.wicket.Session in project wicket by apache.

the class LocaleAwarePageParametersTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        protected void init() {
            super.init();
            mountPage("unaware", LocaleUnawarePageParametersPage.class);
            mount(new MountedMapper("aware", LocaleAwarePageParametersPage.class) {

                @Override
                protected Locale resolveLocale() {
                    return resolveUserLocale();
                }
            });
        }

        @Override
        public Session newSession(Request request, Response response) {
            final Session session = super.newSession(request, response);
            session.setLocale(Locale.GERMANY);
            return session;
        }
    };
}
Also used : Locale(java.util.Locale) Response(org.apache.wicket.request.Response) MockApplication(org.apache.wicket.mock.MockApplication) Request(org.apache.wicket.request.Request) Session(org.apache.wicket.Session)

Aggregations

Session (org.apache.wicket.Session)16 HttpSession (javax.servlet.http.HttpSession)4 Test (org.junit.Test)4 Locale (java.util.Locale)3 WebPage (org.apache.wicket.markup.html.WebPage)3 WebSession (org.apache.wicket.protocol.http.WebSession)3 Page (org.apache.wicket.Page)2 MockApplication (org.apache.wicket.mock.MockApplication)2 Request (org.apache.wicket.request.Request)2 Response (org.apache.wicket.request.Response)2 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)2 Authentication (org.springframework.security.core.Authentication)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)1 CallableResult (com.evolveum.midpoint.web.component.util.CallableResult)1 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)1 CaseWorkItemsPanel (com.evolveum.midpoint.web.page.admin.cases.CaseWorkItemsPanel)1 AsyncDashboardPanel (com.evolveum.midpoint.web.page.admin.home.component.AsyncDashboardPanel)1 AccountCallableResult (com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult)1 CasesTablePanel (com.evolveum.midpoint.web.page.admin.server.CasesTablePanel)1