removed obsolete code
This commit is contained in:
@ -1,104 +0,0 @@
|
|||||||
package de.muehlencord.shared.jeeutil;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.FilterConfig;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletOutputStream;
|
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.ServletResponse;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpSession;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Jörn Mühlencord (<a href="mailto:joern@muehlencord.de">joern@muehlencord.de</a>
|
|
||||||
*/
|
|
||||||
public class AuthenticationFilter implements Filter {
|
|
||||||
|
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(AuthenticationFilter.class);
|
|
||||||
private final static String USER = AuthenticationFilter.class.getName() + "_user";
|
|
||||||
private String loginPage;
|
|
||||||
private String errorPage;
|
|
||||||
private FilterConfig filterConfig;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
|
||||||
this.filterConfig = filterConfig;
|
|
||||||
if (filterConfig != null) {
|
|
||||||
errorPage = filterConfig.getInitParameter("error_page");
|
|
||||||
loginPage = filterConfig.getInitParameter("login_page");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
||||||
|
|
||||||
if ((loginPage == null) || (errorPage == null)) {
|
|
||||||
returnError(response, "AuthenticationFilter not properly configured! Contact Administrator.");
|
|
||||||
}
|
|
||||||
|
|
||||||
User currentUser = null;
|
|
||||||
HttpSession session = ((HttpServletRequest) request).getSession();
|
|
||||||
|
|
||||||
if (session != null) {
|
|
||||||
if (session.getAttribute(USER) != null) {
|
|
||||||
currentUser = (User) session.getAttribute(USER);
|
|
||||||
LOGGER.debug("found " + currentUser);
|
|
||||||
} else {
|
|
||||||
LOGGER.debug("No active session found - going to force login");
|
|
||||||
filterConfig.getServletContext().getRequestDispatcher(loginPage).forward(request, response);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (currentUser == null) {
|
|
||||||
LOGGER.debug("No logged in user found - going to force login");
|
|
||||||
filterConfig.getServletContext().getRequestDispatcher(loginPage).forward(request, response);
|
|
||||||
} else {
|
|
||||||
LOGGER.debug("User is authenticated, continue filter chain");
|
|
||||||
// user is authenticated, continue with filter chain
|
|
||||||
chain.doFilter(request, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroy() {
|
|
||||||
this.filterConfig = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void returnError(ServletResponse response, String errorMsg) {
|
|
||||||
response.setContentType("text/html");
|
|
||||||
try (
|
|
||||||
ServletOutputStream servletOutputStream = response.getOutputStream();
|
|
||||||
PrintStream ps = new PrintStream(servletOutputStream);
|
|
||||||
PrintWriter pw = new PrintWriter(ps)) {
|
|
||||||
|
|
||||||
pw.print("<html>");
|
|
||||||
pw.print("<head><title>Error</title></head>");
|
|
||||||
pw.print("<body>");
|
|
||||||
pw.print("<h1>");
|
|
||||||
pw.print(errorMsg);
|
|
||||||
pw.print("</h1>");
|
|
||||||
pw.print("</body");
|
|
||||||
pw.print("</html>");
|
|
||||||
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOGGER.error(errorMsg, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static String readFirstLineFromFile(String path) throws IOException {
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
|
|
||||||
return br.readLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.jeeutil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jomu
|
|
||||||
*/
|
|
||||||
public interface Authenticator {
|
|
||||||
|
|
||||||
public User getUser ();
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.jeeutil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jomu
|
|
||||||
*/
|
|
||||||
public class User {
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user