use of net.sourceforge.myvd.types.Entry in project OpenUnison by TremoloSecurity.
the class AmazonSimpleDBEntrySet method getNextEntry.
private boolean getNextEntry() {
if (this.baseEntries != null && this.baseEntries.hasNext()) {
Entry tmpEntry = this.baseEntries.next();
if (filter.getRoot().checkEntry(tmpEntry.getEntry())) {
this.currEntry = tmpEntry;
this.entryFetched = false;
return true;
} else {
return getNextEntry();
}
} else if (this.userRes != null && this.userRes.hasNext()) {
Entry tmpEntry = createEntry(this.userRes.next(), true);
// if (filter.getRoot().checkEntry(tmpEntry.getEntry())) {
this.currEntry = tmpEntry;
this.entryFetched = false;
return true;
// } else {
// return getNextEntry();
// }
} else if (this.groupRes != null && this.groupRes.hasNext()) {
Entry tmpEntry = createEntry(this.groupRes.next(), false);
// if (filter.getRoot().checkEntry(tmpEntry.getEntry())) {
this.currEntry = tmpEntry;
this.entryFetched = false;
return true;
// } else {
// return getNextEntry();
// }
} else {
this.done = true;
return false;
}
}
use of net.sourceforge.myvd.types.Entry in project OpenUnison by TremoloSecurity.
the class AdminInsert 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 {
Entry luserEntry = new Entry(new LDAPEntry(userEntry.getDN(), (LDAPAttributeSet) userEntry.getAttributeSet().clone()));
Entry lrootEntry = new Entry(new LDAPEntry(userEntry.getDN(), (LDAPAttributeSet) userEntry.getAttributeSet().clone()));
ArrayList<Entry> res = new ArrayList<Entry>();
if (scope.getValue() == 0) {
if (base.getDN().toString().equalsIgnoreCase(rootEntry.getDN()) && filter.getRoot().checkEntry(rootEntry)) {
res.add(lrootEntry);
}
if (base.getDN().toString().equalsIgnoreCase(userEntry.getDN()) && filter.getRoot().checkEntry(userEntry)) {
res.add(luserEntry);
}
} else if (scope.getValue() == 1) {
if (base.getDN().toString().equalsIgnoreCase(rootEntry.getDN()) && filter.getRoot().checkEntry(userEntry)) {
res.add(luserEntry);
}
} else if (scope.getValue() == 2) {
if (base.getDN().toString().equalsIgnoreCase(rootEntry.getDN()) && filter.getRoot().checkEntry(rootEntry)) {
res.add(lrootEntry);
}
if (userEntry.getDN().toLowerCase().endsWith(base.getDN().toString().toLowerCase()) && filter.getRoot().checkEntry(userEntry)) {
res.add(luserEntry);
}
}
chain.addResult(results, new IteratorEntrySet(res.iterator()), base, scope, filter, attributes, typesOnly, constraints);
}
use of net.sourceforge.myvd.types.Entry 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;
}
}
use of net.sourceforge.myvd.types.Entry in project OpenUnison by TremoloSecurity.
the class AmazonSimpleDB 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 addBase = false;
boolean addUser = false;
boolean addGroups = false;
boolean searchUsers = false;
boolean searchGroups = false;
Filter filterToUser = null;
Iterator<Item> userResults = null;
Iterator<Item> groupResults = null;
try {
filterToUser = new Filter((FilterNode) filter.getRoot().clone());
} catch (CloneNotSupportedException e) {
}
if (scope.getValue() == 0) {
if (base.getDN().equals(this.baseDN)) {
addBase = true;
} else if (base.getDN().equals(this.userDN)) {
addUser = true;
} else if (base.getDN().equals(this.groupDN)) {
addGroups = true;
} else if (base.getDN().toString().endsWith(this.userDN.toString())) {
searchUsers = true;
filterToUser = this.addBaseToFilter(base, filterToUser);
} else if (base.getDN().toString().endsWith(this.groupDN.toString())) {
searchGroups = true;
filterToUser = this.addBaseToFilter(base, filterToUser);
} else {
throw new LDAPException("Object not found", LDAPException.NO_SUCH_OBJECT, base.getDN().toString());
}
} else if (scope.getValue() == 1) {
if (base.getDN().equals(this.baseDN)) {
addUser = true;
addGroups = true;
} else if (base.getDN().equals(userDN)) {
searchUsers = true;
// filterToUser = this.addBaseToFilter(base, filterToUser);
} else if (base.getDN().equals(groupDN)) {
searchGroups = true;
// filterToUser = this.addBaseToFilter(base, filterToUser);
}
} else if (scope.getValue() == 2) {
if (base.getDN().equals(this.baseDN)) {
addBase = true;
addUser = true;
addGroups = true;
searchUsers = true;
searchGroups = true;
// filterToUser = this.addBaseToFilter(base, filterToUser);
} else if (base.getDN().equals(userDN) || base.getDN().toString().endsWith(this.userDN.toString())) {
searchUsers = true;
// filterToUser = this.addBaseToFilter(base, filterToUser);
} else if (base.getDN().equals(groupDN) || base.getDN().toString().endsWith(this.groupDN.toString())) {
searchGroups = true;
// filterToUser = this.addBaseToFilter(base, filterToUser);
}
}
ArrayList<Entry> baseEntries = new ArrayList<Entry>();
if (addBase) {
baseEntries.add(new Entry(EntryUtil.createBaseEntry(this.baseDN)));
}
if (addUser) {
baseEntries.add(new Entry(EntryUtil.createBaseEntry(this.userDN)));
}
if (addGroups) {
baseEntries.add(new Entry(EntryUtil.createBaseEntry(this.groupDN)));
}
if (searchUsers) {
userResults = this.searchAmazonSimpleDB(true, filterToUser, attributes);
}
if (searchGroups) {
groupResults = this.searchAmazonSimpleDB(false, filterToUser, attributes);
}
chain.addResult(results, new AmazonSimpleDBEntrySet(this.baseDN.toString(), baseEntries.iterator(), userResults, groupResults, filterToUser), base, scope, filterToUser, attributes, typesOnly, constraints);
}
use of net.sourceforge.myvd.types.Entry in project OpenUnison by TremoloSecurity.
the class AmazonSimpleDBEntrySet method createEntry.
private Entry createEntry(Item item, boolean user) {
StringBuffer dnBuff = new StringBuffer();
LDAPAttribute objClass = null;
if (user) {
dnBuff.append("uid=").append(item.getName()).append(",ou=users,").append(this.dnBase);
objClass = new LDAPAttribute("objectClass", GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getUserObjectClass());
} else {
dnBuff.append("cn=").append(item.getName()).append(",ou=groups,").append(this.dnBase);
objClass = new LDAPAttribute("objectClass", GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getGroupObjectClass());
}
LDAPAttributeSet attrs = new LDAPAttributeSet();
for (Attribute fromAmz : item.getAttributes()) {
LDAPAttribute attr = attrs.getAttribute(fromAmz.getName());
if (attr == null) {
attr = new LDAPAttribute(fromAmz.getName());
attrs.add(attr);
}
attr.addValue(fromAmz.getValue());
}
attrs.add(objClass);
return new Entry(new LDAPEntry(dnBuff.toString(), attrs));
}
Aggregations