// Gather information
HttpSession session = request.getSession();
String uri = request.getServletPath();
String method = request.getMethod();
User user = null;
try {
user = (User) session.getAttribute("user");
} catch(Exception e) {}
boolean auth = user != null;
// Result
Command command = null;
// Web
if(uri.equals("/")) {
command = new HomeCommand();
} else if(uri.equals("/debug")) {
command = new DebugCommand();
} else if(uri.equals("/dashboard")) {
if(auth && user.isUser() && user.isEnabled()) {
command = new DashboardCommand();
} else {
command = new UnauthorizedCommand();
}
} else if(uri.equals("/profile")) {
//if(auth && (user.isUser() || user.isAdmin())) {
if(auth) {
command = new ProfileCommand();
} else {
command = new UnauthorizedCommand();
}
} else if(uri.equals("/admin")) {
if(auth && user.isAdmin() && user.isEnabled()) {
command = new AdminCommand();
} else {
command = new UnauthorizedCommand();
}
// AJAX
} else if(uri.equals("/login")) {
command = new LoginCommand();
} else if(uri.equals("/register")) {
command = new RegisterCommand();
} else if(uri.equals("/logout")) {
command = new LogoutCommand();
} else if(uri.equals("/request")) {
if(auth && user.isUser() && user.isEnabled()) {
command = new RequestCommand();
} else {
command = new UnauthorizedCommand();
}
} else if(uri.equals("/answer")) {
if(auth && user.isUser() && user.isEnabled()) {
command = new AnswerCommand();
} else {
command = new UnauthorizedCommand();
}
} else if(uri.equals("/upload/mygeo")) {
if(auth && user.isAdmin() && user.isEnabled()) {
command = new MyGeoCommand();
} else {
command = new UnauthorizedCommand();
}
} else if(uri.equals("/expertise/add") ||
uri.equals("/expertise/remove")) {
if(auth && user.isUser() && user.isEnabled()) {
command = new ExpertiseCommand();
} else {
command = new UnauthorizedCommand();
}
}