/** @see org.apache.wicket.Application#init() */
  @Override
  public void init() {
    super.init();

    if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) {
      getDebugSettings().setAjaxDebugModeEnabled(true);
      getDebugSettings().setDevelopmentUtilitiesEnabled(true);
    }
    // add your configuration here
    // TODO - create profilers filesystem
  }
 /** Sets the application configurations. */
 protected void onApplicationConfigurations() {
   // set configuration before the application configuration...
   onBeforeApplicationConfigurations();
   // set global configurations for both development and deployment mode...
   onGlobalSettings();
   // set configuration for development...
   if (RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType())) {
     onDevelopmentModeSettings();
   }
   // set configuration for deployment...
   if (RuntimeConfigurationType.DEPLOYMENT.equals(this.getConfigurationType())) {
     onDeploymentModeSettings();
   }
 }
  @Override
  public void init() {
    super.init();

    getFrameworkSettings().setSerializer(new Fast2WicketSerializer());

    getJavaScriptLibrarySettings()
        .setJQueryReference(
            new PackageResourceReference(
                MidPointApplication.class,
                "../../../../../webjars/adminlte/2.3.0/plugins/jQuery/jQuery-2.1.4.min.js"));

    GuiComponents.init();

    getComponentInstantiationListeners().add(new SpringComponentInjector(this));

    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 Utf8BundleStringResourceLoader("localization/Midpoint"));
    resourceLoaders.add(
        1,
        new Utf8BundleStringResourceLoader(
            SchemaConstants.SCHEMA_LOCALIZATION_PROPERTIES_RESOURCE_BASE_PATH));

    resourceSettings.setThrowExceptionOnMissingResource(false);
    getMarkupSettings().setStripWicketTags(true);
    //        getMarkupSettings().setDefaultBeforeDisabledLink("");
    //        getMarkupSettings().setDefaultAfterDisabledLink("");

    if (RuntimeConfigurationType.DEVELOPMENT.equals(getConfigurationType())) {
      getDebugSettings().setAjaxDebugModeEnabled(true);
      getDebugSettings().setDevelopmentUtilitiesEnabled(true);
    }

    // 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("/error", PageError.class, MidPointPageParametersEncoder.ENCODER));
    mount(
        new MountedMapper("/error/401", PageError401.class, MidPointPageParametersEncoder.ENCODER));
    mount(
        new MountedMapper("/error/403", PageError403.class, MidPointPageParametersEncoder.ENCODER));
    mount(
        new MountedMapper("/error/404", PageError404.class, MidPointPageParametersEncoder.ENCODER));
    mount(
        new MountedMapper("/error/410", PageError410.class, MidPointPageParametersEncoder.ENCODER));

    getRequestCycleListeners().add(new LoggingRequestCycleListener(this));

    // descriptor loader, used for customization
    new DescriptorLoader().loadData(this);
  }
示例#4
0
  @SuppressWarnings("serial")
  public GeoServerBasePage() {
    // lookup for a pluggable favicon
    PackageResourceReference faviconReference = null;
    List<HeaderContribution> cssContribs =
        getGeoServerApplication().getBeansOfType(HeaderContribution.class);
    for (HeaderContribution csscontrib : cssContribs) {
      try {
        if (csscontrib.appliesTo(this)) {
          PackageResourceReference ref = csscontrib.getFavicon();
          if (ref != null) {
            faviconReference = ref;
          }
        }
      } catch (Throwable t) {
        LOGGER.log(Level.WARNING, "Problem adding header contribution", t);
      }
    }

    // favicon
    if (faviconReference == null) {
      faviconReference = new PackageResourceReference(GeoServerBasePage.class, "favicon.ico");
    }
    String faviconUrl = RequestCycle.get().urlFor(faviconReference, null).toString();
    add(new ExternalLink("faviconLink", faviconUrl, null));

    // page title
    add(
        new Label(
            "pageTitle",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getPageTitle();
              }
            }));

    // login form
    WebMarkupContainer loginForm =
        new WebMarkupContainer("loginform") {
          protected void onComponentTag(org.apache.wicket.markup.ComponentTag tag) {
            String path = getRequest().getUrl().getPath();
            StringBuilder loginPath = new StringBuilder();
            if (path.isEmpty()) {
              // home page
              loginPath.append("../j_spring_security_check");
            } else {
              // boomarkable page of sorts
              String[] pathElements = path.split("/");
              for (String pathElement : pathElements) {
                if (!pathElement.isEmpty()) {
                  loginPath.append("../");
                }
              }
              loginPath.append("j_spring_security_check");
            }
            tag.put("action", loginPath);
          };
        };
    add(loginForm);
    final Authentication user = GeoServerSession.get().getAuthentication();
    final boolean anonymous = user == null || user instanceof AnonymousAuthenticationToken;
    loginForm.setVisible(anonymous);

    WebMarkupContainer logoutForm = new WebMarkupContainer("logoutform");
    logoutForm.setVisible(!anonymous);

    add(logoutForm);
    logoutForm.add(new Label("username", anonymous ? "Nobody" : user.getName()));

    // home page link
    add(
        new BookmarkablePageLink("home", GeoServerHomePage.class)
            .add(new Label("label", new StringResourceModel("home", (Component) null, null))));

    // dev buttons
    DeveloperToolbar devToolbar = new DeveloperToolbar("devButtons");
    add(devToolbar);
    devToolbar.setVisible(
        RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType()));

    final Map<Category, List<MenuPageInfo>> links =
        splitByCategory(filterByAuth(getGeoServerApplication().getBeansOfType(MenuPageInfo.class)));

    List<MenuPageInfo> standalone =
        links.containsKey(null) ? links.get(null) : new ArrayList<MenuPageInfo>();
    links.remove(null);

    List<Category> categories = new ArrayList<>(links.keySet());
    Collections.sort(categories);

    add(
        new ListView<Category>("category", categories) {
          public void populateItem(ListItem<Category> item) {
            Category category = item.getModelObject();
            item.add(
                new Label(
                    "category.header",
                    new StringResourceModel(category.getNameKey(), (Component) null, null)));
            item.add(
                new ListView<MenuPageInfo>("category.links", links.get(category)) {
                  public void populateItem(ListItem<MenuPageInfo> item) {
                    MenuPageInfo info = item.getModelObject();
                    BookmarkablePageLink<Page> link =
                        new BookmarkablePageLink<>("link", info.getComponentClass());
                    link.add(
                        AttributeModifier.replace(
                            "title",
                            new StringResourceModel(
                                info.getDescriptionKey(), (Component) null, null)));
                    link.add(
                        new Label(
                            "link.label",
                            new StringResourceModel(info.getTitleKey(), (Component) null, null)));
                    Image image;
                    if (info.getIcon() != null) {
                      image =
                          new Image(
                              "link.icon",
                              new PackageResourceReference(
                                  info.getComponentClass(), info.getIcon()));
                    } else {
                      image =
                          new Image(
                              "link.icon",
                              new PackageResourceReference(
                                  GeoServerBasePage.class, "img/icons/silk/wrench.png"));
                    }
                    image.add(
                        AttributeModifier.replace(
                            "alt", new ParamResourceModel(info.getTitleKey(), null)));
                    link.add(image);
                    item.add(link);
                  }
                });
          }
        });

    add(
        new ListView<MenuPageInfo>("standalone", standalone) {
          public void populateItem(ListItem<MenuPageInfo> item) {
            MenuPageInfo info = item.getModelObject();
            BookmarkablePageLink<Page> link =
                new BookmarkablePageLink<>("link", info.getComponentClass());
            link.add(
                AttributeModifier.replace(
                    "title",
                    new StringResourceModel(info.getDescriptionKey(), (Component) null, null)));
            link.add(
                new Label(
                    "link.label",
                    new StringResourceModel(info.getTitleKey(), (Component) null, null)));
            item.add(link);
          }
        });

    add(feedbackPanel = new FeedbackPanel("feedback"));
    feedbackPanel.setOutputMarkupId(true);

    // ajax feedback image
    add(
        new Image(
            "ajaxFeedbackImage",
            new PackageResourceReference(GeoServerBasePage.class, "img/ajax-loader.gif")));

    add(new WebMarkupContainer(HEADER_PANEL));

    // allow the subclasses to initialize before getTitle/getDescription are called
    add(
        new Label(
            "gbpTitle",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getTitle();
              }
            }));
    add(
        new Label(
            "gbpDescription",
            new LoadableDetachableModel<String>() {

              @Override
              protected String load() {
                return getDescription();
              }
            }));

    // node id handling
    WebMarkupContainer container = new WebMarkupContainer("nodeIdContainer");
    add(container);
    String id = getNodeInfo().getId();
    Label label = new Label("nodeId", id);
    container.add(label);
    NODE_INFO.customize(container);
    if (id == null) {
      container.setVisible(false);
    }
  }
  @Override
  public void init() {
    super.init();

    getMarkupSettings().setStripWicketTags(true);
    getResourceSettings().setPackageResourceGuard(new PackageResourceGuard());

    // used for selenium testing
    // http://www.wijsmullerbros.nl/content/wicket-selenium

    if (RuntimeConfigurationType.DEVELOPMENT.equals(this.getConfigurationType())) {
      getDebugSettings().setOutputComponentPath(true);
      getDebugSettings().setOutputMarkupContainerClassName(true);
    }

    IComponentInstantiationListener spListener =
        new SpringComponentInjector(this, applicationContext, true);
    this.getComponentInstantiationListeners().add(spListener);

    mountPages();

    // this is for the generated image in demo in ImageRefPage.java
    mountResource("/images/${name}", new ImageResourceReference());
    // this cleans up the url http://localhost:9090/wicket-sandbox/imagesPage?0
    // will go to the ImageRefPage
    mountPage("imagesPage", ImageRefPage.class);
    ////////////////////
    // mountBookmarkablePage(page.getSimpleName(), page);
    // Register the authorization strategy
    getSecuritySettings()
        .setAuthorizationStrategy(
            new IAuthorizationStrategy() {
              @Override
              public boolean isActionAuthorized(
                  org.apache.wicket.Component component, Action action) {
                // authorize everything
                //  logger.debug("authorizing for component " + component.getMarkupId() + " action "
                // + action.getName());
                return true;
              }

              @Override
              public <T extends IRequestableComponent> boolean isInstantiationAuthorized(
                  Class<T> componentClass) {
                // Check if the new Page requires authentication (implements the marker interface)
                // logger.debug("entering isInstantiationAuthorized " +
                // componentClass.getSimpleName());
                if (AuthenticatedWebPage.class.isAssignableFrom(componentClass)) {
                  // Is user signed in?
                  if (((SandboxSession) Session.get()).isAuthenticated()) {
                    // okay to proceed
                    //    logger.debug("authenticated hit " + componentClass.getSimpleName());
                    return true;
                  }
                  // logger.debug("about to throw noauth " + componentClass.getSimpleName());

                  // Intercept the request, but remember the target for later.
                  // Invoke Component.continueToOriginalDestination() after successful logon to
                  // continue with the target remembered.

                  throw new RestartResponseAtInterceptPageException(SignIn.class);
                }

                // okay to proceed
                return true;
              }
            });
  }