List of usage examples for org.apache.commons.configuration Configuration getProperty
Object getProperty(String key);
From source file:com.netflix.config.ConcurrentCompositeConfiguration.java
/** * Read property from underlying composite. It first checks if the property has been overridden * by {@link #setOverrideProperty(String, Object)} and if so return the overriding value. * Otherwise, it iterates through the list of sub configurations until it finds one that contains the * property and return the value from that sub configuration. It returns null of the property does * not exist.//from w ww . j a v a 2s. c om * * @param key key to use for mapping * * @return object associated with the given configuration key. null if it does not exist. */ public Object getProperty(String key) { if (overrideProperties.containsKey(key)) { return overrideProperties.getProperty(key); } Configuration firstMatchingConfiguration = null; for (Configuration config : configList) { if (config.containsKey(key)) { firstMatchingConfiguration = config; break; } } if (firstMatchingConfiguration != null) { return firstMatchingConfiguration.getProperty(key); } else { return null; } }
From source file:dk.itst.oiosaml.sp.service.SPFilter.java
/** * Check whether the user is authenticated i.e. having session with a valid * assertion. If the user is not authenticated an <AuthnRequest> is sent to * the Login Site.//from w w w. ja v a 2 s . com * * @param request * The servletRequest * @param response * The servletResponse */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (log.isDebugEnabled()) log.debug("OIOSAML-J SP Filter invoked"); if (!(request instanceof HttpServletRequest)) { throw new RuntimeException("Not supported operation..."); } HttpServletRequest servletRequest = ((HttpServletRequest) request); Audit.init(servletRequest); if (!isFilterInitialized()) { try { Configuration conf = SAMLConfiguration.getSystemConfiguration(); setRuntimeConfiguration(conf); } catch (IllegalStateException e) { request.getRequestDispatcher("/saml/configure").forward(request, response); return; } } if (conf.getBoolean(Constants.PROP_DEVEL_MODE, false)) { log.warn("Running in debug mode, skipping regular filter"); develMode.doFilter(servletRequest, (HttpServletResponse) response, chain, conf); return; } if (cleanerRunning.compareAndSet(false, true)) { SessionCleaner.startCleaner(sessionHandlerFactory.getHandler(), ((HttpServletRequest) request).getSession().getMaxInactiveInterval(), 30); } SessionHandler sessionHandler = sessionHandlerFactory.getHandler(); if (servletRequest.getServletPath().equals(conf.getProperty(Constants.PROP_SAML_SERVLET))) { log.debug("Request to SAML servlet, access granted"); chain.doFilter(new SAMLHttpServletRequest(servletRequest, hostname, null), response); return; } final HttpSession session = servletRequest.getSession(); if (log.isDebugEnabled()) log.debug("sessionId....:" + session.getId()); // Is the user logged in? if (sessionHandler.isLoggedIn(session.getId()) && session.getAttribute(Constants.SESSION_USER_ASSERTION) != null) { int actualAssuranceLevel = sessionHandler.getAssertion(session.getId()).getAssuranceLevel(); int assuranceLevel = conf.getInt(Constants.PROP_ASSURANCE_LEVEL); if (actualAssuranceLevel < assuranceLevel) { sessionHandler.logOut(session); log.warn("Assurance level too low: " + actualAssuranceLevel + ", required: " + assuranceLevel); throw new RuntimeException( "Assurance level too low: " + actualAssuranceLevel + ", required: " + assuranceLevel); } UserAssertion ua = (UserAssertion) session.getAttribute(Constants.SESSION_USER_ASSERTION); if (log.isDebugEnabled()) log.debug("Everything is ok... Assertion: " + ua); Audit.log(Operation.ACCESS, servletRequest.getRequestURI()); try { UserAssertionHolder.set(ua); HttpServletRequestWrapper requestWrap = new SAMLHttpServletRequest(servletRequest, ua, hostname); chain.doFilter(requestWrap, response); return; } finally { UserAssertionHolder.set(null); } } else { session.removeAttribute(Constants.SESSION_USER_ASSERTION); UserAssertionHolder.set(null); String relayState = sessionHandler.saveRequest(Request.fromHttpRequest(servletRequest)); String protocol = conf.getString(Constants.PROP_PROTOCOL, "saml20"); String loginUrl = conf.getString(Constants.PROP_SAML_SERVLET, "/saml"); String protocolUrl = conf.getString(Constants.PROP_PROTOCOL + "." + protocol); if (protocolUrl == null) { throw new RuntimeException( "No protocol url configured for " + Constants.PROP_PROTOCOL + "." + protocol); } loginUrl += protocolUrl; if (log.isDebugEnabled()) log.debug("Redirecting to " + protocol + " login handler at " + loginUrl); RequestDispatcher dispatch = servletRequest.getRequestDispatcher(loginUrl); dispatch.forward(new SAMLHttpServletRequest(servletRequest, hostname, relayState), response); } }
From source file:edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.java
/** * Instantiate based on a configuration * @param config// w ww . ja va2s. c o m */ public AccumuloGraphConfiguration(Configuration config) { this(); Iterator<String> keys = config.getKeys(); while (keys.hasNext()) { String key = keys.next(); conf.setProperty(key.replace("..", "."), config.getProperty(key)); } }
From source file:com.blazegraph.gremlin.structure.BlazeGraph.java
/** * Construct an instance using the supplied configuration. *///from w w w.j a v a2s . c o m protected BlazeGraph(final Configuration config) { this.config = config; this.vf = Optional.ofNullable((BlazeValueFactory) config.getProperty(Options.VALUE_FACTORY)) .orElse(BlazeValueFactory.INSTANCE); final long listIndexFloor = config.getLong(Options.LIST_INDEX_FLOOR, System.currentTimeMillis()); this.vpIdFactory = new AtomicLong(listIndexFloor); this.maxQueryTime = config.getInt(Options.MAX_QUERY_TIME, 0); this.sparqlLogMax = config.getInt(Options.SPARQL_LOG_MAX, Options.DEFAULT_SPARQL_LOG_MAX); this.TYPE = vf.type(); this.VALUE = vf.value(); this.LI_DATATYPE = vf.liDatatype(); this.sparql = new SparqlGenerator(vf); this.transforms = new Transforms(); }
From source file:org.acmsl.queryj.ConfigurationQueryJCommandImpl.java
/** * Retrieves the setting for given key.//w ww .java 2 s . co m * @param key the key. * @param configuration the {@link Configuration configuration} settings. * @param <T> the type. * @return the value for such key. */ @Nullable @SuppressWarnings("unchecked") protected <T> T getSetting(@NotNull final String key, @NotNull final Configuration configuration) { return (T) configuration.getProperty(key); }
From source file:org.acmsl.queryj.ConfigurationQueryJCommandImpl.java
/** * Retrieves the setting for given key.//from www . ja va 2 s .c o m * @param key the key. * @param configuration the configuration. * @param <T> the type. * @return the value for such key. */ @SuppressWarnings("unchecked") protected <T> T getObjectSetting(@NotNull final String key, @NotNull final Configuration configuration) { return (T) configuration.getProperty(key); }
From source file:org.acmsl.queryj.ConfigurationQueryJCommandImpl.java
/** * Returns a JSON representation of given {@link Configuration}. * @param conf the instance to represent. * @return the JSON string.// ww w . j a v a2s .c om */ @SuppressWarnings("unused") @NotNull protected String confToString(@NotNull final Configuration conf) { @NotNull final StringBuilder result = new StringBuilder(); @NotNull final Iterator<String> t_itKey = conf.getKeys(); while (t_itKey.hasNext()) { @NotNull final String t_strKey = t_itKey.next(); result.append(", \""); result.append(t_strKey); result.append("\": \""); result.append(conf.getProperty(t_strKey)); result.append('"'); } return result.toString(); }
From source file:org.ambraproject.action.debug.DebugInfoAction.java
@Override public String execute() throws Exception { if (!checkAccess()) { return ERROR; }//from ww w. j a v a 2 s . co m timestamp = new Date(System.currentTimeMillis()); Runtime rt = Runtime.getRuntime(); jvmFreeMemory = (double) rt.freeMemory() / (1024.0 * 1024.0); jvmTotalMemory = (double) rt.totalMemory() / (1024.0 * 1024.0); jvmMaxMemory = (double) rt.maxMemory() / (1024.0 * 1024.0); HttpServletRequest req = ServletActionContext.getRequest(); tomcatVersion = ServletActionContext.getServletContext().getServerInfo(); sessionCount = SessionCounter.getSessionCount(); host = req.getLocalName(); hostIp = req.getLocalAddr(); buildInfo = generateBuildInfo(); // The easiest way I found to get the URL and username for the DB. // It's not that easy and involves opening a connection... Context initialContext = new InitialContext(); Context context = (Context) initialContext.lookup("java:comp/env"); DataSource ds = (DataSource) context.lookup("jdbc/AmbraDS"); Connection conn = null; try { conn = ds.getConnection(); DatabaseMetaData metadata = conn.getMetaData(); dbUrl = metadata.getURL(); dbUser = metadata.getUserName(); } finally { conn.close(); } Configuration config = ConfigurationStore.getInstance().getConfiguration(); FileStoreService filestoreService = (FileStoreService) context.lookup("ambra/FileStore"); filestore = filestoreService.toString(); solrUrl = (String) config.getProperty("ambra.services.search.server.url"); configuration = dumpConfig(config); cmdLine = IOUtils.toString(new FileInputStream("/proc/self/cmdline")); return SUCCESS; }
From source file:org.ambraproject.action.debug.DebugInfoAction.java
/** * Returns a string with information about many of the ambra.* properties * in a Configuration. Intended to be informational-only, not exhaustive. *///from w w w .j a va 2 s. c o m private String dumpConfig(Configuration config) { StringBuilder result = new StringBuilder(); Iterator iter = config.getKeys(); while (iter.hasNext()) { String key = (String) iter.next(); // Don't display the virtual journal stuff; it's long and not particularly useful. if (key.startsWith("ambra.") && !key.startsWith("ambra.virtualJournals.")) { Object value = config.getProperty(key); // Attempt to dereference other properties referred to by "${foo}" notation. if (value instanceof String) { String valueStr = (String) value; if (valueStr.startsWith("${")) { String refKey = valueStr.substring(2, valueStr.length() - 1); Object refValue = config.getProperty(refKey); if (refValue != null) { value = String.format("%s -> %s", valueStr, refValue); } } } result.append(key).append(": ").append(value).append('\n'); } } return result.toString(); }
From source file:org.ambraproject.freemarker.AmbraFreemarkerConfig.java
private void loadConfig2(Configuration configuration) { int numJournals = configuration.getList("ambra.freemarker.journal.name").size(); for (int k = 0; k < numJournals; k++) { final String journal = "ambra.freemarker.journal(" + k + ")"; final String journalName = configuration.getString(journal + ".name"); if (log.isDebugEnabled()) { log.debug("reading journal name: " + journalName); }/*from w w w. j a v a 2s. c om*/ JournalConfig jc = journals.get(journalName); if (jc == null) { if (log.isDebugEnabled()) { log.debug("journal Not found, creating: " + journalName); } jc = new JournalConfig(); journals.put(journalName, jc); } if (jc.getDefaultTitle() == null) { final String title = configuration.getString(journal + ".default.title"); if (title != null) { jc.setDefaultTitle(title); } } if (jc.getMetaDescription() == null) { final String metaDescription = configuration.getString(journal + ".metaDescription"); if (metaDescription != null) { jc.setMetaDescription(metaDescription); } } if (jc.getMetaKeywords() == null) { final String metaKeywords = configuration.getString(journal + ".metaKeywords"); if (metaKeywords != null) { jc.setMetaKeywords(metaKeywords); } } if (jc.getHashTag() == null) { final String hashtag = configuration.getString(journal + ".hashTag"); if (hashtag != null) { jc.setHashTag(hashtag); } } if (jc.getDisplayName() == null) { final String displayName = configuration.getString(journal + ".displayName"); if (displayName != null) { jc.setDisplayName(displayName); } } if (jc.getArticleTitlePrefix() == null) { final String articleTitlePrefix = configuration.getString(journal + ".articleTitlePrefix"); if (articleTitlePrefix != null) { jc.setArticleTitlePrefix(articleTitlePrefix); } } if (jc.getDefaultCss() == null) { final List fileList = configuration.getList(journal + ".default.css.file"); String[] defaultCss; if (fileList.size() > 0) { defaultCss = new String[fileList.size()]; Iterator iter = fileList.iterator(); for (int i = 0; i < fileList.size(); i++) { defaultCss[i] = dirPrefix + subdirPrefix + iter.next(); } jc.setDefaultCss(defaultCss); } } if (jc.getDefaultJavaScript() == null) { final List fileList = configuration.getList(journal + ".default.javascript.file"); String javascriptFile; String[] defaultJavaScript; if (fileList.size() > 0) { defaultJavaScript = new String[fileList.size()]; Iterator iter = fileList.iterator(); for (int i = 0; i < fileList.size(); i++) { javascriptFile = (String) iter.next(); if (javascriptFile.endsWith(".ftl")) { defaultJavaScript[i] = subdirPrefix + javascriptFile; } else { defaultJavaScript[i] = dirPrefix + subdirPrefix + javascriptFile; } } jc.setDefaultJavaScript(defaultJavaScript); } } final int numPages = configuration.getList(journal + ".page.name").size(); for (int i = 0; i < numPages; i++) { String page = journal + ".page(" + i + ")"; String pageName = configuration.getString(page + ".name"); if (log.isDebugEnabled()) log.debug("Reading config for page name: " + pageName); if (!jc.getTitles().containsKey(pageName)) { final String title = configuration.getString(page + ".title"); if (title != null) { jc.getTitles().put(pageName, title); } } if (!jc.getCssFiles().containsKey(pageName)) { List<String> list = configuration.getList(page + ".css.file"); String[] cssArray = new String[list.size()]; int j = 0; for (String fileName : list) { cssArray[j++] = dirPrefix + subdirPrefix + fileName; } if (cssArray.length > 0 || cssArray.length == 0 && configuration.getProperty(page + ".css") != null) { jc.getCssFiles().put(pageName, cssArray); } } if (!jc.getJavaScriptFiles().containsKey(pageName)) { List<String> list = configuration.getList(page + ".javascript.file"); String[] javaScriptArray = new String[list.size()]; int j = 0; for (String fileName : list) { if (fileName.endsWith(".ftl")) { javaScriptArray[j++] = subdirPrefix + fileName; } else { javaScriptArray[j++] = dirPrefix + subdirPrefix + fileName; } } if (javaScriptArray.length > 0 || javaScriptArray.length == 0 && configuration.getProperty(page + ".javascript") != null) { jc.getJavaScriptFiles().put(pageName, javaScriptArray); } } } } }