use of com.unboundid.ldap.sdk.Filter in project oxAuth by GluuFederation.
the class ClientAuthorizationsService method findClientAuthorizations.
public ClientAuthorizations findClientAuthorizations(String userInum, String clientId) {
prepareBranch(userInum);
String baseDn = getBaseDnForClientAuthorizations(userInum);
Filter filter = Filter.createEqualityFilter("oxAuthClientId", clientId);
List<ClientAuthorizations> entries = ldapEntryManager.findEntries(baseDn, ClientAuthorizations.class, filter);
if (entries != null && !entries.isEmpty()) {
// if more then one entry then it's problem, non-deterministic behavior, id must be unique
if (entries.size() > 1) {
log.error("Found more then one client authorization entry by client Id: {}" + clientId);
for (ClientAuthorizations entry : entries) {
log.error(entry.toString());
}
}
return entries.get(0);
}
return null;
}
use of com.unboundid.ldap.sdk.Filter in project oxAuth by GluuFederation.
the class BaseAuthFilterService method loadEntryDN.
public String loadEntryDN(LdapEntryManager p_manager, AuthenticationFilterWithParameters authenticationFilterWithParameters, Map<String, String> normalizedAttributeValues) {
final String filter = buildFilter(authenticationFilterWithParameters, normalizedAttributeValues);
Filter ldapFilter;
try {
ldapFilter = Filter.create(filter);
} catch (LDAPException ex) {
log.error("Failed to create Ldap filter: '{}'", ex, filter);
return null;
}
List<LdapDummyEntry> foundEntries = p_manager.findEntries(authenticationFilterWithParameters.getAuthenticationFilter().getBaseDn(), LdapDummyEntry.class, new String[0], ldapFilter);
if (foundEntries.size() > 1) {
log.error("Found more than one entry by filter: '{}'. Entries:\n", ldapFilter, foundEntries);
return null;
}
if (!(foundEntries.size() == 1)) {
return null;
}
return foundEntries.get(0).getDn();
}
use of com.unboundid.ldap.sdk.Filter in project oxAuth by GluuFederation.
the class PairwiseIdentifierService method findPairWiseIdentifier.
public PairwiseIdentifier findPairWiseIdentifier(String userInum, String sectorIdentifierUri) throws Exception {
PairwiseIdType pairwiseIdType = PairwiseIdType.fromString(appConfiguration.getPairwiseIdType());
String sectorIdentifier = URI.create(sectorIdentifierUri).getHost();
if (PairwiseIdType.PERSISTENT == pairwiseIdType) {
prepareBranch(userInum);
String baseDnForPairwiseIdentifiers = getBaseDnForPairwiseIdentifiers(userInum);
Filter filter = Filter.createEqualityFilter("oxSectorIdentifier", sectorIdentifier);
List<PairwiseIdentifier> entries = ldapEntryManager.findEntries(baseDnForPairwiseIdentifiers, PairwiseIdentifier.class, filter);
if (entries != null && !entries.isEmpty()) {
// if more then one entry then it's problem, non-deterministic behavior, id must be unique
if (entries.size() > 1) {
log.error("Found more then one pairwise identifier by sector identifier: {}" + sectorIdentifier);
for (PairwiseIdentifier pairwiseIdentifier : entries) {
log.error("PairwiseIdentifier: {}", pairwiseIdentifier);
}
}
return entries.get(0);
}
} else {
// PairwiseIdType.ALGORITHMIC
String key = appConfiguration.getPairwiseCalculationKey();
String salt = appConfiguration.getPairwiseCalculationSalt();
String calculatedSub = SubjectIdentifierGenerator.generatePairwiseSubjectIdentifier(sectorIdentifierUri, userInum, key, salt, appConfiguration);
PairwiseIdentifier pairwiseIdentifier = new PairwiseIdentifier(sectorIdentifierUri);
pairwiseIdentifier.setId(calculatedSub);
return pairwiseIdentifier;
}
return null;
}
use of com.unboundid.ldap.sdk.Filter in project oxCore by GluuFederation.
the class LdapSampleBatchJob method main.
public static void main(String[] args) {
// Prepare sample connection details
LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
// Create LDAP entry manager
final LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
BatchOperation<SimpleTokenLdap> tokenLdapBatchOperation = new BatchOperation<SimpleTokenLdap>(ldapEntryManager) {
private int processedCount = 0;
@Override
protected List<SimpleTokenLdap> getChunkOrNull(int batchSize) {
log.info("Processed: " + processedCount);
final Filter filter = Filter.createPresenceFilter("oxAuthExpiration");
return ldapEntryManager.findEntries("o=gluu", SimpleTokenLdap.class, filter, SearchScope.SUB, new String[] { "oxAuthExpiration" }, this, 0, batchSize, batchSize);
}
@Override
protected void performAction(List<SimpleTokenLdap> objects) {
for (SimpleTokenLdap simpleTokenLdap : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute("oxAuthExpiration", simpleTokenLdap.getAttribute("oxAuthExpiration"));
simpleTokenLdap.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
ldapEntryManager.merge(simpleTokenLdap);
processedCount++;
} catch (EntryPersistenceException ex) {
log.error("Failed to update entry", ex);
}
}
}
};
tokenLdapBatchOperation.iterateAllByChunks(100);
BatchOperation<SimpleSession> sessionBatchOperation = new BatchOperation<SimpleSession>(ldapEntryManager) {
private int processedCount = 0;
@Override
protected List<SimpleSession> getChunkOrNull(int batchSize) {
log.info("Processed: " + processedCount);
final Filter filter = Filter.createPresenceFilter("oxLastAccessTime");
return ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter, SearchScope.SUB, new String[] { "oxLastAccessTime" }, this, 0, batchSize, batchSize);
}
@Override
protected void performAction(List<SimpleSession> objects) {
for (SimpleSession simpleSession : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute("oxLastAccessTime", simpleSession.getAttribute("oxLastAccessTime"));
simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
ldapEntryManager.merge(simpleSession);
processedCount++;
} catch (EntryPersistenceException ex) {
log.error("Failed to update entry", ex);
}
}
}
};
sessionBatchOperation.iterateAllByChunks(100);
}
use of com.unboundid.ldap.sdk.Filter in project oxCore by GluuFederation.
the class LdifDataUtility method getAttributeResultEntryLDIF.
public List<SearchResultEntry> getAttributeResultEntryLDIF(LDAPConnection connection, List<String> patterns, String baseDN) {
List<SearchResultEntry> searchResultEntryList = new ArrayList<SearchResultEntry>();
try {
for (String pattern : patterns) {
String[] targetArray = new String[] { pattern };
Filter inumFilter = Filter.createSubstringFilter("inum", null, targetArray, null);
Filter searchFilter = Filter.createORFilter(inumFilter);
SearchResultEntry sr = connection.searchForEntry(baseDN, SearchScope.SUB, searchFilter, null);
searchResultEntryList.add(sr);
}
return searchResultEntryList;
} catch (LDAPException le) {
if (le.getResultCode() != ResultCode.NO_SUCH_OBJECT) {
log.error("Failed to search ldif record", le);
return null;
}
}
return null;
}
Aggregations