use of org.gluu.persist.exception.mapping.EntryPersistenceException 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 ProcessBatchOperation<SimpleTokenLdap>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleTokenLdap> objects) {
for (SimpleTokenLdap simpleTokenLdap : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "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);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter1 = Filter.createPresenceFilter("oxAuthExpiration");
ldapEntryManager.findEntries("o=gluu", SimpleTokenLdap.class, filter1, SearchScope.SUB, new String[] { "oxAuthExpiration" }, tokenLdapBatchOperation, 0, 0, 100);
BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleSession> objects) {
for (SimpleSession simpleSession : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "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);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter2 = Filter.createPresenceFilter("oxLastAccessTime");
ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "oxLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter3 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
List<SimpleClient> result3 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation, 0, 0, 1000);
LOG.info("Result count (without collecting results): " + result3.size());
BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter4 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
List<SimpleClient> result4 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation2, 0, 0, 1000);
LOG.info("Result count (with collecting results): " + result4.size());
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxTrust by GluuFederation.
the class PersonImportAction method importPersons.
public String importPersons() throws Exception {
if (!fileDataToImport.isReady()) {
facesMessages.add(FacesMessage.SEVERITY_ERROR, "File to import is invalid");
return OxTrustConstants.RESULT_FAILURE;
}
log.info("Attempting to add {} persons", fileDataToImport.getPersons().size());
try {
for (GluuCustomPerson person : fileDataToImport.getPersons()) {
this.person = person;
String result = initializePerson();
if (result.equals(OxTrustConstants.RESULT_SUCCESS)) {
result = save();
}
if (result.equals(OxTrustConstants.RESULT_SUCCESS)) {
log.debug("Added new person: {}", person.getUid());
} else {
log.debug("Failed to add new person: {}", person.getUid());
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to add new person: '%s'", person.getUid());
}
}
} catch (EntryPersistenceException ex) {
log.error("Failed to add new person", ex);
facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to import users");
return OxTrustConstants.RESULT_FAILURE;
}
log.info("All {} persons added successfully", fileDataToImport.getPersons().size());
facesMessages.add(FacesMessage.SEVERITY_INFO, "Users successfully imported");
removeFileToImport();
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxTrust by GluuFederation.
the class GroupService method isMemberOrOwner.
/* (non-Javadoc)
* @see org.gluu.oxtrust.ldap.service.IGroupService#isMemberOrOwner(java.lang.String, java.lang.String)
*/
@Override
public boolean isMemberOrOwner(String groupDN, String personDN) {
Filter ownerFilter = Filter.createEqualityFilter(OxTrustConstants.owner, personDN);
Filter memberFilter = Filter.createEqualityFilter(OxTrustConstants.member, personDN);
Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
boolean isMemberOrOwner = false;
try {
isMemberOrOwner = ldapEntryManager.findEntries(groupDN, GluuGroup.class, searchFilter, 1).size() > 0;
} catch (EntryPersistenceException ex) {
log.error("Failed to determine if person '{}' memeber or owner of group '{}'", personDN, groupDN, ex);
}
return isMemberOrOwner;
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxTrust by GluuFederation.
the class ShibbolethInitializer method createShibbolethConfiguration.
public boolean createShibbolethConfiguration() {
boolean createConfig = appConfiguration.isConfigGeneration();
log.info("IDP config generation is set to " + createConfig);
if (createConfig) {
String gluuSPInum;
GluuSAMLTrustRelationship gluuSP;
try {
gluuSPInum = applianceService.getAppliance().getGluuSPTR();
// log.info("########## gluuSPInum = " + gluuSPInum);
gluuSP = new GluuSAMLTrustRelationship();
gluuSP.setDn(trustService.getDnForTrustRelationShip(gluuSPInum));
} catch (EntryPersistenceException ex) {
log.error("Failed to determine SP inum", ex);
return false;
}
// log.info("########## gluuSP.getDn() = " + gluuSP.getDn());
boolean servicesNeedRestarting = false;
// if (gluuSPInum == null || ! trustService.containsTrustRelationship(gluuSP)) {
//
// log.info("No trust relationships exist in LDAP. Adding gluuSP");
// GluuAppliance appliance = applianceService.getAppliance();
// appliance.setGluuSPTR(null);
// applianceService.updateAppliance(appliance);
// shibboleth3ConfService.addGluuSP();
// servicesNeedRestarting = true;
// }
gluuSP = trustService.getRelationshipByInum(applianceService.getAppliance().getGluuSPTR());
List<GluuSAMLTrustRelationship> trustRelationships = trustService.getAllActiveTrustRelationships();
/*
if (trustRelationships != null && !trustRelationships.isEmpty()) {
for (GluuSAMLTrustRelationship gluuSAMLTrustRelationship : trustRelationships) {
log.info("########## gluuSAMLTrustRelationship.getDn() = " + gluuSAMLTrustRelationship.getDn());
}
}
*/
String shibbolethVersion = appConfiguration.getShibbolethVersion();
log.info("########## shibbolethVersion = " + shibbolethVersion);
shibboleth3ConfService.generateMetadataFiles(gluuSP);
shibboleth3ConfService.generateConfigurationFiles(trustRelationships);
shibboleth3ConfService.removeUnusedCredentials();
shibboleth3ConfService.removeUnusedMetadata();
if (servicesNeedRestarting) {
applianceService.restartServices();
}
}
return true;
}
use of org.gluu.persist.exception.mapping.EntryPersistenceException in project oxTrust by GluuFederation.
the class CleanUpTest method cleanUpPersons.
/**
* Test search
*
* @throws Exception
*/
// @Test
@Parameters(value = "test.keep.persons")
public void cleanUpPersons(String usedPersons) throws Exception {
System.out.println("cleanup person Test initialted ");
assertNotNull(usedPersons);
List<String> usedPersonsList = Arrays.asList(StringHelper.split(usedPersons, ",", true, false));
System.out.println("Used persons: " + usedPersonsList);
int personsResultSetSize = 50;
int countResults = 0;
int countRemoved = 0;
boolean existsMorePersons = true;
while (existsMorePersons && countResults < 10000) {
List<GluuCustomPerson> persons = personService.findAllPersons(new String[] { "inum" });
existsMorePersons = persons.size() == personsResultSetSize;
countResults += persons.size();
assertNotNull(persons);
System.out.println("Found persons: " + persons.size());
System.out.println("Total persons: " + countResults);
for (GluuCustomPerson person : persons) {
// String clientId = person.getClientId();
if (!usedPersonsList.contains(person.getInum())) {
try {
memberService.removePerson(person);
countRemoved++;
} catch (EntryPersistenceException ex) {
System.out.println("Failed to remove person: " + ex.getMessage());
}
}
}
}
System.out.println("Removed Persons: " + countRemoved);
}
Aggregations