HashMap<String, String> httpUrlsToBeByPassed = new HashMap<String, String>();
Context defaultContext = null;
if (bundle != null) {
ServiceReference reference = bundle.getBundleContext().getServiceReference(
CarbonUIDefinitions.class.getName());
CarbonUIDefinitions carbonUIDefinitions;
if (reference != null) {
carbonUIDefinitions = (CarbonUIDefinitions) bundle.getBundleContext().getService(
reference);
if (carbonUIDefinitions != null) {
httpUrlsToBeByPassed = carbonUIDefinitions.getHttpUrls();
if (carbonUIDefinitions.getContexts().containsKey("default-context")) {
defaultContext = carbonUIDefinitions.getContexts().get("default-context");
}
}
}
}
if (requestedURI.equals(context) || requestedURI.equals(context + "/")) {
if (defaultContext != null && !"".equals(defaultContext.getContextName())
&& !"null".equals(defaultContext.getContextName())) {
String adminConsoleURL = CarbonUIUtil.getAdminConsoleURL(request);
int index = adminConsoleURL.lastIndexOf("carbon");
String defaultContextUrl = adminConsoleURL.substring(0, index)
+ defaultContext.getContextName() + "/";
response.sendRedirect(defaultContextUrl);
} else {
response.sendRedirect("carbon");
}
return false;
}
// when war is deployed on top of an existing app server we cannot use
// root context
// for deployment. Hence a new context is added.
// Now url changes from eg: carbon/admin/index.jsp to
// wso2/carbon/admin/index.jsp
// In this case before doing anything, we need to remove web app context
// (eg: wso2) .
String tmp = requestedURI;
String customWarContext = "";
if (requestedURI.startsWith("/carbon") && !(requestedURI.startsWith("/carbon/carbon/"))) {
// one can name the folder as 'carbon'
requestedURI = tmp;
} else if (requestedURI.indexOf("filedownload") == -1
&& requestedURI.indexOf("fileupload") == -1) {
// replace first context
String tmp1 = tmp.replaceFirst("/", "");
int end = tmp1.indexOf("/");
if (end > -1) {
customWarContext = tmp1.substring(0, end);
// one can rename the war file as 'registry'.
// This will conflict with our internal 'registry' context
if (!(requestedURI.startsWith("/registry/registry/"))
&& !(requestedURI.startsWith("/registry/carbon/"))
&& (customWarContext.equals("registry")
|| customWarContext.equals("gadgets") || customWarContext
.equals("social"))) {
requestedURI = tmp;
} else {
requestedURI = tmp.substring(end + 1);
}
}
}
// Disabling http access to admin console
// user guide documents should be allowed to access via http protocol
if (!request.isSecure() && !(requestedURI.endsWith(".html"))) {
// by passing items required for try-it & IDE plugins
if (requestedURI.endsWith(".css") || requestedURI.endsWith(".gif")
|| requestedURI.endsWith(".GIF") || requestedURI.endsWith(".jpg")
|| requestedURI.endsWith(".JPG") || requestedURI.endsWith(".png")
|| requestedURI.endsWith(".PNG") || requestedURI.endsWith(".xsl")
|| requestedURI.endsWith(".xslt") || requestedURI.endsWith(".js")
|| requestedURI.endsWith(".ico") || requestedURI.endsWith("/filedownload")
|| requestedURI.endsWith("/fileupload")
|| requestedURI.indexOf("/fileupload/") > -1
|| requestedURI.indexOf("admin/jsp/WSRequestXSSproxy_ajaxprocessor.jsp") > -1
|| requestedURI.indexOf("registry/atom") > -1
|| requestedURI.indexOf("registry/tags") > -1
|| requestedURI.indexOf("gadgets/") > -1
|| requestedURI.indexOf("registry/resource") > -1) {
return true;
}
String resourceURI = requestedURI.replaceFirst("/carbon/", "../");
// bypassing the pages which are specified as bypass https
if (httpUrlsToBeByPassed.containsKey(resourceURI)) {
if (!authenticated) {
try {
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(CarbonConstants.REMEMBER_ME_COOKE_NAME)) {
if (getAuthenticator(request).reAuthenticateOnSessionExpire(request)) {
String cookieValue = cookie.getValue();
CarbonUIAuthenticationUtil.onSuccessAdminLogin(request,
getUserNameFromCookie(cookieValue));
}
}
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new IOException(e.getMessage(), e);
}
}
return true;
}
String adminConsoleURL = CarbonUIUtil.getAdminConsoleURL(request);
if (adminConsoleURL != null) {
if (log.isTraceEnabled()) {
log.trace("Request came to admin console via http.Forwarding to : "
+ adminConsoleURL);
}
response.sendRedirect(adminConsoleURL);
return false;
}
}
String resourceURI = requestedURI.replaceFirst("/carbon/", "../");
if (log.isDebugEnabled()) {
log.debug("CarbonSecuredHttpContext -> handleSecurity() requestURI:" + requestedURI
+ " id:" + sessionId + " resourceURI:" + resourceURI);
}
// retrieve urls that should be by-passed from security check
HashMap<String, String> urlsToBeByPassed = new HashMap<String, String>();
if (bundle != null) {
ServiceReference reference = bundle.getBundleContext().getServiceReference(
CarbonUIDefinitions.class.getName());
CarbonUIDefinitions carbonUIDefinitions;
if (reference != null) {
carbonUIDefinitions = (CarbonUIDefinitions) bundle.getBundleContext().getService(
reference);
if (carbonUIDefinitions != null) {
urlsToBeByPassed = carbonUIDefinitions.getUnauthenticatedUrls();
/*
* if(log.isDebugEnabled()){ Iterator<String> itr =
* urlsToBeByPassed.keySet().iterator();
* while(itr.hasNext()){
* log.debug("Should bypass url : "+itr.next()); } }