|
|
|
|
@ -9,6 +9,7 @@ import javax.servlet.http.HttpServlet;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
import org.leolo.web.dm.Constant; |
|
|
|
|
import org.leolo.web.dm.dao.APIKeyDao; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
@ -22,7 +23,8 @@ public class BaseServlet extends HttpServlet {
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(BaseServlet.class); |
|
|
|
|
|
|
|
|
|
protected String userName = null; |
|
|
|
|
protected int userId = 0;//Special UID for anonymous user
|
|
|
|
|
protected int userId = Constant.COM_DEFAULT_USER_ID; |
|
|
|
|
protected boolean fatalError = false; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @see HttpServlet#HttpServlet() |
|
|
|
|
@ -37,19 +39,33 @@ public class BaseServlet extends HttpServlet {
|
|
|
|
|
*/ |
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
|
|
|
|
log.info("Request - [GET] {}", request.getRequestURI()); |
|
|
|
|
//Reset parameters
|
|
|
|
|
userName = null; |
|
|
|
|
userId = Constant.COM_DEFAULT_USER_ID; |
|
|
|
|
fatalError = false; |
|
|
|
|
|
|
|
|
|
if(request.getAttribute(Constant.SESSION_USER_NAME)!=null) { |
|
|
|
|
userName = request.getSession().getAttribute(Constant.SESSION_USER_NAME).toString(); |
|
|
|
|
userId = (Integer) request.getSession().getAttribute(Constant.SESSION_USER_ID); |
|
|
|
|
} |
|
|
|
|
if(request.getParameter("key") != null) { |
|
|
|
|
if(request.getParameter("key") != null && !"".equals(request.getParameter("key").trim())) { |
|
|
|
|
APIKeyDao apiDao = new APIKeyDao(); |
|
|
|
|
String key = request.getParameter("key").toString(); |
|
|
|
|
String key = request.getParameter("key"); |
|
|
|
|
log.info("Using API key {}", key); |
|
|
|
|
Map<String, Object> buim = apiDao.getBasicUserInfomationBuApiKey(key); |
|
|
|
|
if(buim!=null) { |
|
|
|
|
userName = buim.get(Constant.BUI_KEY_USER_NAME).toString(); |
|
|
|
|
userId = (Integer) buim.get(Constant.BUI_KEY_USER_ID); |
|
|
|
|
apiDao.markKeyUsed(key); |
|
|
|
|
}else { |
|
|
|
|
response.setContentType("application/json"); |
|
|
|
|
JSONObject obj = new JSONObject(); |
|
|
|
|
response.setStatus(403); |
|
|
|
|
obj.put("status", "error"); |
|
|
|
|
obj.put("message", "Invalid API key"); |
|
|
|
|
obj.write(response.getWriter()); |
|
|
|
|
fatalError = true; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -58,7 +74,7 @@ public class BaseServlet extends HttpServlet {
|
|
|
|
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) |
|
|
|
|
*/ |
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
|
|
|
|
|
|
|
|
|
doGet(request, response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|