Search in sources :

Example 1 with LDAPUrl

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;
}
Also used : ST(org.stringtemplate.v4.ST) AzException(com.tremolosecurity.proxy.az.AzException) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) CustomAuthorization(com.tremolosecurity.proxy.az.CustomAuthorization) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPUrl(com.novell.ldap.LDAPUrl) LDAPException(com.novell.ldap.LDAPException)

Example 2 with LDAPUrl

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();
}
Also used : LDAPUrl(com.novell.ldap.LDAPUrl)

Aggregations

LDAPUrl (com.novell.ldap.LDAPUrl)2 LDAPEntry (com.novell.ldap.LDAPEntry)1 LDAPException (com.novell.ldap.LDAPException)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1 AzException (com.tremolosecurity.proxy.az.AzException)1 CustomAuthorization (com.tremolosecurity.proxy.az.CustomAuthorization)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 ST (org.stringtemplate.v4.ST)1