src/de/uhilger/wbx/web/MarkdownServlet.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/wbx/web/ViewServlet.java | ●●●●● patch | view | raw | blame | history | |
src/de/uhilger/wbx/web/WbxServlet.java | ●●●●● patch | view | raw | blame | history |
src/de/uhilger/wbx/web/MarkdownServlet.java
@@ -17,12 +17,49 @@ */ package de.uhilger.wbx.web; import org.apache.catalina.servlets.DefaultServlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author ulrich */ public class MarkdownServlet extends DefaultServlet { public class MarkdownServlet extends WbxServlet { /** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String contextPath = request.getContextPath(); if(HOME_CTX.equals(contextPath)) { String userName = getUserName(request); if (userName != null) { String urlUser = getUrlUser(request, userName); if(userName.equals(urlUser)) { seiteAusgeben(request, response); } else { logger.fine("Wrong user."); } } else { logger.fine("Missing login."); } } else { seiteAusgeben(request, response); } } private void seiteAusgeben(HttpServletRequest request, HttpServletResponse response) { } } src/de/uhilger/wbx/web/ViewServlet.java
@@ -18,14 +18,11 @@ package de.uhilger.wbx.web; import java.io.IOException; import java.security.Principal; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.catalina.servlets.DefaultServlet; /** * Das ViewServlet fügt dem DefaultServlet von Tomcat @@ -36,10 +33,10 @@ * * TODO: Stylesheets dynamisch einbinden */ public class ViewServlet extends DefaultServlet { public class ViewServlet extends WbxServlet { private static final Logger logger = Logger.getLogger(ViewServlet.class.getName()); private static final String HOME_CTX = "/home"; //private static final String HOME_CTX = "/home"; /** * Handles the HTTP <code>GET</code> method. @@ -92,6 +89,7 @@ out.print("</body></html>"); } /* private String getUrlUser(HttpServletRequest request, String userName) throws IOException { String result = ""; String requestUrlStr = request.getRequestURL().toString(); @@ -118,6 +116,7 @@ } return userName; } */ /** * Returns a short description of the servlet. src/de/uhilger/wbx/web/WbxServlet.java
New file @@ -0,0 +1,52 @@ /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.uhilger.wbx.web; import java.io.IOException; import java.security.Principal; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.http.HttpServletRequest; import org.apache.catalina.servlets.DefaultServlet; /** * * @author ulrich */ public class WbxServlet extends DefaultServlet { protected static final Logger logger = Logger.getLogger(WbxServlet.class.getName()); protected static final String HOME_CTX = "/home"; protected String getUrlUser(HttpServletRequest request, String userName) throws IOException { String result = ""; String requestUrlStr = request.getRequestURL().toString(); String contextPath = request.getContextPath(); if(contextPath != null && requestUrlStr != null && userName != null) { int start = requestUrlStr.indexOf(contextPath); start += contextPath.length(); start++; int end = start + userName.length(); try { result = requestUrlStr.substring(start, end); } catch(Exception ex) { logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } } return result; } protected String getUserName(HttpServletRequest hr) { String userName = null; Object p = hr.getUserPrincipal(); if (p instanceof Principal) { userName = ((Principal) p).getName(); } return userName; } }