@Test public void testStripContextPathFromURLWhenRootContextPathWithoutSlash() throws Exception { doReturn("").when(this.oldcore.getSpyXWiki()).getWebAppPath(any(XWikiContext.class)); assertEquals("/something", this.authService.stripContextPathFromURL(new URL("http: this.oldcore.getXWikiContext())); }
protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; } }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; }  }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; }  @Override XWikiUser checkAuth(XWikiContext context); @Override XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context); @Override void showLogin(XWikiContext context); @Override Principal authenticate(String username, String password, XWikiContext context); }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { protected String stripContextPathFromURL(URL url, XWikiContext context) { String contextPath = context.getWiki().getWebAppPath(context); if (contextPath.endsWith("/") && !contextPath.startsWith("/")) { contextPath = "/" + StringUtils.chop(contextPath); } else if ("/".equals(contextPath)) { contextPath = ""; } String urlPrefix = url.getProtocol() + ": String encodedUrlPrefix = context.getResponse().encodeURL(urlPrefix); encodedUrlPrefix = encodedUrlPrefix.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); encodedUrlPrefix = StringUtils.substringBeforeLast(encodedUrlPrefix, "?"); String strippedURL = StringUtils.removeStart(url.toExternalForm(), encodedUrlPrefix); if (!strippedURL.startsWith("/")) { strippedURL = "/" + strippedURL; } return strippedURL; }  @Override XWikiUser checkAuth(XWikiContext context); @Override XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context); @Override void showLogin(XWikiContext context); @Override Principal authenticate(String username, String password, XWikiContext context);  }