Search in sources :

Example 41 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class AddAttribute method doTask.

@Override
public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException {
    String localName = this.renderTemplate(name, request);
    String localVal = this.renderTemplate(value, request);
    if (this.addToRequest) {
        if (this.remove) {
            request.remove(localName);
        } else {
            request.put(localName, localVal);
        }
    } else {
        if (this.remove) {
            Attribute attr = user.getAttribs().get(localName);
            if (attr != null) {
                if (localVal.isEmpty()) {
                    user.getAttribs().remove(localName);
                } else {
                    attr.getValues().remove(localVal);
                }
            }
        } else {
            Attribute attr = user.getAttribs().get(localName);
            if (attr == null) {
                attr = new Attribute(localName);
                user.getAttribs().put(localName, attr);
            }
            attr.getValues().add(localVal);
        }
    }
    return true;
}
Also used : Attribute(com.tremolosecurity.saml.Attribute)

Example 42 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class LDAPDynaicWorkflows method getAttributeEntry.

private String getAttributeEntry(String name, LDAPEntry entry, HashMap<String, Attribute> params) throws ProvisioningException {
    Attribute attrName = params.get(name);
    if (attrName == null) {
        return null;
    }
    LDAPAttribute attr = entry.getAttribute(attrName.getValues().get(0));
    if (attr != null) {
        return attr.getStringValue();
    } else {
        return null;
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) LDAPAttribute(com.novell.ldap.LDAPAttribute)

Example 43 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class MongoDBTarget method findUser.

public User findUser(String userID, Set<String> attributes, Map<String, Object> request) throws ProvisioningException {
    MongoIterable<String> colNames = mongo.getDatabase(this.database).listCollectionNames();
    for (String col : colNames) {
        FindIterable<Document> searchRes = mongo.getDatabase(this.database).getCollection(col).find(and(eq("objectClass", this.userObjectClass), eq(this.userIdAttribute, userID)));
        Document doc = searchRes.first();
        if (doc != null) {
            User user = new User(userID);
            for (String attrName : attributes) {
                Object o = doc.get(attrName);
                if (o != null) {
                    if (o instanceof List) {
                        List l = (List) o;
                        Attribute attr = new Attribute(attrName);
                        attr.getValues().addAll(l);
                        user.getAttribs().put(attrName, attr);
                    } else {
                        Attribute attr = new Attribute(attrName);
                        attr.getValues().add(o.toString());
                        user.getAttribs().put(attrName, attr);
                    }
                }
            }
            MongoIterable<String> colNamesG = mongo.getDatabase(this.database).listCollectionNames();
            for (String colG : colNamesG) {
                FindIterable<Document> searchResG = mongo.getDatabase(this.database).getCollection(colG).find(and(eq("objectClass", this.groupObjectClass), eq(this.groupMemberAttribute, doc.getString(this.groupUserIdAttribute))));
                for (Document g : searchResG) {
                    user.getGroups().add(g.getString(this.groupIdAttribute));
                }
            }
            user.getAttribs().put(this.collectionAttributeName, new Attribute(this.collectionAttributeName, col));
            user.getAttribs().put("_id", new Attribute("_id", doc.getObjectId("_id").toString()));
            return user;
        }
    }
    // if we're here, there's no entry in the mongo
    if (this.supportExternalUsers) {
        try {
            LDAPSearchResults res = this.searchExternalUser(userID);
            if (!res.hasMore()) {
                return null;
            } else {
                LDAPEntry ldap = res.next();
                LDAPAttribute attr = ldap.getAttribute(this.groupUserIdAttribute);
                if (attr == null) {
                    return null;
                }
                String groupMemberID = attr.getStringValue();
                User user = new User(userID);
                user.getAttribs().put(this.userIdAttribute, new Attribute(this.userIdAttribute, userID));
                MongoIterable<String> colNamesG = mongo.getDatabase(this.database).listCollectionNames();
                for (String colG : colNamesG) {
                    FindIterable<Document> searchResG = mongo.getDatabase(this.database).getCollection(colG).find(and(eq("objectClass", this.groupObjectClass), eq(this.groupMemberAttribute, groupMemberID)));
                    for (Document g : searchResG) {
                        user.getGroups().add(g.getString(this.groupIdAttribute));
                    }
                }
                return user;
            }
        } catch (LDAPException e) {
            throw new ProvisioningException("Error searching for external user", e);
        }
    } else {
        return null;
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) User(com.tremolosecurity.provisioning.core.User) LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) Document(org.bson.Document) LDAPEntry(com.novell.ldap.LDAPEntry) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) ProvisioningException(com.tremolosecurity.provisioning.core.ProvisioningException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 44 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class MongoDBTarget method deleteAttrsFromServer.

private void deleteAttrsFromServer(User user, boolean addOnly, Set<String> attributes, User fromServer, Document unsetChanges, HashMap<String, List<String>> valsToDel) {
    if (!addOnly) {
        for (String attrNameFromServer : fromServer.getAttribs().keySet()) {
            if (attributes.contains(attrNameFromServer)) {
                Attribute attrFromServer = fromServer.getAttribs().get(attrNameFromServer);
                Attribute attrFromUser = user.getAttribs().get(attrNameFromServer);
                if (attrFromUser == null) {
                    // attribute to be removed
                    ArrayList<String> vals = new ArrayList<String>();
                    vals.addAll(attrFromServer.getValues());
                    valsToDel.put(attrNameFromServer, vals);
                    unsetChanges.append(attrNameFromServer, "");
                }
            }
        }
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) ArrayList(java.util.ArrayList)

Example 45 with Attribute

use of com.tremolosecurity.saml.Attribute in project OpenUnison by TremoloSecurity.

the class MongoDBTarget method syncUserToServer.

private void syncUserToServer(User user, boolean addOnly, Set<String> attributes, User fromServer, Document addChanges, Document unsetChanges, HashMap<String, List<String>> valsToAdd, HashMap<String, List<String>> valsToDel) {
    for (String attrNameFromUser : user.getAttribs().keySet()) {
        if (attributes.contains(attrNameFromUser) && !attrNameFromUser.equalsIgnoreCase(this.collectionAttributeName) && !attrNameFromUser.equalsIgnoreCase("_id")) {
            Attribute attrFromUser = user.getAttribs().get(attrNameFromUser);
            Attribute attrFromServer = fromServer.getAttribs().get(attrNameFromUser);
            if (attrFromServer == null) {
                // doesnt exist, need to do an add
                addChanges.append(attrNameFromUser, attrFromUser.getValues());
                valsToAdd.put(attrNameFromUser, attrFromUser.getValues());
            } else {
                ArrayList<String> attrValsToAdd = new ArrayList<String>();
                ArrayList<String> attrValsToRm = new ArrayList<String>();
                HashSet<String> valsFromServer = new HashSet<String>();
                for (String val : fromServer.getAttribs().get(attrNameFromUser).getValues()) {
                    valsFromServer.add(val.toLowerCase());
                }
                for (String valUser : user.getAttribs().get(attrNameFromUser).getValues()) {
                    if (!valsFromServer.contains(valUser.toLowerCase())) {
                        // add the value
                        attrValsToAdd.add(valUser);
                    }
                }
                if (!addOnly) {
                    HashSet<String> valsFromUser = new HashSet<String>();
                    for (String val : user.getAttribs().get(attrNameFromUser).getValues()) {
                        valsFromUser.add(val.toLowerCase());
                    }
                    for (String val : fromServer.getAttribs().get(attrNameFromUser).getValues()) {
                        if (!valsFromUser.contains(val.toLowerCase())) {
                            attrValsToRm.add(val);
                        }
                    }
                }
                if (!attrValsToAdd.isEmpty() || !attrValsToRm.isEmpty()) {
                    ArrayList<String> newVals = new ArrayList<String>();
                    newVals.addAll(fromServer.getAttribs().get(attrNameFromUser).getValues());
                    newVals.removeAll(attrValsToRm);
                    newVals.addAll(attrValsToAdd);
                    valsToAdd.put(attrNameFromUser, attrValsToAdd);
                    if (!attrValsToRm.isEmpty()) {
                        valsToDel.put(attrNameFromUser, attrValsToRm);
                    }
                    if (newVals.isEmpty()) {
                        unsetChanges.append(attrNameFromUser, "");
                    } else {
                        if (newVals.size() > 1) {
                            addChanges.append(attrNameFromUser, newVals);
                        } else {
                            addChanges.append(attrNameFromUser, newVals.get(0));
                        }
                    }
                }
            }
        }
    }
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) Attribute(com.tremolosecurity.saml.Attribute) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Attribute (com.tremolosecurity.saml.Attribute)268 LDAPAttribute (com.novell.ldap.LDAPAttribute)90 HashMap (java.util.HashMap)89 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)87 IOException (java.io.IOException)69 ArrayList (java.util.ArrayList)53 LDAPException (com.novell.ldap.LDAPException)51 ServletException (javax.servlet.ServletException)48 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)46 AuthController (com.tremolosecurity.proxy.auth.AuthController)45 LDAPEntry (com.novell.ldap.LDAPEntry)43 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)43 HttpSession (javax.servlet.http.HttpSession)40 Gson (com.google.gson.Gson)35 User (com.tremolosecurity.provisioning.core.User)33 HttpServletRequest (javax.servlet.http.HttpServletRequest)33 UrlHolder (com.tremolosecurity.config.util.UrlHolder)31 UnsupportedEncodingException (java.io.UnsupportedEncodingException)30 AuthChainType (com.tremolosecurity.config.xml.AuthChainType)28 HashSet (java.util.HashSet)26