use of com.tremolosecurity.server.StopableThread in project OpenUnison by TremoloSecurity.
the class BrokerHolder method getInstance.
public static synchronized BrokerService getInstance(ConfigManager cfgMgr, String name, ProvisioningEngineImpl engine) throws ProvisioningException {
if (System.getenv("UNISON_NO_BROKER") != null && System.getenv("UNISON_NO_BROKER").equals("true")) {
return null;
}
if (holder != null) {
logger.info("Broker already initialized");
return holder.broker;
} else {
String path = System.getProperty(OpenUnisonConstants.UNISON_CONFIG_ACTIVEMQDIR);
File f = new File(path + File.separator + "unison-mq-" + name);
if (!f.exists()) {
f.mkdir();
}
logger.info("Starting KahaDB with path " + f.getAbsolutePath());
BrokerService littleBroker;
KahaDBPersistenceAdapter kdb = new KahaDBPersistenceAdapter();
kdb.setDirectory(f);
littleBroker = new BrokerService();
littleBroker.setBrokerName(name);
littleBroker.setPersistent(true);
f = new File(System.getProperty("java.io.tmpdir") + File.separator + "unison-tmp-mq-" + name);
if (!f.exists()) {
f.mkdir();
}
littleBroker.setTmpDataDirectory(f);
try {
littleBroker.setPersistenceAdapter(kdb);
} catch (IOException e1) {
throw new ProvisioningException("Could not initialize", e1);
}
StopableThread st = new BrokerThread(littleBroker, engine);
cfgMgr.addThread(st);
Thread t = new Thread(st);
t.start();
while (!littleBroker.isStarted()) {
logger.info("Waiting for broker to start...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
}
}
BrokerHolder littleholder = new BrokerHolder();
littleholder.cfgMgr = cfgMgr;
littleholder.broker = littleBroker;
try {
littleholder.initDLQ();
} catch (Exception e) {
logger.warn("Could not initiate DLQ checker", e);
}
holder = littleholder;
return holder.broker;
}
}
use of com.tremolosecurity.server.StopableThread in project OpenUnison by TremoloSecurity.
the class UnisonConfigManagerImpl method initialize.
/* (non-Javadoc)
* @see com.tremolosecurity.config.util.ConfigManager#initialize()
*/
/* (non-Javadoc)
* @see com.tremolosecurity.config.util.UnisonConfigManager#initialize()
*/
@Override
public void initialize(String name) throws JAXBException, Exception, IOException, FileNotFoundException, InstantiationException, IllegalAccessException, ClassNotFoundException, LDAPException, KeyStoreException, NoSuchAlgorithmException, CertificateException, ProvisioningException {
JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml");
Unmarshaller unmarshaller = jc.createUnmarshaller();
String path = configXML;
this.threads = new ArrayList<StopableThread>();
// path = path.substring(path.lastIndexOf('/') - 1);
// path = path.substring(path.lastIndexOf('/') - 1);
path = path.substring(0, path.lastIndexOf('/'));
JAXBElement<TremoloType> autoidmcfg = this.loadUnisonConfiguration(unmarshaller);
this.cfg = autoidmcfg.getValue();
this.byHost = new HashMap<String, ArrayList<UrlHolder>>();
this.cache = new HashMap<String, UrlHolder>();
this.upgradeManager = (HttpUpgradeRequestManager) Class.forName(this.cfg.getUpgradeHandler()).newInstance();
String myVdPath = cfg.getMyvdConfig();
this.loadKeystore(path, myVdPath);
this.initSSL();
this.loadMyVD(path, myVdPath);
if (cfg.getApplications().getErrorPage() != null) {
for (ErrorPage ep : cfg.getApplications().getErrorPage()) {
this.errorPages.put(ep.getCode(), ep.getLocation());
}
}
this.customAzRules = new HashMap<String, CustomAuthorization>();
if (this.cfg.getCustomAzRules() != null) {
for (CustomAzRuleType azrule : this.cfg.getCustomAzRules().getAzRule()) {
createCustomAuthorizationRule(azrule);
}
}
loadApplicationObjects();
this.authChains = new HashMap<String, AuthChainType>();
if (cfg.getAuthChains() != null) {
Iterator<AuthChainType> itac = cfg.getAuthChains().getChain().iterator();
while (itac.hasNext()) {
AuthChainType ac = itac.next();
this.authChains.put(ac.getName(), ac);
}
}
this.authMechs = new HashMap<String, MechanismType>();
if (cfg.getAuthMechs() != null) {
Iterator<MechanismType> itmt = cfg.getAuthMechs().getMechanism().iterator();
while (itmt.hasNext()) {
MechanismType mt = itmt.next();
authMechs.put(mt.getName(), mt);
}
}
this.resGroups = new HashMap<String, ResultGroupType>();
if (cfg.getResultGroups() != null) {
Iterator<ResultGroupType> itrgt = cfg.getResultGroups().getResultGroup().iterator();
while (itrgt.hasNext()) {
ResultGroupType rgt = itrgt.next();
this.resGroups.put(rgt.getName(), rgt);
}
}
this.apps = new HashMap<String, ApplicationType>();
Iterator<ApplicationType> itApp = cfg.getApplications().getApplication().iterator();
while (itApp.hasNext()) {
ApplicationType app = itApp.next();
this.apps.put(app.getName(), app);
}
this.provEnvgine = new ProvisioningEngineImpl(this);
this.provEnvgine.initWorkFlows();
this.provEnvgine.initMessageConsumers();
this.provEnvgine.initScheduler();
this.provEnvgine.initListeners();
this.provEnvgine.initReports();
try {
if (this.getCfg().getResultGroups() != null && this.getCfg().getResultGroups().getDynamicResultGroups() != null && this.getCfg().getResultGroups().getDynamicResultGroups().isEnabled()) {
DynamicPortalUrlsType dynamicResultGroups = this.getCfg().getResultGroups().getDynamicResultGroups();
String className = dynamicResultGroups.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicResultGroups.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicResultGroups dynResGroups = (DynamicResultGroups) Class.forName(className).newInstance();
dynResGroups.loadDynamicResultGroups(this, this.getProvisioningEngine(), cfgAttrs);
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize dynamic targets", e);
}
try {
if (this.getCfg().getCustomAzRules() != null && this.getCfg().getCustomAzRules().getDynamicCustomAuthorizations() != null && this.getCfg().getCustomAzRules().getDynamicCustomAuthorizations().isEnabled()) {
DynamicPortalUrlsType dynamicCustomAuthorization = this.getCfg().getCustomAzRules().getDynamicCustomAuthorizations();
String className = dynamicCustomAuthorization.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicCustomAuthorization.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicAuthorizations dynCustomAz = (DynamicAuthorizations) Class.forName(className).newInstance();
dynCustomAz.loadDynamicAuthorizations(this, this.getProvisioningEngine(), cfgAttrs);
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize dynamic targets", e);
}
try {
if (this.getCfg().getAuthChains() != null && this.getCfg().getAuthChains().getDynamicAuthChains() != null && this.getCfg().getAuthChains().getDynamicAuthChains().isEnabled()) {
DynamicPortalUrlsType dynamicAuthChains = this.getCfg().getAuthChains().getDynamicAuthChains();
String className = dynamicAuthChains.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicAuthChains.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicAuthChains dynAuthChains = (DynamicAuthChains) Class.forName(className).newInstance();
dynAuthChains.loadDynamicAuthChains(this, provEnvgine, cfgAttrs);
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize dynamic targets", e);
}
try {
if (this.getCfg().getApplications() != null && this.getCfg().getApplications().getDynamicApplications() != null && this.getCfg().getApplications().getDynamicApplications().isEnabled()) {
DynamicPortalUrlsType dynamicApps = this.getCfg().getApplications().getDynamicApplications();
String className = dynamicApps.getClassName();
HashMap<String, Attribute> cfgAttrs = new HashMap<String, Attribute>();
for (ParamType pt : dynamicApps.getParams()) {
Attribute attr = cfgAttrs.get(pt.getName());
if (attr == null) {
attr = new Attribute(pt.getName());
cfgAttrs.put(pt.getName(), attr);
}
attr.getValues().add(pt.getValue());
}
DynamicApplications dynApps = (DynamicApplications) Class.forName(className).newInstance();
dynApps.loadDynamicApplications(this, provEnvgine, cfgAttrs);
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new ProvisioningException("Could not initialize dynamic targets", e);
}
this.postInitialize();
}
use of com.tremolosecurity.server.StopableThread in project OpenUnison by TremoloSecurity.
the class MongoDBTarget method init.
public void init(Map<String, Attribute> cfg, ConfigManager cfgMgr, String name) throws ProvisioningException {
this.cfgMgr = cfgMgr;
this.name = name;
this.mongo = new MongoClient(new MongoClientURI(cfg.get("url").getValues().get(0)));
this.database = cfg.get("database").getValues().get(0);
this.userObjectClass = cfg.get("userObjectClass").getValues().get(0);
this.userRDN = cfg.get("userRDN").getValues().get(0);
this.userIdAttribute = cfg.get("userIdAttribute").getValues().get(0);
this.groupIdAttribute = cfg.get("groupIdAttribute").getValues().get(0);
this.groupObjectClass = cfg.get("groupObjectClass").getValues().get(0);
this.groupRDN = cfg.get("groupRDN").getValues().get(0);
this.groupMemberAttribute = cfg.get("groupMemberAttribute").getValues().get(0);
this.groupUserIdAttribute = cfg.get("groupUserIdAttribute").getValues().get(0);
this.supportExternalUsers = cfg.get("supportExternalUsers").getValues().get(0).equalsIgnoreCase("true");
this.collectionAttributeName = cfg.get("collectionAttributeName").getValues().get(0);
cfgMgr.addThread(new StopableThread() {
public void run() {
}
public void stop() {
mongo.close();
}
});
}
use of com.tremolosecurity.server.StopableThread in project OpenUnison by TremoloSecurity.
the class TokenData method init.
public void init(String idpName, ServletContext ctx, HashMap<String, Attribute> init, HashMap<String, HashMap<String, Attribute>> trustCfg, MapIdentity mapper) {
final String localIdPName = idpName;
this.idpName = idpName;
this.authURI = GlobalEntries.getGlobalEntries().getConfigManager().getApp(this.idpName).getUrls().getUrl().get(0).getUri();
try {
loadStaticTrusts(trustCfg);
} catch (Exception e1) {
logger.warn("could not load trusts", e1);
}
if (init.get("trustConfigurationClassName") != null) {
String className = init.get("trustConfigurationClassName").getValues().get(0);
DynamicLoadTrusts loadTrusts;
try {
loadTrusts = (DynamicLoadTrusts) Class.forName(className).newInstance();
loadTrusts.loadTrusts(idpName, ctx, init, trustCfg, mapper, this.trusts);
} catch (Exception e) {
logger.error("Could not initialize trusts", e);
}
}
this.amrToAuthChain = new HashMap<String, String>();
this.authChainToAmr = new HashMap<String, String>();
Attribute au2Amr = init.get("authChainToAmr");
if (au2Amr != null) {
for (String val : au2Amr.getValues()) {
String au = val.substring(0, val.indexOf('='));
String amr = val.substring(val.indexOf('=') + 1);
this.authChainToAmr.put(au, amr);
this.amrToAuthChain.put(amr, au);
}
}
this.mapper = mapper;
this.subAttribute = mapper.getSourceAttributeName("sub");
this.jwtSigningKeyName = init.get("jwtSigningKey").getValues().get(0);
HashMap<String, OpenIDConnectIdP> oidcIdPs = (HashMap<String, OpenIDConnectIdP>) GlobalEntries.getGlobalEntries().get(UNISON_OPENIDCONNECT_IDPS);
if (oidcIdPs == null) {
oidcIdPs = new HashMap<String, OpenIDConnectIdP>();
GlobalEntries.getGlobalEntries().set(UNISON_OPENIDCONNECT_IDPS, oidcIdPs);
}
oidcIdPs.put(this.idpName, this);
GlobalEntries.getGlobalEntries().getConfigManager().addThread(new StopableThread() {
@Override
public void run() {
// do nothing
}
@Override
public void stop() {
HashMap<String, OpenIDConnectIdP> oidcIdPs = (HashMap<String, OpenIDConnectIdP>) GlobalEntries.getGlobalEntries().get(UNISON_OPENIDCONNECT_IDPS);
if (oidcIdPs != null) {
OpenIDConnectIdP me = oidcIdPs.remove(localIdPName);
try {
me.getSessionStore().shutdown();
} catch (Exception e) {
logger.error("Could not shutdown session store", e);
}
}
}
});
String sessionStoreClassName = init.get("sessionStoreClassName") != null ? init.get("sessionStoreClassName").getValues().get(0) : "com.tremolosecurity.idp.providers.oidc.db.DbOidcSessionStore";
try {
this.sessionStore = (OidcSessionStore) Class.forName(sessionStoreClassName).newInstance();
this.sessionStore.init(localIdPName, ctx, init, trustCfg, mapper);
} catch (Exception e) {
logger.error("Could not initialize session store", e);
}
this.sessionKeyName = GlobalEntries.getGlobalEntries().getConfigManager().getApp(this.idpName).getCookieConfig().getKeyAlias();
if (init.get("updateClaimsClassName") != null) {
try {
this.claimsUpdater = (UpdateClaims) Class.forName(init.get("updateClaimsClassName").getValues().get(0)).newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
logger.error("Could not initialize claim updater", e);
}
}
if (init.get("scopes") != null) {
this.scopes = new HashSet<String>();
this.scopes.addAll(init.get("scopes").getValues());
}
}
use of com.tremolosecurity.server.StopableThread in project OpenUnison by TremoloSecurity.
the class DbOidcSessionStore method initializeHibernate.
private void initializeHibernate(String driver, String user, String password, String url, String dialect, int maxCons, int maxIdleCons, String validationQuery, String mappingFile, String createSchema) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
Configuration config = new Configuration();
config.setProperty("hibernate.connection.driver_class", driver);
config.setProperty("hibernate.connection.password", password);
config.setProperty("hibernate.connection.url", url);
config.setProperty("hibernate.connection.username", user);
config.setProperty("hibernate.dialect", dialect);
if (createSchema == null || createSchema.equalsIgnoreCase("true")) {
config.setProperty("hibernate.hbm2ddl.auto", "update");
}
config.setProperty("show_sql", "true");
config.setProperty("hibernate.current_session_context_class", "thread");
config.setProperty("hibernate.c3p0.max_size", Integer.toString(maxCons));
config.setProperty("hibernate.c3p0.maxIdleTimeExcessConnections", Integer.toString(maxIdleCons));
if (validationQuery != null && !validationQuery.isEmpty()) {
config.setProperty("hibernate.c3p0.testConnectionOnCheckout", "true");
}
config.setProperty("hibernate.c3p0.autoCommitOnClose", "true");
if (validationQuery == null) {
validationQuery = "SELECT 1";
}
config.setProperty("hibernate.c3p0.preferredTestQuery", validationQuery);
LoadedConfig lc = null;
if (mappingFile == null || mappingFile.trim().isEmpty()) {
JaxbCfgHibernateConfiguration jaxbCfg = new JaxbCfgHibernateConfiguration();
jaxbCfg.setSessionFactory(new JaxbCfgSessionFactory());
JaxbCfgMappingReferenceType mrt = new JaxbCfgMappingReferenceType();
mrt.setClazz(OidcDbSession.class.getName());
jaxbCfg.getSessionFactory().getMapping().add(mrt);
lc = LoadedConfig.consume(jaxbCfg);
} else {
lc = LoadedConfig.baseline();
}
StandardServiceRegistry registry = builder.configure(lc).applySettings(config.getProperties()).build();
try {
if (mappingFile == null || mappingFile.trim().isEmpty()) {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} else {
sessionFactory = new MetadataSources(registry).addResource(mappingFile).buildMetadata().buildSessionFactory();
}
GlobalEntries.getGlobalEntries().getConfigManager().addThread(new StopableThread() {
@Override
public void run() {
}
@Override
public void stop() {
logger.info("Stopping hibernate");
sessionFactory.close();
}
});
} catch (Exception e) {
e.printStackTrace();
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
}
}
Aggregations