Search in sources :

Example 11 with DN

use of com.novell.ldap.util.DN in project OpenUnison by TremoloSecurity.

the class AmazonDynamoDB method configure.

@Override
public void configure(String name, Properties props, NameSpace ns) throws LDAPException {
    this.name = name;
    this.accessKey = props.getProperty("accessKey");
    this.secretKey = props.getProperty("secretKey");
    this.userTable = props.getProperty("userTable");
    this.groupTable = props.getProperty("groupTable");
    this.userDN = new DN("ou=users," + ns.getBase().getDN().toString());
    this.groupDN = new DN("ou=groups," + ns.getBase().getDN().toString());
    this.baseDN = new DN(ns.getBase().getDN().toString());
    this.db = new AmazonDynamoDBClient(new BasicAWSCredentials(accessKey, secretKey));
}
Also used : DN(com.novell.ldap.util.DN) RDN(com.novell.ldap.util.RDN) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 12 with DN

use of com.novell.ldap.util.DN in project OpenUnison by TremoloSecurity.

the class MongoInsert method search.

public void search(SearchInterceptorChain chain, DistinguishedName base, Int scope, Filter filter, ArrayList<Attribute> attributes, Bool typesOnly, Results results, LDAPSearchConstraints constraints) throws LDAPException {
    boolean addBase = false;
    boolean addCollection = false;
    boolean oneEntry = false;
    boolean listCollections = false;
    boolean searchUsers = false;
    Bson mongoFilter = null;
    Filter filterToUser = null;
    try {
        filterToUser = new Filter((FilterNode) filter.getRoot().clone());
    } catch (CloneNotSupportedException e) {
    }
    String localBase = this.getLocalBase(base.getDN().toString());
    String collectionName = this.getCollection(localBase);
    Attribute rdn = null;
    if (!localBase.isEmpty()) {
        rdn = this.getRDN(localBase);
    }
    if (scope.getValue() == 0) {
        if (localBase.isEmpty()) {
            addBase = true;
        } else if (rdn == null) {
            addCollection = true;
        } else {
            oneEntry = true;
        }
    } else if (scope.getValue() == 1) {
        addBase = false;
        if (localBase.isEmpty()) {
            listCollections = true;
        } else {
            searchUsers = true;
        }
    } else {
        // scope == 2
        addBase = true;
        if (localBase.isEmpty()) {
            listCollections = true;
        }
        searchUsers = true;
    }
    // create results
    ArrayList<Entry> res = new ArrayList<Entry>();
    StringBuffer b = new StringBuffer();
    if (addBase) {
        this.addToEntry(new Entry(EntryUtil.createBaseEntry(new DN(this.nameSpace.getBase().getDN().toString()))), filter, res);
    }
    if (listCollections) {
        for (String ou : mongo.getDatabase(this.database).listCollectionNames()) {
            b.setLength(0);
            b.append("ou=").append(ou).append(",").append(this.nameSpace.getBase().getDN().toString());
            this.addToEntry(new Entry(EntryUtil.createBaseEntry(new DN(b.toString()))), filter, res);
        }
    }
    if (addCollection) {
        boolean found = false;
        for (String ou : mongo.getDatabase(this.database).listCollectionNames()) {
            if (ou.equalsIgnoreCase(collectionName)) {
                b.setLength(0);
                b.append("ou=").append(ou).append(",").append(this.nameSpace.getBase().getDN().toString());
                this.addToEntry(new Entry(EntryUtil.createBaseEntry(new DN(b.toString()))), filter, res);
                found = true;
            }
        }
        if (!found) {
            throw new LDAPException("Could not find object", LDAPException.NO_SUCH_OBJECT, LDAPException.resultCodeToString(LDAPException.NO_SUCH_OBJECT));
        }
    }
    if (oneEntry) {
        boolean found = false;
        for (String ou : mongo.getDatabase(this.database).listCollectionNames()) {
            if (ou.equalsIgnoreCase(collectionName)) {
                found = true;
            }
        }
        if (!found) {
            throw new LDAPException("Could not find object", LDAPException.NO_SUCH_OBJECT, LDAPException.resultCodeToString(LDAPException.NO_SUCH_OBJECT));
        }
        // first see if we get results with the filter
        ArrayList<FilterNode> children = new ArrayList<FilterNode>();
        children.add(new FilterNode(FilterType.EQUALS, rdn.getAttribute().getName(), rdn.getAttribute().getStringValue()));
        children.add(filterToUser.getRoot());
        FilterNode and = new FilterNode(FilterType.AND, children);
        mongoFilter = this.convertFilterToMongo(and);
        FindIterable<Document> searchRes = mongo.getDatabase(this.database).getCollection(collectionName).find(mongoFilter);
        if (searchRes == null) {
            // nothing, need to know if the object exists or if its just the filter that didn't match
            searchRes = mongo.getDatabase(this.database).getCollection(collectionName).find(eq(rdn.getAttribute().getName(), rdn.getAttribute().getStringValue()));
            if (searchRes == null) {
                throw new LDAPException("Could not find object", LDAPException.NO_SUCH_OBJECT, LDAPException.resultCodeToString(LDAPException.NO_SUCH_OBJECT));
            }
        } else {
            Document doc = searchRes.first();
            if (doc == null) {
                // nothing, need to know if the object exists or if its just the filter that didn't match
                searchRes = mongo.getDatabase(this.database).getCollection(collectionName).find(eq(rdn.getAttribute().getName(), rdn.getAttribute().getStringValue()));
                if (searchRes.first() == null) {
                    throw new LDAPException("Could not find object", LDAPException.NO_SUCH_OBJECT, LDAPException.resultCodeToString(LDAPException.NO_SUCH_OBJECT));
                }
            } else {
                res.add(createEntry(doc, collectionName));
            }
        }
    }
    if (searchUsers) {
        mongoFilter = this.convertFilterToMongo(filter.getRoot());
        if (collectionName != null) {
            boolean found = false;
            for (String ou : mongo.getDatabase(this.database).listCollectionNames()) {
                if (ou.equalsIgnoreCase(collectionName)) {
                    found = true;
                }
            }
            if (!found) {
                throw new LDAPException("Could not find object", LDAPException.NO_SUCH_OBJECT, LDAPException.resultCodeToString(LDAPException.NO_SUCH_OBJECT));
            }
            FindIterable<Document> searchRes = mongo.getDatabase(this.database).getCollection(collectionName).find(mongoFilter);
            for (Document doc : searchRes) {
                res.add(createEntry(doc, collectionName));
            }
        } else {
            for (String ou : mongo.getDatabase(this.database).listCollectionNames()) {
                FindIterable<Document> searchRes = mongo.getDatabase(this.database).getCollection(ou).find(mongoFilter);
                for (Document doc : searchRes) {
                    res.add(createEntry(doc, ou));
                }
            }
        }
    }
    chain.addResult(results, new IteratorEntrySet(res.iterator()), base, scope, filterToUser, attributes, typesOnly, constraints);
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(net.sourceforge.myvd.types.Attribute) FilterNode(net.sourceforge.myvd.types.FilterNode) ArrayList(java.util.ArrayList) DN(com.novell.ldap.util.DN) Document(org.bson.Document) Bson(org.bson.conversions.Bson) IteratorEntrySet(net.sourceforge.myvd.util.IteratorEntrySet) Entry(net.sourceforge.myvd.types.Entry) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPException(com.novell.ldap.LDAPException) Filter(net.sourceforge.myvd.types.Filter)

Example 13 with DN

use of com.novell.ldap.util.DN in project OpenUnison by TremoloSecurity.

the class SetupGroupMetadataWatch method addMapping.

public synchronized void addMapping(String k8s, String ext) {
    ext = ext.toLowerCase();
    k8s = k8s.toLowerCase();
    if (extIsDN) {
        DN dn = new DN(ext);
        ext = dn.toString();
    }
    List<String> k8sFromExt = ext2k8s.get(ext);
    if (k8sFromExt == null) {
        k8sFromExt = new ArrayList<String>();
        ext2k8s.put(ext, k8sFromExt);
    }
    k8sFromExt.add(k8s);
    k8s2ext.put(k8s, ext);
}
Also used : DN(com.novell.ldap.util.DN)

Example 14 with DN

use of com.novell.ldap.util.DN in project OpenUnison by TremoloSecurity.

the class SetupGroupMetadataWatch method deleteMapping.

public synchronized void deleteMapping(String k8s, String ext) {
    ext = ext.toLowerCase();
    k8s = k8s.toLowerCase();
    if (extIsDN) {
        DN dn = new DN(ext);
        ext = dn.toString();
    }
    String keyToDel = null;
    String valToDel = null;
    for (String key : ext2k8s.keySet()) {
        for (String val : ext2k8s.get(key)) {
            if (val.equalsIgnoreCase(k8s)) {
                keyToDel = key;
                valToDel = val;
            }
        }
    }
    ext2k8s.get(keyToDel).remove(valToDel);
    if (ext2k8s.get(keyToDel).size() == 0) {
        ext2k8s.remove(keyToDel);
    }
    keyToDel = null;
    for (String key : k8s2ext.keySet()) {
        if (k8s2ext.get(key).equalsIgnoreCase(ext)) {
            keyToDel = key;
        }
    }
    k8s2ext.remove(keyToDel);
}
Also used : DN(com.novell.ldap.util.DN)

Example 15 with DN

use of com.novell.ldap.util.DN in project OpenUnison by TremoloSecurity.

the class OpenShiftInsert method configure.

@Override
public void configure(String name, Properties props, NameSpace nameSpace) throws LDAPException {
    this.name = name;
    this.baseDN = new DN(nameSpace.getBase().getDN().toString());
    this.osTarget = props.getProperty("osTargetName");
}
Also used : DN(com.novell.ldap.util.DN) RDN(com.novell.ldap.util.RDN)

Aggregations

DN (com.novell.ldap.util.DN)15 RDN (com.novell.ldap.util.RDN)6 ArrayList (java.util.ArrayList)5 LDAPAttribute (com.novell.ldap.LDAPAttribute)3 LDAPException (com.novell.ldap.LDAPException)3 Attribute (com.tremolosecurity.saml.Attribute)3 List (java.util.List)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 LDAPEntry (com.novell.ldap.LDAPEntry)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Attribute (net.sourceforge.myvd.types.Attribute)2 Filter (net.sourceforge.myvd.types.Filter)2 IteratorEntrySet (net.sourceforge.myvd.util.IteratorEntrySet)2 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)1 AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 LDAPSearchConstraints (com.novell.ldap.LDAPSearchConstraints)1 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)1