io.firebus.adapters.http.SecurityHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebus-http Show documentation
Show all versions of firebus-http Show documentation
Firebus http gateway adapter
package io.firebus.adapters.http;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import io.firebus.Payload;
import io.firebus.utils.DataMap;
public abstract class SecurityHandler {
protected DataMap config;
protected List authValidationHandlers;
public SecurityHandler(DataMap c)
{
config = c;
authValidationHandlers = new ArrayList();
}
public void addAuthValidationHandler(AuthValidationHandler avh)
{
authValidationHandlers.add(avh);
}
protected void unauthenticated(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String accept = req.getHeader("accept");
String path = req.getRequestURI();
if(accept.contains("text/html") || accept.contains("*/*")) {
if(authValidationHandlers.size() > 1) {
PrintWriter writer = resp.getWriter();
writer.println("Login ");
writer.println("Select an identity provider");
for(AuthValidationHandler avh: authValidationHandlers) {
writer.println("");
}
writer.println("");
} else if(authValidationHandlers.size() == 1) {
resp.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
resp.setHeader("Location", authValidationHandlers.get(0).getLoginURL(path));
} else {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
} else {
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}
public abstract boolean checkHttpRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
public abstract void enrichFirebusRequest(HttpServletRequest req, Payload payload) throws ServletException, IOException;
public abstract void enrichAuthResponse(String username, HttpServletResponse resp) throws ServletException, IOException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy