use of com.novell.ldap.LDAPUrl in project OpenUnison by TremoloSecurity.
the class AzSys method checkRule.
private boolean checkRule(AuthInfo authData, ConfigManager cfgMgr, ApplicationType at, boolean OK, HashMap<UUID, DateTime> azCache, AzRule rule, Map<String, Object> request) throws MalformedURLException {
String localConstraint = rule.getConstraint();
if (request != null) {
ST st = new ST(localConstraint, '$', '$');
for (String key : request.keySet()) {
st.add(key.replaceAll("[.]", "_"), request.get(key));
}
localConstraint = st.render();
}
switch(rule.getScope()) {
case DN:
if (authData.getUserDN().endsWith(localConstraint)) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
}
break;
case Group:
if (isUserInGroup(authData, cfgMgr, rule, localConstraint)) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
}
break;
case DynamicGroup:
if (isUserInGroup(authData, cfgMgr, rule, localConstraint)) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
} else {
ArrayList<String> attribs = new ArrayList<String>();
attribs.add("memberURL");
try {
LDAPSearchResults rs = cfgMgr.getMyVD().search(localConstraint, 0, "(objectClass=*)", attribs);
rs.hasMore();
LDAPEntry entry = rs.next();
String[] urls = entry.getAttribute("memberURL").getStringValueArray();
for (int i = 0; i < urls.length; i++) {
String url = urls[i];
LDAPUrl ldapUrl = new LDAPUrl(url);
if (ldapUrl.getScope() == 0) {
if (!authData.getUserDN().equalsIgnoreCase(ldapUrl.getDN())) {
continue;
}
} else if (ldapUrl.getScope() == 1) {
String oneLevelDN = authData.getUserDN().substring(authData.getUserDN().indexOf(',') + 1);
if (!ldapUrl.getDN().equalsIgnoreCase(oneLevelDN)) {
continue;
}
} else {
if (!authData.getUserDN().endsWith(ldapUrl.getDN())) {
continue;
}
}
net.sourceforge.myvd.types.Filter filter = new net.sourceforge.myvd.types.Filter(ldapUrl.getFilter());
if (this.checkEntry(filter.getRoot(), authData)) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
}
}
} catch (LDAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
case Filter:
try {
net.sourceforge.myvd.types.Filter filter = new net.sourceforge.myvd.types.Filter(localConstraint);
if (this.checkEntry(filter.getRoot(), authData)) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
}
} catch (LDAPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case Custom:
CustomAuthorization customAz = rule.getCustomAuthorization();
if (customAz == null) {
cfgMgr.getCustomAuthorizations().get(localConstraint);
}
if (customAz == null) {
logger.warn("Rule '" + localConstraint + "' does not exist, failing");
OK = false;
} else {
try {
if (customAz.isAuthorized(authData, rule.getCustomParameters())) {
OK = true;
if (azCache != null) {
azCache.put(rule.getGuid(), new DateTime().plus(at.getAzTimeoutMillis()));
}
}
} catch (AzException e) {
logger.warn("Could not run authorization", e);
}
}
break;
}
return OK;
}
use of com.novell.ldap.LDAPUrl in project OpenUnison by TremoloSecurity.
the class LdapCRL method init.
@Override
public void init(String name, HashMap<String, Attribute> init, ConfigManager mgr) throws Exception {
String url = init.get("crl." + name + ".path").getValues().get(0);
LDAPUrl ldapUrl = new LDAPUrl(url);
this.host = ldapUrl.getHost();
this.port = ldapUrl.getPort();
this.base = ldapUrl.getDN();
this.attribute = "certificateRevocationList;binary";
this.crl = getCRLFromLDAP();
}
Aggregations