List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:org.wso2.carbon.appmgt.rest.api.util.interceptors.PreAuthenticationInterceptor.java
@Override public void handleMessage(Message message) throws Fault { String path = (String) message.get(Message.PATH_INFO); String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD); Dictionary<URITemplate, List<String>> whiteListedResourcePathsMap; //If Authorization headers are present anonymous URI check will be skipped ArrayList authHeaders = (ArrayList) ((TreeMap) (message.get(Message.PROTOCOL_HEADERS))) .get(RestApiConstants.AUTH_HEADER_NAME); if (authHeaders != null) return;/*from w w w . j a v a2 s. co m*/ //Check if the accessing URI is white-listed and then authorization is skipped try { whiteListedResourcePathsMap = RestApiUtil.getWhiteListedURIsToMethodsMap(); Enumeration<URITemplate> uriTemplateSet = whiteListedResourcePathsMap.keys(); while (uriTemplateSet.hasMoreElements()) { URITemplate uriTemplate = uriTemplateSet.nextElement(); if (uriTemplate.matches(path, new HashMap<String, String>())) { List<String> whiteListedVerbs = whiteListedResourcePathsMap.get(uriTemplate); if (whiteListedVerbs.contains(httpMethod)) { message.put(RestApiConstants.AUTHENTICATION_REQUIRED, false); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); carbonContext.setUsername(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); return; } } } } catch (AppManagementException e) { RestApiUtil.handleInternalServerError("Unable to retrieve/process white-listed URIs for REST API", e, logger); } }
From source file:org.wso2.carbon.apimgt.rest.api.util.interceptors.PreAuthenticationInterceptor.java
@Override public void handleMessage(Message message) throws Fault { String path = (String) message.get(Message.PATH_INFO); String httpMethod = (String) message.get(Message.HTTP_REQUEST_METHOD); Dictionary<URITemplate, List<String>> whiteListedResourcePathsMap; //If Authorization headers are present anonymous URI check will be skipped ArrayList authHeaders = (ArrayList) ((TreeMap) (message.get(Message.PROTOCOL_HEADERS))) .get(RestApiConstants.AUTH_HEADER_NAME); if (authHeaders != null) return;/*from w w w .jav a 2s . c o m*/ //Check if the accessing URI is white-listed and then authorization is skipped try { whiteListedResourcePathsMap = RestApiUtil.getWhiteListedURIsToMethodsMap(); Enumeration<URITemplate> uriTemplateSet = whiteListedResourcePathsMap.keys(); while (uriTemplateSet.hasMoreElements()) { URITemplate uriTemplate = uriTemplateSet.nextElement(); if (uriTemplate.matches(path, new HashMap<String, String>())) { List<String> whiteListedVerbs = whiteListedResourcePathsMap.get(uriTemplate); if (whiteListedVerbs.contains(httpMethod)) { message.put(RestApiConstants.AUTHENTICATION_REQUIRED, false); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext .getThreadLocalCarbonContext(); carbonContext.setUsername(CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); return; } } } } catch (APIManagementException e) { RestApiUtil.handleInternalServerError("Unable to retrieve/process white-listed URIs for REST API", e, logger); } }
From source file:org.openhab.binding.pulseaudio.internal.PulseaudioBinding.java
@SuppressWarnings("rawtypes") public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; }/*w w w.ja va 2 s. c o m*/ Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given pulseaudio-config-key '" + key + "' does not follow the expected pattern '<serverId>.<host|port>'"); continue; } matcher.reset(); matcher.find(); String serverId = matcher.group(1); PulseaudioServerConfig serverConfig = serverConfigCache.get(serverId); if (serverConfig == null) { serverConfig = new PulseaudioServerConfig(); serverConfigCache.put(serverId, serverConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { serverConfig.host = value; } else if ("port".equals(configKey)) { serverConfig.port = Integer.valueOf(value); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } connectAllPulseaudioServers(); } }
From source file:ddf.common.test.ServiceManager.java
public void printInactiveBundles() { LOGGER.info("Listing inactive bundles"); for (Bundle bundle : getBundleContext().getBundles()) { if (bundle.getState() != Bundle.ACTIVE) { StringBuffer headerString = new StringBuffer("[ "); Dictionary<String, String> headers = bundle.getHeaders(); Enumeration<String> keys = headers.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); headerString.append(key).append("=").append(headers.get(key)).append(", "); }//from ww w . j a v a2 s .c o m headerString.append(" ]"); LOGGER.info("{} | {} | {} | {}", bundle.getSymbolicName(), bundle.getVersion().toString(), OsgiStringUtils.bundleStateAsString(bundle), headerString.toString()); } } }
From source file:org.openengsb.core.test.AbstractOsgiMockServiceTest.java
@SuppressWarnings("unchecked") private ServiceRegistration<?> registerServiceInBundlecontext(String[] clazzes, final Object service, Dictionary<String, Object> dict) { dict.put(Constants.OBJECTCLASS, clazzes); final ServiceReference<?> serviceReference = putService(service, dict); ServiceRegistration<?> result = mock(ServiceRegistration.class); // unregistering removes the service from both maps doAnswer(new Answer<Void>() { @Override// www . j a v a2s.co m public Void answer(InvocationOnMock invocation) throws Throwable { synchronized (services) { services.remove(serviceReference); } synchronized (serviceReferences) { Dictionary<String, Object> props = serviceReferences.remove(serviceReference); updateServiceListeners(ServiceEvent.UNREGISTERING, serviceReference, props); return null; } } }).when(result).unregister(); // when properties are replaced, place a copy of the new properties-dictionary in the // serviceReferences-map (that overwrites the old dictionary) doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { Dictionary<String, Object> arg = (Dictionary<String, Object>) invocation.getArguments()[0]; Dictionary<String, Object> newDict = new Hashtable<String, Object>(); Enumeration<String> keys = arg.keys(); while (keys.hasMoreElements()) { String next = keys.nextElement(); newDict.put(next, arg.get(next)); } synchronized (serviceReferences) { serviceReferences.put(serviceReference, newDict); } return null; } }).when(result).setProperties(any(Dictionary.class)); when(result.getReference()).thenAnswer(new ValueAnswer<ServiceReference<?>>(serviceReference)); updateServiceListeners(ServiceEvent.REGISTERED, serviceReference, dict); return result; }
From source file:org.sakaiproject.nakamura.proxy.ProxyClientServiceImpl.java
/** * Create resources used by this component. * * @param ctx/*from w w w.j a v a2 s.c o m*/ * @throws Exception */ @SuppressWarnings("unchecked") protected void activate(ComponentContext ctx) throws Exception { if (ctx != null) { Dictionary<String, Object> props = ctx.getProperties(); configProperties = new HashMap<String, Object>(); for (Enumeration<String> e = props.keys(); e.hasMoreElements();) { String k = e.nextElement(); configProperties.put(k, props.get(k)); } String[] safePostProcessorNames = (String[]) configProperties.get(SAFE_POSTPROCESSORS); if (safePostProcessorNames == null) { safeOpenProcessors.add("rss"); safeOpenProcessors.add("trustedLoginTokenProxyPostProcessor"); } else { for (String pp : safePostProcessorNames) { safeOpenProcessors.add(pp); } } } else { configProperties = new HashMap<String, Object>(); } velocityEngine = new VelocityEngine(); velocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger(this.getClass())); velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, JCR_RESOURCE_LOADER); velocityEngine.setProperty(JCR_RESOURCE_LOADER_CLASS, JcrResourceLoader.class.getName()); ExtendedProperties configuration = new ExtendedProperties(); configuration.addProperty(JCR_RESOURCE_LOADER_PATH + ProxyNodeSource.JCR_RESOURCE_LOADER_RESOURCE_SOURCE, this); velocityEngine.setExtendedProperties(configuration); velocityEngine.init(); httpClientConnectionManager = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = new HttpConnectionManagerParams(); // could set a whole load of connection properties httpClientConnectionManager.setParams(params); httpClient = new HttpClient(httpClientConnectionManager); // allow communications via a proxy server if command line // java parameters http.proxyHost,http.proxyPort,http.proxyUser, // http.proxyPassword have been provided. externalAuthenticatingProxy = false; String proxyHost = System.getProperty("http.proxyHost", ""); int proxyPort = Integer.parseInt(System.getProperty("http.proxyPort", "80")); if (!proxyHost.equals("")) { // allow communications via a non-authenticating proxy httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort); String proxyUser = System.getProperty("http.proxyUser", ""); String proxyPassword = System.getProperty("http.proxyPassword", ""); if (!proxyUser.equals("")) { // allow communications via an authenticating proxy Credentials credentials = new UsernamePasswordCredentials(proxyUser, proxyPassword); AuthScope authScope = new AuthScope(proxyHost, proxyPort); httpClient.getState().setProxyCredentials(authScope, credentials); externalAuthenticatingProxy = true; } } }
From source file:org.jabsorb.serializer.impl.DictionarySerializer.java
public Object marshall(SerializerState state, Object p, Object o) throws MarshallException { Dictionary ht = (Dictionary) o; JSONObject obj = new JSONObject(); JSONObject mapdata = new JSONObject(); try {//from w ww . j a va 2 s. c om if (ser.getMarshallClassHints()) { obj.put("javaClass", o.getClass().getName()); } obj.put("map", mapdata); state.push(o, mapdata, "map"); } catch (JSONException e) { throw new MarshallException("Could not put data" + e.getMessage(), e); } Object key = null; try { Enumeration en = ht.keys(); while (en.hasMoreElements()) { key = en.nextElement(); String keyString = key.toString(); // only support String keys Object json = ser.marshall(state, mapdata, ht.get(key), keyString); // omit the object entirely if it's a circular reference or duplicate // it will be regenerated in the fixups phase if (JSONSerializer.CIRC_REF_OR_DUPLICATE != json) { mapdata.put(keyString, json); } } } catch (MarshallException e) { throw new MarshallException("map key " + key + " " + e.getMessage(), e); } catch (JSONException e) { throw new MarshallException("map key " + key + " " + e.getMessage(), e); } finally { state.pop(); } return obj; }
From source file:org.openhab.binding.plugwise.internal.PlugwiseBinding.java
@SuppressWarnings("rawtypes") @Override/*from w w w . j a v a 2s.c o m*/ public void updated(Dictionary config) throws ConfigurationException { if (config != null) { // First of all make sure the Stick gets set up Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_PLUGWISE_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.error("given plugwise-config-key '" + key + "' does not follow the expected pattern '<PlugwiseId>.<mac|port|interval>'"); continue; } matcher.reset(); matcher.find(); String plugwiseID = matcher.group(1); if (plugwiseID.equals("stick")) { if (stick == null) { String configKey = matcher.group(2); String value = (String) config.get(key); if ("port".equals(configKey)) { stick = new Stick(value, this); logger.info("Plugwise added Stick connected to serial port {}", value); } else if ("interval".equals(configKey)) { // do nothing for now. we will set in the second run } else if ("retries".equals(configKey)) { // do nothing for now. we will set in the second run } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } } if (stick != null) { // re-run through the configuration and setup the remaining devices keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_PLUGWISE_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.error("given plugwise-config-key '" + key + "' does not follow the expected pattern '<PlugwiseId>.<mac|port>'"); continue; } matcher.reset(); matcher.find(); String plugwiseID = matcher.group(1); if (plugwiseID.equals("stick")) { String configKey = matcher.group(2); String value = (String) config.get(key); if ("interval".equals(configKey)) { stick.setInterval(Integer.valueOf(value)); logger.info("Setting the interval to send ZigBee PDUs to {} ms", value); } else if ("retries".equals(configKey)) { stick.setRetries(Integer.valueOf(value)); logger.info("Setting the maximum number of attempts to send a message to ", value); } else if ("port".equals(configKey)) { //ignore } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } PlugwiseDevice device = stick.getDeviceByName(plugwiseID); if (device == null && !plugwiseID.equals("stick")) { String configKey = matcher.group(2); String value = (String) config.get(key); String MAC = null; if ("mac".equals(configKey)) { MAC = value; } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } if (!MAC.equals("")) { if (plugwiseID.equals("circleplus")) { if (stick.getDeviceByMAC(MAC) == null) { device = new CirclePlus(MAC, stick); logger.info("Plugwise added Circle+ with MAC address: {}", MAC); } } else { if (stick.getDeviceByMAC(MAC) == null) { device = new Circle(MAC, stick, plugwiseID); logger.info("Plugwise added Circle with MAC address: {}", MAC); } } stick.plugwiseDeviceCache.add(device); } } } setProperlyConfigured(true); } else { logger.error("Plugwise needs at least one Stick in order to operate"); } } }
From source file:org.openhab.binding.maxcul.internal.MaxCulBinding.java
private Map<String, Object> convertDictionaryToMap(Dictionary<String, ?> config) { Map<String, Object> myMap = new HashMap<String, Object>(); if (config == null) { return null; }/*from w w w .ja va 2 s . co m*/ if (config.size() == 0) { return myMap; } Enumeration<String> allKeys = config.keys(); while (allKeys.hasMoreElements()) { String key = allKeys.nextElement(); myMap.put(key, config.get(key)); } return myMap; }
From source file:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java
/** * defines or update the context of the provider * @param context the Spring application context object * @param dictionary configuration parameters *///w ww . j a va 2 s. com public void setContext(ApplicationContext context, Dictionary<String, ?> dictionary) { Properties userLdapProperties = new Properties(); Properties groupLdapProperties = new Properties(); UserConfig userConfig = new UserConfig(); GroupConfig groupConfig = new GroupConfig(); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (Constants.SERVICE_PID.equals(key) || ConfigurationAdmin.SERVICE_FACTORYPID.equals(key) || "felix.fileinstall.filename".equals(key)) { continue; } Object value = dictionary.get(key); if (key.startsWith("user.")) { buildConfig(userLdapProperties, userConfig, key, value, true); } else if (key.startsWith("group.")) { buildConfig(groupLdapProperties, groupConfig, key, value, false); } else { userLdapProperties.put(transformPropKeyToBeanAttr(key), value); groupLdapProperties.put(transformPropKeyToBeanAttr(key), value); } } try { // populate config beans BeanUtils.populate(userConfig, userLdapProperties); BeanUtils.populate(groupConfig, groupLdapProperties); // handle defaults values userConfig.handleDefaults(); groupConfig.handleDefaults(); // instantiate ldap context if (userConfig.isMinimalSettingsOk()) { LdapContextSource lcs = new LdapContextSource(); lcs.setUrl(userConfig.getUrl()); if (StringUtils.isNotEmpty(userConfig.getPublicBindDn())) { lcs.setUserDn(userConfig.getPublicBindDn()); } if (StringUtils.isNotEmpty(userConfig.getPublicBindPassword())) { lcs.setPassword(userConfig.getPublicBindPassword()); } Map<String, Object> publicEnv = new Hashtable<String, Object>(1); if (POOL_LDAP.equalsIgnoreCase(userConfig.getLdapConnectPool())) { lcs.setPooled(true); publicEnv.put("com.sun.jndi.ldap.connect.pool.authentication", "none simple"); if (userConfig.getLdapConnectPoolTimeout() != null && Long.valueOf(userConfig.getLdapConnectTimeout()) > 0) { publicEnv.put("com.sun.jndi.ldap.connect.pool.timeout", userConfig.getLdapConnectPoolTimeout()); } if (userConfig.getLdapConnectPoolDebug() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.debug", userConfig.getLdapConnectPoolDebug()); } if (userConfig.getLdapConnectPoolInitSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.initsize", userConfig.getLdapConnectPoolInitSize()); } if (userConfig.getLdapConnectPoolMaxSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.maxsize", userConfig.getLdapConnectPoolMaxSize()); } if (userConfig.getLdapConnectPoolPrefSize() != null) { publicEnv.put("com.sun.jndi.ldap.connect.pool.prefsize", userConfig.getLdapConnectPoolPrefSize()); } } if (userConfig.getLdapReadTimeout() != null) { publicEnv.put("com.sun.jndi.ldap.read.timeout", userConfig.getLdapReadTimeout()); } if (userConfig.getLdapConnectTimeout() != null) { publicEnv.put("com.sun.jndi.ldap.connect.timeout", userConfig.getLdapConnectTimeout()); } lcs.setBaseEnvironmentProperties(publicEnv); lcs.setReferral(groupConfig.getRefferal()); lcs.setDirObjectFactory(DefaultDirObjectFactory.class); lcs.afterPropertiesSet(); LdapTemplate ldap; if (POOL_APACHE_COMMONS.equalsIgnoreCase(userConfig.getLdapConnectPool())) { PoolingContextSource poolingContextSource = new PoolingContextSource(); poolingContextSource.setContextSource(lcs); if (userConfig.getLdapConnectPoolMaxActive() != null) { poolingContextSource.setMaxActive(userConfig.getLdapConnectPoolMaxActive()); } if (userConfig.getLdapConnectPoolMaxIdle() != null) { poolingContextSource.setMaxIdle(userConfig.getLdapConnectPoolMaxIdle()); } if (userConfig.getLdapConnectPoolMaxTotal() != null) { poolingContextSource.setMaxTotal(userConfig.getLdapConnectPoolMaxTotal()); } if (userConfig.getLdapConnectPoolMaxWait() != null) { poolingContextSource.setMaxWait(userConfig.getLdapConnectPoolMaxWait()); } if (userConfig.getLdapConnectPoolMinEvictableIdleTimeMillis() != null) { poolingContextSource.setMinEvictableIdleTimeMillis( userConfig.getLdapConnectPoolMinEvictableIdleTimeMillis()); } if (userConfig.getLdapConnectPoolMinIdle() != null) { poolingContextSource.setMinIdle(userConfig.getLdapConnectPoolMinIdle()); } if (userConfig.getLdapConnectPoolNumTestsPerEvictionRun() != null) { poolingContextSource .setNumTestsPerEvictionRun(userConfig.getLdapConnectPoolNumTestsPerEvictionRun()); } if (userConfig.getLdapConnectPoolTestOnBorrow() != null) { poolingContextSource.setTestOnBorrow(userConfig.getLdapConnectPoolTestOnBorrow()); } if (userConfig.getLdapConnectPoolTestOnReturn() != null) { poolingContextSource.setTestOnReturn(userConfig.getLdapConnectPoolTestOnReturn()); } if (userConfig.getLdapConnectPoolTestWhileIdle() != null) { poolingContextSource.setTestWhileIdle(userConfig.getLdapConnectPoolTestWhileIdle()); } if (userConfig.getLdapConnectPoolTimeBetweenEvictionRunsMillis() != null) { poolingContextSource.setTimeBetweenEvictionRunsMillis( userConfig.getLdapConnectPoolTimeBetweenEvictionRunsMillis()); } if (WHEN_EXHAUSTED_BLOCK.equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); } else if (WHEN_EXHAUSTED_FAIL .equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL); } else if (WHEN_EXHAUSTED_GROW .equalsIgnoreCase(userConfig.getLdapConnectPoolWhenExhaustedAction())) { poolingContextSource.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW); } ldap = new LdapTemplate(poolingContextSource); } else { ldap = new LdapTemplate(lcs); } // AD workaround to ignore Exceptions ldap.setIgnorePartialResultException(true); ldap.setIgnoreNameNotFoundException(true); if (ldapUserGroupProvider == null) { ldapUserGroupProvider = (LDAPUserGroupProvider) context.getBean("ldapUserGroupProvider"); } ldapUserGroupProvider.setKey(providerKey); ldapUserGroupProvider.setUserConfig(userConfig); ldapUserGroupProvider.setGroupConfig(groupConfig); if (StringUtils.isNotEmpty(userConfig.getUidSearchName()) && StringUtils.isNotEmpty(groupConfig.getSearchName())) { ldapUserGroupProvider .setDistinctBase(!userConfig.getUidSearchName().startsWith(groupConfig.getSearchName()) && !groupConfig.getSearchName().startsWith(userConfig.getUidSearchName())); } ldapUserGroupProvider.setLdapTemplateWrapper(new LdapTemplateWrapper(ldap)); ldapUserGroupProvider.setContextSource(lcs); ldapUserGroupProvider.unregister(); ldapUserGroupProvider.register(); if (groupConfig.isPreload()) { new Thread(new Runnable() { @Override public void run() { List<String> l = ldapUserGroupProvider.searchGroups(new Properties(), 0, -1); for (String s : l) { List<Member> m = ldapUserGroupProvider.getGroupMembers(s); } } }, "LDAP Preload").start(); } } else { unregister(); } } catch (IllegalAccessException e) { logger.error("Config LDAP invalid, pls read the documentation on LDAP configuration", e); } catch (InvocationTargetException e) { logger.error("Config LDAP invalid, pls read the documentation on LDAP configuration", e); } }