List of usage examples for org.apache.commons.configuration ConfigurationConverter getProperties
public static Properties getProperties(Configuration config)
From source file:org.apache.atlas.web.security.AtlasPamAuthenticationProvider.java
private Authentication getPamAuthentication(Authentication authentication) { try {//from w w w .ja va 2s .c o m DefaultJaasAuthenticationProvider jaasAuthenticationProvider = new DefaultJaasAuthenticationProvider(); String loginModuleName = "org.apache.atlas.web.security.PamLoginModule"; AppConfigurationEntry.LoginModuleControlFlag controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED; Properties properties = ConfigurationConverter .getProperties(ApplicationProperties.get().subset("atlas.authentication.method.pam")); Map<String, String> options = new HashMap<>(); for (String key : properties.stringPropertyNames()) { String value = properties.getProperty(key); options.put(key, value); } if (!options.containsKey("service")) options.put("service", "atlas-login"); AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry(loginModuleName, controlFlag, options); AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry }; Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>(); appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries); Configuration configuration = new InMemoryConfiguration(appConfigurationEntriesOptions); jaasAuthenticationProvider.setConfiguration(configuration); UserAuthorityGranter authorityGranter = new UserAuthorityGranter(); UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[] { authorityGranter }; jaasAuthenticationProvider.setAuthorityGranters(authorityGranters); jaasAuthenticationProvider.afterPropertiesSet(); String userName = authentication.getName(); String userPassword = ""; if (authentication.getCredentials() != null) { userPassword = authentication.getCredentials().toString(); } // getting user authenticated if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) { final List<GrantedAuthority> grantedAuths = getAuthorities(userName); final UserDetails principal = new User(userName, userPassword, grantedAuths); final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths); authentication = jaasAuthenticationProvider.authenticate(finalAuthentication); authentication = getAuthenticationWithGrantedAuthority(authentication); return authentication; } else { return authentication; } } catch (Exception e) { logger.debug("Pam Authentication Failed:", e); } return authentication; }
From source file:org.apache.gobblin.util.PullFileLoader.java
/** * Load a {@link Properties} compatible path using fallback as fallback. * @return The {@link Config} in path with fallback as fallback. * @throws IOException//from w w w. j a v a 2 s.c om */ private Config loadJavaPropsWithFallback(Path propertiesPath, Config fallback) throws IOException { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); try (InputStreamReader inputStreamReader = new InputStreamReader(this.fs.open(propertiesPath), Charsets.UTF_8)) { propertiesConfiguration.setDelimiterParsingDisabled(ConfigUtils.getBoolean(fallback, PROPERTY_DELIMITER_PARSING_ENABLED_KEY, DEFAULT_PROPERTY_DELIMITER_PARSING_ENABLED_KEY)); propertiesConfiguration.load(inputStreamReader); Config configFromProps = ConfigUtils .propertiesToConfig(ConfigurationConverter.getProperties(propertiesConfiguration)); return ConfigFactory .parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, PathUtils.getPathWithoutSchemeAndAuthority(propertiesPath).toString())) .withFallback(configFromProps).withFallback(fallback); } catch (ConfigurationException ce) { throw new IOException(ce); } }
From source file:org.apache.s4.comm.DefaultCommModule.java
private void loadProperties(Binder binder) { try {//from www.j a v a2 s . c o m config = new PropertiesConfiguration(); config.load(commConfigInputStream); // TODO - validate properties. /* Make all properties injectable. Do we need this? */ Names.bindProperties(binder, ConfigurationConverter.getProperties(config)); } catch (ConfigurationException e) { binder.addError(e); e.printStackTrace(); } }
From source file:org.apache.s4.core.BaseModule.java
@SuppressWarnings("serial") private void loadProperties(Binder binder) { try {//from w ww . j a va 2 s . c om config = new PropertiesConfiguration(); config.load(baseConfigInputStream); // TODO - validate properties. /* Make all properties injectable. Do we need this? */ Names.bindProperties(binder, ConfigurationConverter.getProperties(config)); if (clusterName != null) { if (config.containsKey("s4.cluster.name")) { logger.warn( "cluster [{}] passed as a parameter will not be used because an existing cluster.name parameter of value [{}] was found in the configuration file and will be used", clusterName, config.getProperty("s4.cluster.name")); } else { Names.bindProperties(binder, new HashMap<String, String>() { { put("s4.cluster.name", clusterName); } }); } } } catch (ConfigurationException e) { binder.addError(e); e.printStackTrace(); } }
From source file:org.apache.s4.core.DefaultCoreModule.java
private void loadProperties(Binder binder) { try {//www . j a v a 2 s . c o m config = new PropertiesConfiguration(); config.load(coreConfigFileInputStream); // TODO - validate properties. /* Make all properties injectable. Do we need this? */ Names.bindProperties(binder, ConfigurationConverter.getProperties(config)); } catch (ConfigurationException e) { binder.addError(e); e.printStackTrace(); } }
From source file:org.apache.s4.example.fluent.counter.Module.java
private void loadProperties(Binder binder) { try {// w w w . j av a 2 s . co m InputStream is = this.getClass().getResourceAsStream("/s4-counter-example.properties"); config = new PropertiesConfiguration(); config.load(is); System.out.println(ConfigurationUtils.toString(config)); // TODO - validate properties. /* Make all properties injectable. Do we need this? */ Names.bindProperties(binder, ConfigurationConverter.getProperties(config)); } catch (ConfigurationException e) { binder.addError(e); e.printStackTrace(); } }
From source file:org.debux.webmotion.jpa.Transactional.java
/** * Create the transaction and the GenericDAO if the entity name is not * empty or null.//from ww w . j a va 2s . c o m * * @param request set EntityManager, EntityTransaction and GenericDAO into the request * @param persistenceUnitName precise the persistence unit * @param packageEntityName precise the package of entity * @param entityName precise the class name of the entity * * @throws Exception catch execption to rollback the transaction */ public void tx(HttpServletRequest request, String persistenceUnitName, Properties properties, String packageEntityName, String entityName) throws Exception { // Create factory if (persistenceUnitName == null || persistenceUnitName.isEmpty()) { persistenceUnitName = DEFAULT_PERSISTENCE_UNIT_NAME; } EntityManagerFactory factory = factories.get(persistenceUnitName); if (factory == null) { Configuration subset = properties.subset(persistenceUnitName); java.util.Properties additionalProperties = ConfigurationConverter.getProperties(subset); factory = Persistence.createEntityManagerFactory(persistenceUnitName, additionalProperties); factories.put(persistenceUnitName, factory); } // Create manager EntityManager manager = (EntityManager) request.getAttribute(CURRENT_ENTITY_MANAGER); if (manager == null) { manager = factory.createEntityManager(); request.setAttribute(CURRENT_ENTITY_MANAGER, manager); } // Create generic DAO each time if callback an action on an other entity if (entityName != null) { String fullEntityName = null; if (packageEntityName != null && !packageEntityName.isEmpty()) { fullEntityName = packageEntityName + "." + entityName; } else { fullEntityName = entityName; } GenericDAO genericDAO = new GenericDAO(manager, fullEntityName); request.setAttribute(CURRENT_GENERIC_DAO, genericDAO); } else { request.setAttribute(CURRENT_GENERIC_DAO, null); } // Create transaction EntityTransaction transaction = (EntityTransaction) request.getAttribute(CURRENT_ENTITY_TRANSACTION); if (transaction == null) { transaction = manager.getTransaction(); request.setAttribute(CURRENT_ENTITY_TRANSACTION, transaction); transaction.begin(); try { doProcess(); } catch (Exception e) { if (transaction.isActive()) { transaction.rollback(); } throw e; } if (transaction.isActive()) { transaction.commit(); } manager.close(); } else { doProcess(); } }
From source file:org.dspace.core.ConfigurationManager.java
/** * Returns all properties for a given module * * @param module//from www . j a v a2 s . c o m * the name of the module * @return properties - all module's properties */ public static Properties getProperties(String module) { // Find subset of Configurations which have been prefixed with the module name Configuration subset = DSpaceServicesFactory.getInstance().getConfigurationService().getConfiguration() .subset(module); // Convert to a Properties object and return it return ConfigurationConverter.getProperties(subset); }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationFactoryBean.java
/** * @see org.springframework.beans.factory.FactoryBean#getObject() *///from w ww . ja va 2s . c o m @Override public Object getObject() throws Exception { return (configuration != null) ? ConfigurationConverter.getProperties(configuration) : null; }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationService.java
/** * Returns all loaded properties as a Properties object. * * @see org.dspace.services.ConfigurationService#getProperties() *//* ww w . ja v a 2 s . c o m*/ @Override public Properties getProperties() { // Return our configuration as a set of Properties return ConfigurationConverter.getProperties(configuration); }