List of usage examples for org.apache.commons.configuration Configuration getStringArray
String[] getStringArray(String key);
From source file:org.seedstack.seed.persistence.tinkerpop.internal.TinkerpopPlugin.java
@Override @SuppressWarnings("unchecked") public InitState init(InitContext initContext) { Configuration tinkerpopConfiguration = null; TransactionPlugin transactionPlugin = null; for (Plugin plugin : initContext.pluginsRequired()) { if (plugin instanceof ApplicationPlugin) { tinkerpopConfiguration = ((ApplicationPlugin) plugin).getApplication().getConfiguration() .subset(TinkerpopPlugin.TINKERPOP_PLUGIN_CONFIGURATION_PREFIX); } else if (plugin instanceof TransactionPlugin) { transactionPlugin = ((TransactionPlugin) plugin); }//w w w . ja v a 2 s . c o m } if (tinkerpopConfiguration == null) { throw new PluginException("Unable to find application plugin"); } if (transactionPlugin == null) { throw new PluginException("Unable to find transaction plugin"); } String[] graphNames = tinkerpopConfiguration.getStringArray("graphs"); if (graphNames != null) { for (String graphName : graphNames) { Configuration graphConfiguration = tinkerpopConfiguration.subset("graph." + graphName); String implementation = graphConfiguration.getString("implementation"); if (implementation != null && !implementation.isEmpty()) { try { this.graphs.put(graphName, (Graph) Class.forName(implementation).newInstance()); } catch (Exception e) { throw new PluginException("Unable to load class " + implementation, e); } } else { throw new IllegalArgumentException( "The implementation is not specified for graph " + graphName); } String exceptionHandler = graphConfiguration.getString("exception-handler"); if (exceptionHandler != null && !exceptionHandler.isEmpty()) { try { graphExceptionHandlerClasses.put(graphName, (Class<? extends GraphExceptionHandler>) Class.forName(exceptionHandler)); } catch (Exception e) { throw new PluginException("Unable to load class " + exceptionHandler, e); } } } transactionPlugin.registerTransactionHandler(GraphTransactionHandler.class); } else { LOGGER.info("No Tinkerpop graph configured, Tinkerpop support disabled"); } return InitState.INITIALIZED; }
From source file:org.seedstack.seed.security.internal.authorization.ConfigurationRolePermissionResolver.java
private void processPermissionsConfiguration(Configuration permissionsConfiguration) { Iterator<String> keys = permissionsConfiguration.getKeys(); while (keys.hasNext()) { String roleName = keys.next(); String[] tokens = permissionsConfiguration.getStringArray(roleName); Set<String> permissions = new HashSet<String>(); for (String permission : tokens) { permissions.add(permission); }/*ww w . java2 s . c o m*/ roles.put(roleName, permissions); } }
From source file:org.seedstack.seed.security.internal.realms.ConfigurationRealm.java
private void processUsersConfiguration(Configuration usersConfiguration) { Iterator<String> keys = usersConfiguration.getKeys(); while (keys.hasNext()) { String userName = keys.next(); ConfigurationUser user = new ConfigurationUser(userName); String[] values = usersConfiguration.getStringArray(userName); if (values.length == 0) { user.password = ""; } else {//from w w w . j a v a2 s . c o m user.password = values[0]; for (int i = 1; i < values.length; i++) { user.roles.add(values[i]); } } users.add(user); } }
From source file:org.seedstack.seed.security.ldap.internal.LdapSecurityPlugin.java
@Override public InitState init(InitContext initContext) { ApplicationPlugin appPlugin = (ApplicationPlugin) initContext.pluginsRequired().iterator().next(); String[] realms = appPlugin.getApplication().getConfiguration().getStringArray(CHOSEN_REALMS); startPlugin = ArrayUtils.contains(realms, LDAPRealm.class.getSimpleName()); if (startPlugin) { Configuration ldapConfiguration = appPlugin.getApplication().getConfiguration() .subset(LDAP_CONFIG_PREFIX); // Initialize ldap pool connection String host = ldapConfiguration.getString(SERVER_HOST_PROP); if (host == null) { throw SeedException.createNew(LDAPErrorCode.NO_HOST_DEFINED).put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP); }/*w w w. ja va2 s. co m*/ int port = ldapConfiguration.getInt(SERVER_PORT_PROP, DEFAULT_SERVER_PORT); int numConnections = ldapConfiguration.getInt(NUM_CONNECTIONS_PROP, DEFAULT_NUM_CONNECTIONS); String accountDn = StringUtils.join(ldapConfiguration.getStringArray(ACCOUNT_DN_PROP), ','); LDAPConnection connection; try { connection = new LDAPConnection(host, port, accountDn, ldapConfiguration.getString(ACCOUNT_PASSWORD_PROP)); ldapConnectionPool = new LDAPConnectionPool(connection, numConnections); } catch (LDAPException e) { switch (e.getResultCode().intValue()) { case ResultCode.NO_SUCH_OBJECT_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.NO_SUCH_ACCOUNT).put("account", accountDn) .put("propName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.INVALID_CREDENTIALS_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.INVALID_CREDENTIALS).put("account", accountDn) .put("passwordPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_PASSWORD_PROP) .put("userPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.CONNECT_ERROR_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.CONNECT_ERROR).put("host", host).put("port", port) .put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP) .put("portPropName", LDAP_CONFIG_PREFIX + "." + SERVER_PORT_PROP); default: throw SeedException.wrap(e, LDAPErrorCode.LDAP_ERROR).put("message", e.getMessage()) .put("host", host).put("port", port).put("account", accountDn); } } } return InitState.INITIALIZED; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
@Override @SuppressWarnings("unchecked") public InitState init(InitContext initContext) { Application application = initContext.dependency(ApplicationPlugin.class).getApplication(); TransactionPlugin transactionPlugin = initContext.dependency(TransactionPlugin.class); Configuration solrConfiguration = application.getConfiguration() .subset(SolrPlugin.SOLR_PLUGIN_CONFIGURATION_PREFIX); String[] solrClients = solrConfiguration.getStringArray("clients"); if (solrClients == null || solrClients.length == 0) { LOGGER.info("No Solr client configured, Solr support disabled"); return InitState.INITIALIZED; }//from w w w . ja v a2 s . c o m for (String solrClient : solrClients) { Configuration solrClientConfiguration = solrConfiguration.subset("client." + solrClient); try { this.solrClients.put(solrClient, buildSolrClient(solrClientConfiguration)); } catch (Exception e) { throw SeedException.wrap(e, SolrErrorCodes.UNABLE_TO_CREATE_CLIENT).put("clientName", solrClient); } String exceptionHandler = solrClientConfiguration.getString("exception-handler"); if (exceptionHandler != null && !exceptionHandler.isEmpty()) { try { solrTransactionHandlers.put(solrClient, (Class<? extends SolrExceptionHandler>) Class.forName(exceptionHandler)); } catch (Exception e) { throw new PluginException("Unable to load class " + exceptionHandler, e); } } } if (solrClients.length == 1) { SolrTransactionMetadataResolver.defaultSolrClient = solrClients[0]; } transactionPlugin.registerTransactionHandler(SolrTransactionHandler.class); return InitState.INITIALIZED; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private SolrClient buildSolrClient(Configuration solrClientConfiguration) throws MalformedURLException { SolrClientType clientType = SolrClientType.valueOf( solrClientConfiguration.getString(SolrConfigurationConstants.TYPE, SolrClientType.HTTP.toString())); String[] urls = solrClientConfiguration.getStringArray(SolrConfigurationConstants.URLS); if (urls == null || urls.length == 0 || urls[0].isEmpty()) { urls = new String[] { solrClientConfiguration.getString(SolrConfigurationConstants.URL) }; if (urls[0] == null || urls[0].isEmpty()) { throw SeedException.createNew(SolrErrorCodes.MISSING_URL_CONFIGURATION); }//from w ww.j av a 2 s . c om } switch (clientType) { case LOAD_BALANCED_HTTP: return buildLBSolrClient(solrClientConfiguration, urls); case HTTP: return buildHttpSolrClient(solrClientConfiguration, urls[0]); case CLOUD: return buildCloudSolrClient(solrClientConfiguration, urls); default: throw SeedException.createNew(SolrErrorCodes.UNSUPPORTED_CLIENT_TYPE); } }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private SolrClient buildLBSolrClient(Configuration solrClientConfiguration, String[] lbUrls) throws MalformedURLException { LBHttpSolrClient lbHttpSolrClient = new LBHttpSolrClient(lbUrls); if (solrClientConfiguration.containsKey(SolrConfigurationConstants.CONNECTION_TIMEOUT)) { lbHttpSolrClient.setConnectionTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.CONNECTION_TIMEOUT)); }/* ww w . ja v a2s. c o m*/ if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)) { lbHttpSolrClient.setAliveCheckInterval( solrClientConfiguration.getInt(SolrConfigurationConstants.ALIVE_CHECK_INTERVAL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.QUERY_PARAMS)) { lbHttpSolrClient.setQueryParams(Sets .newHashSet(solrClientConfiguration.getStringArray(SolrConfigurationConstants.QUERY_PARAMS))); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.SO_TIMEOUT)) { lbHttpSolrClient.setSoTimeout(solrClientConfiguration.getInt(SolrConfigurationConstants.SO_TIMEOUT)); } return lbHttpSolrClient; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private SolrClient buildHttpSolrClient(Configuration solrClientConfiguration, String url) { HttpSolrClient httpSolrClient = new HttpSolrClient(url); if (solrClientConfiguration.containsKey(SolrConfigurationConstants.CONNECTION_TIMEOUT)) { httpSolrClient.setConnectionTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.CONNECTION_TIMEOUT)); }// ww w . j ava2s . co m if (solrClientConfiguration.containsKey(SolrConfigurationConstants.QUERY_PARAMS)) { httpSolrClient.setQueryParams(Sets .newHashSet(solrClientConfiguration.getStringArray(SolrConfigurationConstants.QUERY_PARAMS))); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.SO_TIMEOUT)) { httpSolrClient.setSoTimeout(solrClientConfiguration.getInt(SolrConfigurationConstants.SO_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ALLOW_COMPRESSION)) { httpSolrClient.setAllowCompression( solrClientConfiguration.getBoolean(SolrConfigurationConstants.ALLOW_COMPRESSION)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.MAX_CONNECTIONS_PER_HOST)) { httpSolrClient.setDefaultMaxConnectionsPerHost( solrClientConfiguration.getInt(SolrConfigurationConstants.MAX_CONNECTIONS_PER_HOST)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.FOLLOW_REDIRECTS)) { httpSolrClient.setFollowRedirects( solrClientConfiguration.getBoolean(SolrConfigurationConstants.FOLLOW_REDIRECTS)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.MAX_TOTAL_CONNECTIONS)) { httpSolrClient.setMaxTotalConnections( solrClientConfiguration.getInt(SolrConfigurationConstants.MAX_TOTAL_CONNECTIONS)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.USE_MULTI_PART_HOST)) { httpSolrClient.setUseMultiPartPost( solrClientConfiguration.getBoolean(SolrConfigurationConstants.USE_MULTI_PART_HOST)); } return httpSolrClient; }
From source file:org.seedstack.solr.internal.SolrPlugin.java
private CloudSolrClient buildCloudSolrClient(Configuration solrClientConfiguration, String[] zooKeeperUrls) throws MalformedURLException { String[] lbUrls = solrClientConfiguration.getStringArray(SolrConfigurationConstants.LB_URLS); CloudSolrClient cloudSolrClient;//ww w . ja v a2s . c o m if (lbUrls != null && lbUrls.length > 0) { cloudSolrClient = new CloudSolrClient(zooKeeperUrls[0], new LBHttpSolrClient(lbUrls), solrClientConfiguration.getBoolean(SolrConfigurationConstants.UPDATE_TO_LEADERS, true)); } else { cloudSolrClient = new CloudSolrClient(Lists.newArrayList(zooKeeperUrls), solrClientConfiguration.getString(SolrConfigurationConstants.CHROOT)); } String defaultCollection = solrClientConfiguration.getString(SolrConfigurationConstants.DEFAULT_COLLECTION); if (defaultCollection != null && !defaultCollection.isEmpty()) { cloudSolrClient.setDefaultCollection(defaultCollection); } String idField = solrClientConfiguration.getString(SolrConfigurationConstants.ID_FIELD); if (idField != null && !idField.isEmpty()) { cloudSolrClient.setIdField(idField); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.COLLECTION_CACHE_TTL)) { cloudSolrClient.setCollectionCacheTTl( solrClientConfiguration.getInt(SolrConfigurationConstants.COLLECTION_CACHE_TTL)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)) { cloudSolrClient.setParallelCacheRefreshes( solrClientConfiguration.getInt(SolrConfigurationConstants.PARALLEL_CACHE_REFRESHES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.PARALLEL_UPDATES)) { cloudSolrClient.setParallelUpdates( solrClientConfiguration.getBoolean(SolrConfigurationConstants.PARALLEL_UPDATES)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)) { cloudSolrClient.setZkClientTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CLIENT_TIMEOUT)); } if (solrClientConfiguration.containsKey(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)) { cloudSolrClient.setZkConnectTimeout( solrClientConfiguration.getInt(SolrConfigurationConstants.ZK_CONNECT_TIMEOUT)); } return cloudSolrClient; }
From source file:org.seedstack.spring.internal.SpringPlugin.java
@Override public InitState init(InitContext initContext) { configurationProvider = initContext.dependency(ConfigurationProvider.class); Configuration configuration = configurationProvider.getConfiguration(); Configuration springConfiguration = configuration.subset(SPRING_PLUGIN_CONFIGURATION_PREFIX); Map<String, Collection<String>> scannedApplicationContexts = initContext.mapResourcesByRegex(); SeedConfigurationFactoryBean.configuration = configuration; boolean autodetect = springConfiguration.getBoolean("autodetect", true); managedTransaction = springConfiguration.getBoolean("manage-transactions", false); for (String applicationContextPath : scannedApplicationContexts.get(APPLICATION_CONTEXT_REGEX)) { if (autodetect && applicationContextPath.startsWith("META-INF/spring")) { applicationContextsPaths.add(applicationContextPath); LOGGER.trace("Autodetected spring context at " + applicationContextPath); }/*from w ww . ja v a 2 s .c o m*/ } if (springConfiguration.containsKey("contexts")) { String[] explicitContexts = springConfiguration.getStringArray("contexts"); for (String explicitContext : explicitContexts) { applicationContextsPaths.add(explicitContext); LOGGER.trace("Configured spring context at " + explicitContext); } } else if (springConfiguration.containsKey("context")) { String explicitContext = springConfiguration.getString("context"); applicationContextsPaths.add(explicitContext); LOGGER.trace("Configured spring context at " + explicitContext); } LOGGER.info("Initializing spring context(s) " + applicationContextsPaths); globalApplicationContext = new ClassPathXmlApplicationContext( this.applicationContextsPaths.toArray(new String[this.applicationContextsPaths.size()])); return InitState.INITIALIZED; }