Skip to content

Commit

Permalink
SAK-29788 Remove covers from /access
Browse files Browse the repository at this point in the history
  • Loading branch information
buckett committed Aug 8, 2015
1 parent cddae3e commit 330193d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.authz.api.SecurityAdvisor;
import org.sakaiproject.authz.cover.SecurityService;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.cheftool.VmServlet;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.entity.api.Entity;
import org.sakaiproject.entity.api.EntityAccessOverloadException;
import org.sakaiproject.entity.api.EntityCopyrightException;
Expand All @@ -46,13 +47,13 @@
import org.sakaiproject.entity.api.HttpAccess;
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.cover.EntityManager;
import org.sakaiproject.entity.api.EntityManager;
import org.sakaiproject.tool.api.ActiveTool;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.api.Tool;
import org.sakaiproject.tool.api.ToolException;
import org.sakaiproject.tool.cover.ActiveToolManager;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.tool.api.ActiveToolManager;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.util.BaseResourceProperties;
import org.sakaiproject.util.BasicAuth;
import org.sakaiproject.util.ParameterParser;
Expand Down Expand Up @@ -110,6 +111,11 @@ public class AccessServlet extends VmServlet

protected BasicAuth basicAuth = null;

protected SecurityService securityService;
protected EntityManager entityManager;
protected ActiveToolManager activeToolManager;
protected SessionManager sessionManager;

/** init thread - so we don't wait in the actual init() call */
public class AccessServletInit extends Thread
{
Expand Down Expand Up @@ -145,7 +151,11 @@ public void init(ServletConfig config) throws ServletException
startInit();
basicAuth = new BasicAuth();
basicAuth.init();

// Grab our services
securityService = ComponentManager.get(SecurityService.class);
entityManager = ComponentManager.get(EntityManager.class);
activeToolManager = ComponentManager.get(ActiveToolManager.class);
sessionManager = ComponentManager.get(SessionManager.class);
}

/**
Expand Down Expand Up @@ -250,18 +260,18 @@ public void dispatch(HttpServletRequest req, HttpServletResponse res) throws Ser
String acceptedRef = req.getParameter(COPYRIGHT_ACCEPT_REF);
String returnPath = req.getParameter(COPYRIGHT_ACCEPT_URL);

Reference aRef = EntityManager.newReference(acceptedRef);
Reference aRef = entityManager.newReference(acceptedRef);

// get the properties - but use a security advisor to avoid needing end-user permission to the resource
SecurityService.pushAdvisor(new SecurityAdvisor()
securityService.pushAdvisor(new SecurityAdvisor()
{
public SecurityAdvice isAllowed(String userId, String function, String reference)
{
return SecurityAdvice.ALLOWED;
}
});
ResourceProperties props = aRef.getProperties();
SecurityService.popAdvisor();
securityService.popAdvisor();

// send the copyright agreement interface
if (props == null)
Expand All @@ -283,18 +293,18 @@ public SecurityAdvice isAllowed(String userId, String function, String reference
}

// make sure we have a collection for accepted copyright agreements
Collection accepted = (Collection) SessionManager.getCurrentSession().getAttribute(COPYRIGHT_ACCEPTED_REFS_ATTR);
Collection accepted = (Collection) sessionManager.getCurrentSession().getAttribute(COPYRIGHT_ACCEPTED_REFS_ATTR);
if (accepted == null)
{
accepted = new Vector();
SessionManager.getCurrentSession().setAttribute(COPYRIGHT_ACCEPTED_REFS_ATTR, accepted);
sessionManager.getCurrentSession().setAttribute(COPYRIGHT_ACCEPTED_REFS_ATTR, accepted);
}

// for accepted copyright, mark it and redirect to the entity's access URL
if (COPYRIGHT_ACCEPT.equals(path))
{
String acceptedRef = req.getParameter(COPYRIGHT_ACCEPT_REF);
Reference aRef = EntityManager.newReference(acceptedRef);
Reference aRef = entityManager.newReference(acceptedRef);

// save this with the session's other accepted refs
accepted.add(aRef.getReference());
Expand All @@ -318,7 +328,7 @@ public SecurityAdvice isAllowed(String userId, String function, String reference
path = preProcessPath(path, req);

// what is being requested?
Reference ref = EntityManager.newReference(path);
Reference ref = entityManager.newReference(path);

// get the incoming information
AccessServletInfo info = newInfo(req);
Expand Down Expand Up @@ -349,7 +359,7 @@ public SecurityAdvice isAllowed(String userId, String function, String reference
{
// the end user does not have permission - offer a login if there is no user id yet established
// if not permitted, and the user is the anon user, let them login
if (SessionManager.getCurrentSessionUserId() == null)
if (sessionManager.getCurrentSessionUserId() == null)
{
try {
doLogin(req, res, origPath);
Expand Down Expand Up @@ -460,7 +470,7 @@ protected void doLogin(HttpServletRequest req, HttpServletResponse res, String p
}

// get the Sakai session
Session session = SessionManager.getCurrentSession();
Session session = sessionManager.getCurrentSession();

// set the return path for after login if needed (Note: in session, not tool session, special for Login helper)
if (path != null)
Expand All @@ -476,7 +486,7 @@ protected void doLogin(HttpServletRequest req, HttpServletResponse res, String p
}

// map the request to the helper, leaving the path after ".../options" for the helper
ActiveTool tool = ActiveToolManager.getActiveTool("sakai.login");
ActiveTool tool = activeToolManager.getActiveTool("sakai.login");
String context = req.getContextPath() + req.getServletPath() + "/login";
tool.help(req, res, context, "/login");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@
import org.sakaiproject.entity.api.Reference;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entity.api.ResourcePropertiesEdit;
import org.sakaiproject.entity.cover.EntityManager;
import org.sakaiproject.event.cover.NotificationService;
import org.sakaiproject.event.api.NotificationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.IdUsedException;
import org.sakaiproject.exception.InconsistentException;
import org.sakaiproject.time.api.TimeBreakdown;
import org.sakaiproject.time.cover.TimeService;
import org.sakaiproject.time.api.TimeService;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.cover.UserDirectoryService;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;

/**
* <p>
Expand All @@ -65,7 +63,9 @@ public class WebServlet extends AccessServlet
{
/** Our log (commons). */
private static Log M_log = LogFactory.getLog(WebServlet.class);
private ContentHostingService contentHostingService;
protected ContentHostingService contentHostingService;
protected UserDirectoryService userDirectoryService;
protected TimeService timeService;



Expand All @@ -77,7 +77,9 @@ public void init(ServletConfig config) throws ServletException
{
super.init(config);

contentHostingService = (ContentHostingService) ComponentManager.get(ContentHostingService.class.getName());
contentHostingService = ComponentManager.get(ContentHostingService.class);
userDirectoryService = ComponentManager.get(UserDirectoryService.class);
timeService = ComponentManager.get(TimeService.class);
}
/**
* Set active session according to sessionId parameter
Expand All @@ -87,12 +89,12 @@ private void setSession( HttpServletRequest req )
String sessionId = req.getParameter("session");
if ( sessionId != null)
{
Session session = SessionManager.getSession(sessionId);
Session session = sessionManager.getSession(sessionId);

if (session != null)
{
session.setActive();
SessionManager.setCurrentSession(session);
sessionManager.setCurrentSession(session);
}
}
}
Expand Down Expand Up @@ -222,7 +224,7 @@ protected boolean writeFile(String name, String type, byte[] data, String dir, H
if (!dir.endsWith(Entity.SEPARATOR)) dir = dir + Entity.SEPARATOR;

// get a reference to the content collection - this lets us use alias and short refs
Reference ref = EntityManager.newReference(dir);
Reference ref = entityManager.newReference(dir);

// the reference id replaces the dir - as a fully qualified path (no alias, no short ref)
dir = ref.getId();
Expand Down Expand Up @@ -270,9 +272,9 @@ protected boolean writeFile(String name, String type, byte[] data, String dir, H

try
{
User user = UserDirectoryService.getCurrentUser();
User user = userDirectoryService.getCurrentUser();

TimeBreakdown timeBreakdown = TimeService.newTime().breakdownLocal();
TimeBreakdown timeBreakdown = timeService.newTime().breakdownLocal();
String mycopyright = "copyright (c)" + " " + timeBreakdown.getYear() + ", " + user.getDisplayName()
+ ". All Rights Reserved. ";

Expand Down

0 comments on commit 330193d

Please sign in to comment.