use of net.sourceforge.myvd.types.Attribute in project OpenUnison by TremoloSecurity.
the class MongoInsert method getRDN.
Attribute getRDN(String dn) {
if (dn.toLowerCase().startsWith("ou=")) {
return null;
} else {
int start = dn.indexOf('=');
String attr = dn.substring(0, start);
String val = dn.substring(start + 1, dn.indexOf(',', start + 1));
Attribute rdn = new Attribute(attr, val);
return rdn;
}
}
use of net.sourceforge.myvd.types.Attribute in project OpenUnison by TremoloSecurity.
the class AmazonSimpleDB method searchAmazonSimpleDB.
private Iterator<Item> searchAmazonSimpleDB(boolean users, Filter filter, ArrayList<Attribute> attributes) {
StringBuffer sqlWhere = new StringBuffer();
ArrayList<Object> vals = new ArrayList<Object>();
this.stringFilter(filter.getRoot(), sqlWhere, vals);
StringBuffer SQL = new StringBuffer();
SQL.append("SELECT ");
if (attributes.size() == 0) {
SQL.append("* ");
} else if (attributes.size() == 1 && attributes.get(0).equals("*")) {
SQL.append("* ");
} else if (attributes.size() == 1 && attributes.get(0).getAttribute().getName().equals("1.1")) {
SQL.append("uid ");
} else {
for (Attribute attr : attributes) {
SQL.append(attr.getAttribute().getName()).append(',');
}
SQL.setLength(SQL.length() - 1);
}
SQL.append(" FROM ").append('`');
if (users) {
SQL.append(this.userDomain);
} else {
SQL.append(this.groupDomain);
}
SQL.append("` WHERE ").append(sqlWhere);
if (logger.isDebugEnabled()) {
logger.debug("SQL : " + SQL.toString());
}
SelectResult res = this.sdb.select(new SelectRequest(SQL.toString()));
return res.getItems().iterator();
}
use of net.sourceforge.myvd.types.Attribute in project OpenUnison by TremoloSecurity.
the class AddGroupsFromProvisioningTarget method postSearchEntry.
public void postSearchEntry(PostSearchEntryInterceptorChain chain, Entry entry, DistinguishedName base, Int scope, Filter filter, ArrayList<Attribute> attributes, Bool typesOnly, LDAPSearchConstraints constraints) throws LDAPException {
chain.nextPostSearchEntry(entry, base, scope, filter, attributes, typesOnly, constraints);
if (logger.isDebugEnabled()) {
logger.debug("in post search entry");
}
boolean addAttr = false;
if (attributes == null || attributes.size() == 0 || attributes.get(0).getAttribute().getName().equalsIgnoreCase("*")) {
addAttr = true;
}
if (addAttr) {
for (Attribute attr : attributes) {
if (attr.getAttribute().getName().equalsIgnoreCase(this.attributeName)) {
addAttr = true;
break;
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Adding attribute : '" + addAttr + "'");
}
if (addAttr) {
// LDAPAttribute attr = new LDAPAttribute(this.attributeName);
try {
StringBuffer b = new StringBuffer();
LDAPAttribute userID = entry.getEntry().getAttribute(this.uidAttribute);
if (logger.isDebugEnabled()) {
logger.debug("Looking up user : '" + userID + "'");
}
if (userID != null) {
User user = GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(targetName).findUser(userID.getStringValue(), new HashMap<String, Object>());
if (logger.isDebugEnabled()) {
logger.debug("User returned : '" + user + "'");
}
if (user != null) {
if (logger.isDebugEnabled()) {
logger.debug("User groups : '" + user.getGroups() + "'");
}
if (user.getGroups().size() > 0) {
LDAPAttribute attr = entry.getEntry().getAttributeSet().getAttribute(this.attributeName);
if (attr == null) {
attr = new LDAPAttribute(this.attributeName);
entry.getEntry().getAttributeSet().add(attr);
}
if (this.targetRoleAttribute == null || this.targetRoleAttribute.isEmpty()) {
for (String groupName : user.getGroups()) {
b.setLength(0);
if (this.label.isEmpty()) {
b.append(groupName);
} else {
b.append(this.label).append(" - ").append(groupName);
}
attr.addValue(b.toString());
}
} else {
com.tremolosecurity.saml.Attribute targetAttr = user.getAttribs().get(this.targetRoleAttribute);
if (targetAttr != null) {
for (String val : targetAttr.getValues()) {
b.setLength(0);
b.append(this.label).append(" - ").append(val);
attr.addValue(b.toString());
}
}
}
}
}
}
} catch (Throwable t) {
logger.warn("Could not load user : '" + t.getMessage() + "'");
if (logger.isDebugEnabled()) {
logger.debug(t);
}
}
}
}
use of net.sourceforge.myvd.types.Attribute in project OpenUnison by TremoloSecurity.
the class ExternalGroupMembers method search.
@Override
public void search(SearchInterceptorChain chain, DistinguishedName base, Int scope, Filter filter, ArrayList<Attribute> attributes, Bool typesOnly, Results results, LDAPSearchConstraints constraints) throws LDAPException {
boolean add = false;
for (Attribute attr : attributes) {
if (attr.getAttribute().getName().equalsIgnoreCase(GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupMemberAttribute())) {
add = true;
}
}
if (add) {
ArrayList<Attribute> nattrs = new ArrayList<Attribute>();
nattrs.addAll(attributes);
Attribute attr = new Attribute(this.externalGroupAttrName);
nattrs.add(attr);
attributes = nattrs;
}
Filter nfilter = null;
try {
FilterNode nroot = (FilterNode) filter.getRoot().clone();
nfilter = new Filter(nroot);
} catch (CloneNotSupportedException e) {
throw new LDAPException("Could not clone filter", LDAPException.OPERATIONS_ERROR, "Could not clone filter", e);
}
this.searchExternal(nfilter.getRoot());
chain.nextSearch(base, scope, nfilter, attributes, typesOnly, results, constraints);
}
use of net.sourceforge.myvd.types.Attribute in project OpenUnison by TremoloSecurity.
the class AuthLockoutInsert method bind.
@Override
public void bind(BindInterceptorChain chain, DistinguishedName dn, Password pwd, LDAPConstraints constraints) throws LDAPException {
Results results = new Results(null, chain.getPositionInChain(this) + 1);
SearchInterceptorChain schain = chain.createSearchChain(chain.getPositionInChain(this) + 1);
schain.nextSearch(new DistinguishedName(dn.getDN()), new Int(0), new Filter("(objectClass=*)"), new ArrayList<Attribute>(), new Bool(false), results, new LDAPSearchConstraints());
results.start();
if (!results.hasMore()) {
throw new LDAPException("No such object", LDAPException.NO_SUCH_OBJECT, "Could not find dn");
}
Entry entry = results.next();
while (results.hasMore()) {
results.next();
}
try {
chain.nextBind(dn, pwd, constraints);
LDAPAttribute lastFailed = entry.getEntry().getAttributeSet().getAttribute(this.lastFailedAttribute);
LDAPAttribute numFailures = entry.getEntry().getAttributeSet().getAttribute(this.numFailedAttribute);
if (lastFailed != null && numFailures != null) {
long lastFailedTS = Long.parseLong(lastFailed.getStringValue());
int numPrevFailures = Integer.parseInt(numFailures.getStringValue());
long now = new DateTime(DateTimeZone.UTC).getMillis();
long lockedUntil = lastFailedTS + this.maxLockoutTime;
if (logger.isDebugEnabled()) {
logger.debug("Num Failed : " + numPrevFailures);
logger.debug("Last Failed : '" + lastFailedTS + "'");
logger.info("Now : '" + now + "'");
logger.info("Locked Until : '" + lockedUntil + "'");
logger.info("locked >= now? : '" + (lockedUntil >= now) + "'");
logger.info("max fails? : '" + this.maxFailedAttempts + "'");
logger.info("too many fails : '" + (numPrevFailures >= this.maxFailedAttempts) + "'");
}
if (lockedUntil >= now && numPrevFailures >= this.maxFailedAttempts) {
this.updateFailedAttrs(entry.getEntry());
throw new LDAPException("Invalid credentials", LDAPException.INVALID_CREDENTIALS, "User locked out");
}
}
this.updateSuccessAttrs(entry.getEntry());
} catch (LDAPException e) {
if (e.getResultCode() == LDAPException.INVALID_CREDENTIALS) {
this.updateFailedAttrs(entry.getEntry());
}
throw e;
}
}
Aggregations