use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.
the class ConfigurationFactory method generateWebKeys.
private void generateWebKeys() {
log.info("Failed to load JWKS. Attempting to generate new JWKS...");
String newWebKeys = null;
try {
final AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(getAppConfiguration());
// Generate new JWKS
JSONObject jsonObject = AbstractCryptoProvider.generateJwks(cryptoProvider, getAppConfiguration());
newWebKeys = jsonObject.toString();
// Attempt to load new JWKS
jwks = ServerUtil.createJsonMapper().readValue(newWebKeys, WebKeysConfiguration.class);
// Store new JWKS in LDAP
Conf conf = loadConfigurationFromLdap();
conf.setWebKeys(jwks);
long nextRevision = conf.getRevision() + 1;
conf.setRevision(nextRevision);
final PersistenceEntryManager ldapManager = persistenceEntryManagerInstance.get();
ldapManager.merge(conf);
log.info("Generated new JWKS successfully.");
log.trace("JWKS keys: " + conf.getWebKeys().getKeys().stream().map(JSONWebKey::getKid).collect(Collectors.toList()));
log.trace("KeyStore keys: " + cryptoProvider.getKeys());
} catch (Exception ex2) {
log.error("Failed to re-generate JWKS keys", ex2);
}
}
use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.
the class ConfigurationFactory method loadConfigurationFromLdap.
private Conf loadConfigurationFromLdap(String... returnAttributes) {
final PersistenceEntryManager ldapManager = persistenceEntryManagerInstance.get();
final String dn = this.baseConfiguration.getString("oxauth_ConfigurationEntryDN");
try {
final Conf conf = ldapManager.find(dn, Conf.class, returnAttributes);
return conf;
} catch (BasePersistenceException ex) {
ex.printStackTrace();
log.error(ex.getMessage());
}
return null;
}
use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.
the class AppInitializer method closePersistenceEntryManagers.
private void closePersistenceEntryManagers(List<PersistenceEntryManager> oldPersistenceEntryManagers) {
// Close existing connections
for (PersistenceEntryManager oldPersistenceEntryManager : oldPersistenceEntryManagers) {
log.debug("Attempting to destroy {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceEntryManager);
oldPersistenceEntryManager.destroy();
log.debug("Destroyed {}: {}", ApplicationFactory.PERSISTENCE_AUTH_ENTRY_MANAGER_NAME, oldPersistenceEntryManager);
externalPersistenceExtensionService.executePersistenceExtensionAfterDestroy(oldPersistenceEntryManager);
}
}
use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.
the class AppInitializer method createPersistenceAuthEntryManager.
/*
* Utility method which can be used in custom scripts
*/
public PersistenceEntryManager createPersistenceAuthEntryManager(GluuLdapConfiguration persistenceAuthConfig) {
PersistenceEntryManagerFactory persistenceEntryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory();
Properties persistenceConnectionProperties = prepareAuthConnectionProperties(persistenceAuthConfig, persistenceEntryManagerFactory.getPersistenceType());
PersistenceEntryManager persistenceAuthEntryManager = persistenceEntryManagerFactory.createEntryManager(persistenceConnectionProperties);
log.debug("Created custom authentication PersistenceEntryManager: {}", persistenceAuthEntryManager);
externalPersistenceExtensionService.executePersistenceExtensionAfterCreate(persistenceConnectionProperties, persistenceAuthEntryManager);
return persistenceAuthEntryManager;
}
use of org.gluu.persist.PersistenceEntryManager in project oxAuth by GluuFederation.
the class AppInitializer method recreatePersistanceEntryManagerImpl.
protected void recreatePersistanceEntryManagerImpl(Instance<PersistenceEntryManager> instance, String persistenceEntryManagerName, Annotation... qualifiers) {
// Get existing application scoped instance
PersistenceEntryManager oldPersistenceEntryManager = CdiUtil.getContextBean(beanManager, PersistenceEntryManager.class, persistenceEntryManagerName);
// Close existing connections
closePersistenceEntryManager(oldPersistenceEntryManager, persistenceEntryManagerName);
// Force to create new bean
PersistenceEntryManager persistenceEntryManager = instance.get();
instance.destroy(persistenceEntryManager);
log.info("Recreated instance {}: {} with operation service: {}", persistenceEntryManagerName, persistenceEntryManager, persistenceEntryManager.getOperationService());
}
Aggregations