use of com.tremolosecurity.proxy.auth.AuthController in project OpenUnison by TremoloSecurity.
the class UserToJSON method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
HttpSession session = request.getSession();
AuthController actl = (AuthController) session.getAttribute(ProxyConstants.AUTH_CTL);
if (actl == null) {
throw new Exception("No authentication");
}
if (actl.getAuthInfo() != null) {
AuthInfo authInfo = actl.getAuthInfo();
if (authInfo.getAttribs().containsKey("UserJSON")) {
authInfo.getAttribs().remove("UserJSON");
}
Gson gson = new Gson();
String ret = gson.toJson(authInfo);
if (doProxy) {
chain.setNoProxy(false);
authInfo.getAttribs().put("UserJSON", new Attribute("UserJSON", ret));
chain.nextFilter(request, response, chain);
} else {
response.addHeader("UserJSON", ret);
chain.setNoProxy(true);
}
}
}
use of com.tremolosecurity.proxy.auth.AuthController in project OpenUnison by TremoloSecurity.
the class LastMile method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
DateTime notBefore = new DateTime();
notBefore = notBefore.minusSeconds(timeScew);
DateTime notAfter = new DateTime();
notAfter = notAfter.plusSeconds(timeScew);
AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
com.tremolosecurity.lastmile.LastMile lastmile = new com.tremolosecurity.lastmile.LastMile(request.getRequestURI(), notBefore, notAfter, userData.getAuthLevel(), userData.getAuthChain());
Iterator<String> it = this.headers.keySet().iterator();
while (it.hasNext()) {
String fromUser = it.next();
String toApp = this.headers.get(fromUser);
Attribute attrib = userData.getAttribs().get(fromUser);
request.removeHeader(toApp);
if (logger.isDebugEnabled()) {
logger.debug("Header to add : " + fromUser);
}
if (attrib != null) {
if (logger.isDebugEnabled()) {
logger.debug("Attribute " + fromUser + "='" + attrib.getValues() + "' for " + userData.getUserDN());
}
Attribute toAppAttrib = new Attribute(toApp);
toAppAttrib.getValues().addAll(attrib.getValues());
lastmile.getAttributes().add(toAppAttrib);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Attribute " + fromUser + " is not available for " + userData.getUserDN());
}
}
}
String encryptedXML = lastmile.generateLastMileToken(encKey);
if (this.headerPrefix != null && !this.headerPrefix.isEmpty()) {
StringBuffer b = new StringBuffer();
b.append(this.headerPrefix).append(' ').append(encryptedXML);
encryptedXML = b.toString();
}
request.addHeader(new Attribute(this.headerName, encryptedXML));
// response.addHeader(this.headerName, requestKey.getEncrypted());
chain.nextFilter(request, response, chain);
}
use of com.tremolosecurity.proxy.auth.AuthController in project OpenUnison by TremoloSecurity.
the class LastMileJSON method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
chain.setNoProxy(true);
ConfigManager cfgMgr = (ConfigManager) request.getAttribute(ProxyConstants.TREMOLO_CFG_OBJ);
PrintWriter out = response.getWriter();
out.println("<html><head>");
out.println("<script type=\"text/javascript\">");
out.println(" function onBodyLoad() {");
out.println(" var element = document.getElementById(\"json\");");
// out.println(" alert(element.innerHTML);");
out.println(" window.javascriptAccessor.setJSON(element.innerHTML);");
out.println(" }");
out.println("</script></head><body onload=\"onBodyLoad()\">");
out.print("<div id=\"json\">");
DateTime notBefore = new DateTime().minusSeconds(secondsScew);
DateTime notAfter = new DateTime().plusSeconds(secondsToLive);
AuthController actl = (AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL);
com.tremolosecurity.lastmile.LastMile lmreq = new com.tremolosecurity.lastmile.LastMile(request.getRequestURI(), notBefore, notAfter, 1, "chainName");
lmreq.getAttributes().add(new Attribute("dn", actl.getAuthInfo().getUserDN()));
AccessTokenResponse resp = new AccessTokenResponse();
resp.setAccess_token(lmreq.generateLastMileToken(cfgMgr.getSecretKey(encKeyAlias)));
resp.setToken_type("bearer");
resp.setExpires_in(this.secondsToLive);
Gson gson = new Gson();
out.print(gson.toJson(resp));
out.print("</div></body></html>");
}
use of com.tremolosecurity.proxy.auth.AuthController in project OpenUnison by TremoloSecurity.
the class AnonAz method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
// SharedSession.getSharedSession().getSession(req.getSession().getId());
HttpSession session = request.getSession();
AuthController actl = (AuthController) session.getAttribute(ProxyConstants.AUTH_CTL);
if (actl == null) {
actl = new AuthController();
session.setAttribute(ProxyConstants.AUTH_CTL, actl);
}
if (actl.getAuthInfo() == null) {
AuthInfo authInfo = new AuthInfo(this.rdn, (String) session.getAttribute(ProxyConstants.AUTH_MECH_NAME), "anonymous", 0);
((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).setAuthInfo(authInfo);
authInfo.getAttribs().put(this.uidAttr, new Attribute(this.uidAttr, this.uidVal));
authInfo.getAttribs().put("objectClass", new Attribute("objectClass", GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getUserObjectClass()));
actl.setAuthInfo(authInfo);
}
chain.nextFilter(request, response, chain);
}
use of com.tremolosecurity.proxy.auth.AuthController in project OpenUnison by TremoloSecurity.
the class AzFilter method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
HttpSession session = request.getSession();
AuthInfo authData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
UrlHolder holder = (UrlHolder) request.getAttribute(ProxyConstants.AUTOIDM_CFG);
List<AzRuleType> rules = holder.getUrl().getAzRules().getRule();
boolean OK = az.checkRules(authData, holder.getConfig(), holder.getAzRules(), null);
if (OK) {
String respGroup = az.getResponseSuccessGroup(holder);
AccessLog.log(AccessEvent.AzSuccess, holder.getApp(), request.getServletRequest(), authData, respGroup != null ? respGroup : "NONE");
if (respGroup != null) {
az.processRequestResult(request.getServletRequest(), response.getServletResponse(), holder.getConfig().getResultGroup(respGroup), authData);
}
chain.nextFilter(request, response, chain);
if (respGroup != null) {
az.proccessResponseResult(request.getServletRequest(), response.getServletResponse(), holder.getConfig().getResultGroup(respGroup), false, authData, holder.getApp().getCookieConfig());
}
} else {
String respGroup = az.getResponseFailGroup(holder);
AccessLog.log(AccessEvent.AzFail, holder.getApp(), request.getServletRequest(), authData, respGroup != null ? respGroup : "NONE");
if (respGroup != null) {
az.proccessResponseResult(request.getServletRequest(), response.getServletResponse(), holder.getConfig().getResultGroup(respGroup), true, authData, holder.getApp().getCookieConfig());
} else {
((HttpServletResponse) response).sendError(401);
}
}
}
Aggregations