Example usage for org.apache.wicket.request UrlUtils rewriteToContextRelative

List of usage examples for org.apache.wicket.request UrlUtils rewriteToContextRelative

Introduction

In this page you can find the example usage for org.apache.wicket.request UrlUtils rewriteToContextRelative.

Prototype

public static String rewriteToContextRelative(String url, IRequestCycle requestCycle) 

Source Link

Document

Rewrites a relative url to be context relative, leaves absolute urls same.

Usage

From source file:org.apache.syncope.client.console.pages.SAML2SPBeforeLogout.java

License:Apache License

public SAML2SPBeforeLogout() {
    super();//www . j a  va  2  s.c om

    RequestCycle.get().scheduleRequestHandlerAfterCurrent(new RedirectRequestHandler(
            UrlUtils.rewriteToContextRelative("saml2sp/logout", RequestCycle.get())));
}

From source file:org.apache.syncope.client.console.panels.SAML2SPPanel.java

License:Apache License

public SAML2SPPanel(final String id) {
    super(id);//from w  ww. j  a  v  a  2  s .  co  m

    add(new Link<Void>("downloadMetadata") {

        private static final long serialVersionUID = -4331619903296515985L;

        @Override
        public void onClick() {
            try {
                HttpResourceStream stream = new HttpResourceStream(ClientBuilder.newClient()
                        .target(RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(
                                UrlUtils.rewriteToContextRelative("saml2sp/metadata", RequestCycle.get()))))
                        .request().get());

                ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
                rsrh.setFileName(stream.getFilename() == null
                        ? SyncopeConsoleSession.get().getDomain() + "-SAML-SP-Metadata.xml"
                        : stream.getFilename());
                rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);

                getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
            } catch (Exception e) {
                LOG.error("While exporting SAML 2.0 SP metadata", e);
                SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
            }
        }
    });
}

From source file:org.apache.syncope.client.console.panels.SAMLSSOLoginFormPanel.java

License:Apache License

public SAMLSSOLoginFormPanel(final String id) {
    super(id);/*from ww  w. j a  va 2  s  . c  o m*/

    List<SAML2IdPTO> available = SyncopeConsoleSession.get().getAnonymousClient()
            .getService(SAML2IdPService.class).list();

    final Model<SAML2IdPTO> model = new Model<>();
    AjaxDropDownChoicePanel<SAML2IdPTO> idps = new AjaxDropDownChoicePanel<>("idps", "SAML 2.0", model, false);
    idps.setChoices(available);
    idps.setChoiceRenderer(new IChoiceRenderer<SAML2IdPTO>() {

        private static final long serialVersionUID = 1814750973898916102L;

        @Override
        public Object getDisplayValue(final SAML2IdPTO object) {
            return object.getName();
        }

        @Override
        public String getIdValue(final SAML2IdPTO object, final int index) {
            return object.getEntityID();
        }

        @Override
        public SAML2IdPTO getObject(final String id,
                final IModel<? extends List<? extends SAML2IdPTO>> choices) {
            return choices.getObject().stream().filter(idp -> idp.getEntityID().equals(id)).findFirst()
                    .orElse(null);
        }
    });
    idps.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            if (model.getObject() != null) {
                try {
                    RequestCycle.get()
                            .scheduleRequestHandlerAfterCurrent(
                                    new RedirectRequestHandler(UrlUtils.rewriteToContextRelative(
                                            "saml2sp/login?idp="
                                                    + URLEncoder.encode(model.getObject().getEntityID(),
                                                            StandardCharsets.UTF_8.name()),
                                            RequestCycle.get())));
                } catch (Exception e) {
                    LOG.error("Could not redirect to the selected IdP {}", model.getObject().getEntityID(), e);
                }
            }
        }
    });
    idps.setOutputMarkupPlaceholderTag(true);
    idps.setVisible(!available.isEmpty());
    add(idps);
}

From source file:org.cast.cwm.components.Icon.java

License:Open Source License

@Override
protected void onComponentTag(ComponentTag tag) {
    checkComponentTag(tag, "img");
    if (mImagePath == null)
        throw new RuntimeException();
    if (mAltText != null)
        tag.put("alt", mAltText.getObject());
    // Title attribute is set to the same as ALT if no other title is specified.
    String title = null;//ww w .j  a va 2  s  .  c  o m
    if (mTitleText != null)
        title = mTitleText.getObject();
    if (title == null && mAltText != null)
        title = mAltText.getObject();
    if (title != null)
        tag.put("title", title);
    tag.put("src", UrlUtils.rewriteToContextRelative(mImagePath.getObject(), RequestCycle.get()));
    super.onComponentTag(tag);
}

From source file:org.projectforge.web.wicket.WicketUtils.java

License:Open Source License

/**
 * Should be c:url equivalent, but isn't yet (works for now).
 * @param requestCycle Needed to encode url.
 * @param path//from w  w  w  . j  a v  a 2 s.  co  m
 * @param encodeUrl
 * @return path itself if not starts with '/' otherwise "/ProjectForge" + path with session id and params.
 */
public static String getUrl(final RequestCycle requestCycle, final String path, final boolean encodeUrl) {
    String url = UrlUtils.rewriteToContextRelative(path, requestCycle);
    if (encodeUrl == true) {
        url = requestCycle.getResponse().encodeURL(url);
    }
    return url;
}