boolean isAuthorized = true;
if(protectedSiteNodeVersionId != null)
{
isAuthorized = false;
SiteNodeVersionVO siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(protectedSiteNodeVersionId, db);
if(siteNodeVersionVO.getIsProtected().intValue() == SiteNodeVersionVO.YES_WITH_INHERIT_FALLBACK.intValue())
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)anonymousPrincipal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString(), false);
else
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)anonymousPrincipal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString());
}
logger.info("isAuthorized:" + isAuthorized);
if(isAuthorized)
{
principal = anonymousPrincipal;
if(principal != null)
{
this.getHttpSession().setAttribute("infogluePrincipal", principal);
this.getHttpSession().setAttribute("infoglueRemoteUser", principal.getName());
this.getHttpSession().setAttribute("cmsUserName", principal.getName());
}
}
}
if(principal == null)
{
Map status = new HashMap();
status.put("redirected", new Boolean(false));
principal = AuthenticationModule.getAuthenticationModule(db, this.getOriginalFullURL(), getRequest(), false).loginUser(getRequest(), getResponse(), status);
Boolean redirected = (Boolean)status.get("redirected");
if(redirected != null && redirected.booleanValue())
{
this.getHttpSession().removeAttribute("infogluePrincipal");
this.principal = null;
return true;
}
else if(principal != null)
{
this.getHttpSession().setAttribute("infogluePrincipal", principal);
this.getHttpSession().setAttribute("infoglueRemoteUser", principal.getName());
this.getHttpSession().setAttribute("cmsUserName", principal.getName());
this.principal = principal;
}
if(principal == null)
principal = loginWithCookies();
if(principal == null)
principal = loginWithRequestArguments();
if(principal == null)
{
try
{
if(!forceCmsUser)
{
principal = getAnonymousPrincipal();
if(principal != null)
{
this.getHttpSession().setAttribute("infogluePrincipal", principal);
this.getHttpSession().setAttribute("infoglueRemoteUser", principal.getName());
this.getHttpSession().setAttribute("cmsUserName", principal.getName());
boolean isAuthorized = false;
if(!protectDeliver)
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)principal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString());
if(!isAuthorized)
{
this.getHttpSession().removeAttribute("infogluePrincipal");
logger.info("SiteNode is protected and anonymous user was not allowed - sending him to login page.");
String redirectUrl = getRedirectUrl(getRequest(), getResponse());
//System.out.println("redirectUrl:" + redirectUrl);
getResponse().sendRedirect(redirectUrl);
isRedirected = true;
}
}
}
else
{
this.getHttpSession().removeAttribute("infogluePrincipal");
this.getHttpSession().removeAttribute("infoglueRemoteUser");
this.getHttpSession().removeAttribute("cmsUserName");
logger.info("SiteNode is protected and anonymous user was not allowed - sending him to login page.");
String redirectUrl = getRedirectUrl(getRequest(), getResponse());
getResponse().sendRedirect(redirectUrl);
isRedirected = true;
}
}
catch(Exception e)
{
throw new SystemException("There was no anonymous user found in the system. There must be - add the user anonymous/anonymous and try again.", e);
}
}
else
{
boolean isAuthorized = false;
if(protectDeliver && protectedSiteNodeVersionId == null && !principal.getName().equals(CmsPropertyHandler.getAnonymousUser()))
{
isAuthorized = true;
}
else if(protectedSiteNodeVersionId != null)
{
if(logger.isInfoEnabled())
logger.info("protectedSiteNodeVersionId:" + protectedSiteNodeVersionId);
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized((InfoGluePrincipal)this.getAnonymousPrincipal(), "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString());
if(logger.isInfoEnabled())
logger.info("Anonymous auth:" + isAuthorized);
if(!isAuthorized)
{
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)principal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString());
if(logger.isInfoEnabled())
logger.info("" + principal + " auth:" + isAuthorized);
}
if(logger.isInfoEnabled())
logger.info("protectedSiteNodeVersionId:" + protectedSiteNodeVersionId);
}
else if(!protectDeliver)
{
isAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)principal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString());
}
if(logger.isInfoEnabled())
{
logger.info("protectDeliver:" + protectDeliver);
logger.info("protectedSiteNodeVersionId:" + protectedSiteNodeVersionId);
logger.info("isAuthorized:" + isAuthorized);
logger.info("principal:" + principal);
}
if(!isAuthorized)
{
if(this.referer == null)
this.referer = this.getRequest().getHeader("Referer");
if(this.referer == null || referer.indexOf("ViewStructureToolToolBar.action") != -1)
this.referer = "/";
if(principal.getName().equals(CmsPropertyHandler.getAnonymousUser()))
{
logger.info("SiteNode is protected and user was anonymous - sending him to login page.");
//String url = "ExtranetLogin!loginForm.action?returnAddress=" + URLEncoder.encode(this.getRequest().getRequestURL().toString() + "?" + this.getRequest().getQueryString() + "&referer=" + URLEncoder.encode(referer, "UTF-8") + "&date=" + System.currentTimeMillis(), "UTF-8");
String url = getRedirectUrl(getRequest(), getResponse());
getResponse().sendRedirect(url);
isRedirected = true;
}
else
{
logger.info("SiteNode is protected and user has no access - sending him to no access page.");
String noAccessURL = getNoAccessURL();
getResponse().sendRedirect(noAccessURL);
isRedirected = true;
}
}
else
{
this.getHttpSession().setAttribute("infogluePrincipal", principal);
this.getHttpSession().setAttribute("infoglueRemoteUser", principal.getName());
this.getHttpSession().setAttribute("cmsUserName", principal.getName());
this.principal = principal;
}
}
}
else
{
logger.info("principal:" + principal);
logger.info("protectedSiteNodeVersionId:" + protectedSiteNodeVersionId);
Principal alternativePrincipal = loginWithCookies();
if(alternativePrincipal == null)
alternativePrincipal = loginWithRequestArguments();
SiteNodeVersionVO siteNodeVersionVO = null;
boolean isAlternativePrincipalAuthorized = (alternativePrincipal == null);
boolean isPrincipalAuthorized = true;
boolean isAnonymousPrincipalAuthorized = true;
if(protectedSiteNodeVersionId != null)
{
siteNodeVersionVO = SiteNodeVersionController.getController().getSiteNodeVersionVOWithId(protectedSiteNodeVersionId, db);
isAlternativePrincipalAuthorized = false;
isPrincipalAuthorized = false;
isAnonymousPrincipalAuthorized = false;
}
if(siteNodeVersionVO != null && siteNodeVersionVO.getIsProtected().intValue() == SiteNodeVersionVO.YES_WITH_INHERIT_FALLBACK.intValue())
{
if(alternativePrincipal != null)
isAlternativePrincipalAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)alternativePrincipal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString(), true);
if(!isAlternativePrincipalAuthorized && !((InfoGluePrincipal)principal).getName().equals(((InfoGluePrincipal)this.getAnonymousPrincipal()).getName()))
isPrincipalAuthorized = AccessRightController.getController().getIsPrincipalAuthorized(db, (InfoGluePrincipal)principal, "SiteNodeVersion.Read", protectedSiteNodeVersionId.toString(), true);