grom358
Oct 8th, 2004, 05:55 AM
I was wondering what would be a good way to handle security checks based on the user associated with a request. Currently I have
package presentation.web.shop;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.util.WebUtils;
import application.WebStoreFacade;
import domain.PrimaryKey;
import domain.Order;
import domain.Customer;
/**
* @author <a href="mailto:grom@capsicumcorp.com">Cameron Zemek</a>
*/
public class ViewOrderController implements Controller {
private WebStoreFacade webstore;
public void setWebStore(WebStoreFacade webstore) {
this.webstore = webstore;
}
public ModelAndView handleRequest(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
int orderId = Integer.parseInt(request.getParameter("orderId"));
Order order = webstore.getOrder(new PrimaryKey(orderId));
// TODO Move this authorization check into the application layer
// Check user is authorized to view this order
Customer customer = (Customer) WebUtils.getSessionAttribute(
request, "sessionCustomer");
if (! order.getUserName().equals(customer.getUserName()) ) {
return new ModelAndView("Error", "message",
"You are not authorized to view this order!");
}
return new ModelAndView("Order", "order", order);
}
}
I should move the security check into the application layer but I don't want to pass the customer around. Any ideas?
package presentation.web.shop;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.util.WebUtils;
import application.WebStoreFacade;
import domain.PrimaryKey;
import domain.Order;
import domain.Customer;
/**
* @author <a href="mailto:grom@capsicumcorp.com">Cameron Zemek</a>
*/
public class ViewOrderController implements Controller {
private WebStoreFacade webstore;
public void setWebStore(WebStoreFacade webstore) {
this.webstore = webstore;
}
public ModelAndView handleRequest(
HttpServletRequest request,
HttpServletResponse response) throws Exception {
int orderId = Integer.parseInt(request.getParameter("orderId"));
Order order = webstore.getOrder(new PrimaryKey(orderId));
// TODO Move this authorization check into the application layer
// Check user is authorized to view this order
Customer customer = (Customer) WebUtils.getSessionAttribute(
request, "sessionCustomer");
if (! order.getUserName().equals(customer.getUserName()) ) {
return new ModelAndView("Error", "message",
"You are not authorized to view this order!");
}
return new ModelAndView("Order", "order", order);
}
}
I should move the security check into the application layer but I don't want to pass the customer around. Any ideas?