use of com.tremolosecurity.proxy.auth.AuthInfo in project OpenUnison by TremoloSecurity.
the class AppConfig method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
synchronized (this.appConfig) {
if (this.appConfig.cookieName == null) {
this.loadConfigData(this.filterConfig);
}
if (this.appConfig.cookieName == null) {
response.sendError(401);
return;
}
}
request.setAttribute("com.tremolosecurity.unison.proxy.noRedirectOnError", "com.tremolosecurity.unison.proxy.noRedirectOnError");
ArrayList<Cookie> sessionCookies = request.getCookies(this.appConfig.cookieName);
if (sessionCookies == null || sessionCookies.isEmpty()) {
response.sendError(401);
} else {
for (Cookie cookie : sessionCookies) {
TremoloHttpSession session = SessionManagerImpl.findSessionFromCookie(cookie, this.appConfig.secretKey, (SessionManagerImpl) GlobalEntries.getGlobalEntries().get(ProxyConstants.TREMOLO_SESSION_MANAGER));
if (session == null) {
response.sendError(401);
} else {
AuthInfo userData = ((AuthController) session.getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
if (userData == null || !userData.isAuthComplete() || userData.getAuthLevel() == 0) {
response.sendError(401);
} else {
SessionInfo si = new SessionInfo();
if (this.appConfig.timeoutSeconds > 0) {
ExternalSessionExpires extSession = (ExternalSessionExpires) session.getAttribute(SessionManagerImpl.TREMOLO_EXTERNAL_SESSION);
int extMinLeft = -1;
int stdMinLeft = -1;
if (extSession != null) {
long expires = extSession.getExpires();
if (expires <= 0) {
extMinLeft = -1;
} else {
extMinLeft = (int) ((expires - System.currentTimeMillis()) / 1000 / 60);
}
}
DateTime lastAccessed = (DateTime) session.getAttribute(SessionManagerImpl.TREMOLO_SESSION_LAST_ACCESSED);
DateTime now = new DateTime();
DateTime expires = lastAccessed.plusSeconds(this.appConfig.timeoutSeconds);
stdMinLeft = (int) ((expires.getMillis() - System.currentTimeMillis()) / 1000 / 60);
if (extMinLeft > stdMinLeft) {
si.setMinsLeft(extMinLeft);
} else {
si.setMinsLeft(stdMinLeft);
}
} else {
si.setMinsLeft(-1);
}
String json = gson.toJson(si);
response.setContentType("application/json");
response.getWriter().println(json.trim());
response.sendError(200);
}
}
}
}
}
use of com.tremolosecurity.proxy.auth.AuthInfo in project OpenUnison by TremoloSecurity.
the class ExecuteWorkflow method doFilter.
@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
if (request.getSession().getAttribute("TREMOLO_WF_EXEC") == null) {
AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
UrlHolder holder = (UrlHolder) request.getAttribute(ProxyConstants.AUTOIDM_CFG);
holder.getConfig().getProvisioningEngine().getWorkFlow(workFlowName).executeWorkflow(userData, uidAttrName);
request.getSession().setAttribute("TREMOLO_WF_EXEC", "FALSE");
}
chain.nextFilter(request, response, chain);
}
use of com.tremolosecurity.proxy.auth.AuthInfo in project OpenUnison by TremoloSecurity.
the class ListOrgs method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userID = req.getParameter("uid");
String uidAttr = req.getParameter("uidAttr");
try {
StringBuffer b = new StringBuffer();
b.append("(").append(uidAttr).append("=").append(userID).append(")");
LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
if (!res.hasMore()) {
throw new ProvisioningException("Could not locate user '" + userID + "'");
}
LDAPEntry entry = res.next();
AuthInfo auinfo = new AuthInfo();
auinfo.setUserDN(entry.getDN());
LDAPAttributeSet attrs = entry.getAttributeSet();
for (Object obj : attrs) {
LDAPAttribute attr = (LDAPAttribute) obj;
Attribute attrib = new Attribute(attr.getName());
String[] vals = attr.getStringValueArray();
for (String val : vals) {
attrib.getValues().add(val);
}
auinfo.getAttribs().put(attrib.getName(), attrib);
}
AzSys az = new AzSys();
OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
Organization org = new Organization();
copyOrg(org, ot, az, auinfo);
Gson gson = new Gson();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(true);
pres.setOrg(org);
resp.getOutputStream().print(gson.toJson(pres));
} catch (Exception e) {
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not load orgs : " + e.getMessage());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(false);
res.setError(pe);
Gson gson = new Gson();
resp.getWriter().write(gson.toJson(res));
logger.error("Could not load orgs", e);
}
}
use of com.tremolosecurity.proxy.auth.AuthInfo in project OpenUnison by TremoloSecurity.
the class ListPortalURLs method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userID = req.getParameter("uid");
String uidAttr = req.getParameter("uidAttr");
ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager();
try {
StringBuffer b = new StringBuffer();
LDAPSearchResults res = cfgMgr.getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
if (!res.hasMore()) {
throw new ProvisioningException("Could not locate user '" + userID + "'");
}
LDAPEntry entry = res.next();
AuthInfo auinfo = new AuthInfo();
auinfo.setUserDN(entry.getDN());
LDAPAttributeSet attrs = entry.getAttributeSet();
for (Object obj : attrs) {
LDAPAttribute attr = (LDAPAttribute) obj;
Attribute attrib = new Attribute(attr.getName());
String[] vals = attr.getStringValueArray();
for (String val : vals) {
attrib.getValues().add(val);
}
auinfo.getAttribs().put(attrib.getName(), attrib);
}
AzSys az = new AzSys();
PortalUrlsType pt = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getPortal();
PortalURLs urls = new PortalURLs();
for (PortalUrlType url : pt.getUrls()) {
if (url.getAzRules() != null && url.getAzRules().getRule().size() > 0) {
ArrayList<AzRule> rules = new ArrayList<AzRule>();
for (AzRuleType art : url.getAzRules().getRule()) {
rules.add(new AzRule(art.getScope(), art.getConstraint(), art.getClassName(), cfgMgr, null));
}
if (!az.checkRules(auinfo, GlobalEntries.getGlobalEntries().getConfigManager(), rules, null)) {
continue;
}
}
PortalURL purl = new PortalURL();
purl.setName(url.getName());
purl.setLabel(url.getLabel());
purl.setOrg(url.getOrg());
purl.setUrl(url.getUrl());
purl.setIcon(url.getIcon());
urls.getUrls().add(purl);
}
Gson gson = new Gson();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(true);
pres.setPortalURLs(urls);
resp.getOutputStream().print(gson.toJson(pres));
} catch (Exception e) {
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not load urls : " + e.getMessage());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(false);
res.setError(pe);
Gson gson = new Gson();
resp.getWriter().write(gson.toJson(res));
logger.error("Could not load urls", e);
}
}
use of com.tremolosecurity.proxy.auth.AuthInfo in project OpenUnison by TremoloSecurity.
the class ListReports method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String userID = req.getParameter("uid");
String uidAttr = req.getParameter("uidAttr");
try {
StringBuffer b = new StringBuffer();
LDAPSearchResults res = GlobalEntries.getGlobalEntries().getConfigManager().getMyVD().search(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getLdapRoot(), 2, equal(uidAttr, userID).toString(), new ArrayList<String>());
if (!res.hasMore()) {
throw new ProvisioningException("Could not locate user '" + userID + "'");
}
LDAPEntry entry = res.next();
AuthInfo auinfo = new AuthInfo();
auinfo.setUserDN(entry.getDN());
LDAPAttributeSet attrs = entry.getAttributeSet();
for (Object obj : attrs) {
LDAPAttribute attr = (LDAPAttribute) obj;
Attribute attrib = new Attribute(attr.getName());
String[] vals = attr.getStringValueArray();
for (String val : vals) {
attrib.getValues().add(val);
}
auinfo.getAttribs().put(attrib.getName(), attrib);
}
AzSys az = new AzSys();
HashSet<String> allowedOrgs = new HashSet<String>();
OrgType root = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg();
this.checkOrg(allowedOrgs, root, az, auinfo);
ReportsType reports = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getReports();
ReportsList reportsList = new ReportsList();
reportsList.setReports(new ArrayList<ReportInformation>());
for (ReportType report : reports.getReport()) {
if (allowedOrgs.contains(report.getOrgID())) {
ReportInformation ri = new ReportInformation();
ri.setName(report.getName());
ri.setDescription(report.getDescription());
ri.setOrgID(report.getOrgID());
ri.setParameters(new ArrayList<String>());
ri.getParameters().addAll(report.getParamater());
reportsList.getReports().add(ri);
}
}
Gson gson = new Gson();
ProvisioningResult pres = new ProvisioningResult();
pres.setSuccess(true);
pres.setReportsList(reportsList);
resp.getOutputStream().print(gson.toJson(pres));
} catch (Exception e) {
ProvisioningError pe = new ProvisioningError();
pe.setError("Could not load urls : " + e.getMessage());
ProvisioningResult res = new ProvisioningResult();
res.setSuccess(false);
res.setError(pe);
Gson gson = new Gson();
resp.getWriter().write(gson.toJson(res));
logger.error("Could not load urls", e);
}
}
Aggregations