List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.openengsb.core.services.internal.deployer.connector.ConnectorDeployerServiceTest.java
@Before public void setUp() throws Exception { connectorDeployerService = new ConnectorDeployerService(); connectorDeployerService.setBundleContext(bundleContext); setupPersistence();/*from w ww .j a v a 2 s .c om*/ createServiceManagerMock(); connectorDeployerService.setServiceManager(serviceManager); factory = mock(ConnectorInstanceFactory.class); createdService = mock(NullDomainImpl.class); when(factory.createNewInstance(anyString())).thenReturn(createdService); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(org.openengsb.core.api.Constants.CONNECTOR_KEY, "aconnector"); props.put(org.openengsb.core.api.Constants.DOMAIN_KEY, "mydomain"); registerService(factory, props, ConnectorInstanceFactory.class); createDomainProviderMock(NullDomain.class, "mydomain"); DefaultWiringService defaultWiringService = new DefaultWiringService(); defaultWiringService.setBundleContext(bundleContext); registerServiceViaId(defaultWiringService, "wiring", WiringService.class); testConnectorId = "test-connector-instance"; wiringService = defaultWiringService; }
From source file:org.openengsb.core.test.AbstractOsgiMockServiceTest.java
/** * creates a mock of {@link ConnectorInstanceFactory} for the given connectorType and domains. * * Only {@link ConnectorInstanceFactory#createNewInstance(String)} is mocked to return a {@link Connector}-mock that * contains the given String as id.// ww w.j ava 2 s . co m * * Also the factory is registered as a service with the required properties */ protected ConnectorInstanceFactory createFactoryMock(String connector, final Class<? extends Connector> connectorClass, String... domains) throws Exception { ConnectorInstanceFactory factory = mock(ConnectorInstanceFactory.class); when(factory.createNewInstance(anyString())).thenAnswer(new Answer<Connector>() { @Override public Connector answer(InvocationOnMock invocation) throws Throwable { Connector result = mock(connectorClass); String id = (String) invocation.getArguments()[0]; when(result.getInstanceId()).thenReturn(id); return result; } }); when(factory.applyAttributes(any(Connector.class), anyMap())).thenAnswer(new Answer<Connector>() { @Override public Connector answer(InvocationOnMock invocation) throws Throwable { return (Connector) invocation.getArguments()[0]; } }); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(org.openengsb.core.api.Constants.CONNECTOR_KEY, connector); props.put(org.openengsb.core.api.Constants.DOMAIN_KEY, domains); registerService(factory, props, ConnectorInstanceFactory.class); return factory; }
From source file:org.opendaylight.netvirt.openstack.netvirt.ConfigActivator.java
@Override public void start(BundleContext context) throws Exception { LOG.info("ConfigActivator start:"); registerCRUDServiceProviders(context); ConfigurationServiceImpl configurationService = new ConfigurationServiceImpl(); registerService(context, new String[] { ConfigurationService.class.getName() }, null, configurationService); BridgeConfigurationManagerImpl bridgeConfigurationManager = new BridgeConfigurationManagerImpl( intBridgeGenMac);//from w ww.ja va 2s . com registerService(context, new String[] { BridgeConfigurationManager.class.getName() }, null, bridgeConfigurationManager); final TenantNetworkManagerImpl tenantNetworkManager = new TenantNetworkManagerImpl(); registerService(context, new String[] { TenantNetworkManager.class.getName() }, null, tenantNetworkManager); VlanConfigurationCacheImpl vlanConfigurationCache = new VlanConfigurationCacheImpl(); registerService(context, new String[] { VlanConfigurationCache.class.getName() }, null, vlanConfigurationCache); FloatingIPHandler floatingIPHandler = new FloatingIPHandler(); registerAbstractHandlerService(context, new Class[] { INeutronFloatingIPAware.class }, AbstractEvent.HandlerType.NEUTRON_FLOATING_IP, floatingIPHandler); final NetworkHandler networkHandler = new NetworkHandler(); registerAbstractHandlerService(context, new Class[] { INeutronNetworkAware.class }, AbstractEvent.HandlerType.NEUTRON_NETWORK, networkHandler); SubnetHandler subnetHandler = new SubnetHandler(); registerAbstractHandlerService(context, new Class[] { INeutronSubnetAware.class }, AbstractEvent.HandlerType.NEUTRON_SUBNET, subnetHandler); PortHandler portHandler = new PortHandler(); registerAbstractHandlerService(context, new Class[] { INeutronPortAware.class }, AbstractEvent.HandlerType.NEUTRON_PORT, portHandler); RouterHandler routerHandler = new RouterHandler(); registerAbstractHandlerService(context, new Class[] { INeutronRouterAware.class }, AbstractEvent.HandlerType.NEUTRON_ROUTER, routerHandler); SouthboundHandler southboundHandler = new SouthboundHandler(); registerAbstractHandlerService(context, new Class[] { OvsdbInventoryListener.class, NodeCacheListener.class }, AbstractEvent.HandlerType.SOUTHBOUND, southboundHandler); final LBaaSHandler lBaaSHandler = new LBaaSHandler(); registerAbstractHandlerService(context, new Class[] { INeutronLoadBalancerAware.class, NodeCacheListener.class }, AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER, lBaaSHandler); final LBaaSPoolHandler lBaaSPoolHandler = new LBaaSPoolHandler(); registerAbstractHandlerService(context, new Class[] { INeutronLoadBalancerPoolAware.class }, AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL, lBaaSPoolHandler); final LBaaSPoolMemberHandler lBaaSPoolMemberHandler = new LBaaSPoolMemberHandler(); registerAbstractHandlerService(context, new Class[] { INeutronLoadBalancerPoolMemberAware.class }, AbstractEvent.HandlerType.NEUTRON_LOAD_BALANCER_POOL_MEMBER, lBaaSPoolMemberHandler); PortSecurityHandler portSecurityHandler = new PortSecurityHandler(); registerAbstractHandlerService(context, new Class[] { INeutronSecurityRuleAware.class, INeutronSecurityGroupAware.class }, AbstractEvent.HandlerType.NEUTRON_PORT_SECURITY, portSecurityHandler); final SecurityServicesImpl securityServices = new SecurityServicesImpl(conntrackEnabled); registerService(context, new String[] { SecurityServicesManager.class.getName() }, null, securityServices); final SecurityGroupCacheManger securityGroupCacheManger = new SecurityGroupCacheManagerImpl(); registerService(context, new String[] { SecurityGroupCacheManger.class.getName() }, null, securityGroupCacheManger); registerService(context, new String[] { SecurityServicesManager.class.getName() }, null, securityServices); FWaasHandler fWaasHandler = new FWaasHandler(); registerAbstractHandlerService(context, new Class[] { INeutronFirewallAware.class, INeutronFirewallRuleAware.class, INeutronFirewallPolicyAware.class }, AbstractEvent.HandlerType.NEUTRON_FWAAS, fWaasHandler); ProviderNetworkManagerImpl providerNetworkManager = new ProviderNetworkManagerImpl(); registerService(context, new String[] { NetworkingProviderManager.class.getName() }, null, providerNetworkManager); EventDispatcherImpl eventDispatcher = new EventDispatcherImpl(); registerService(context, new String[] { EventDispatcher.class.getName() }, null, eventDispatcher); final NeutronL3Adapter neutronL3Adapter = new NeutronL3Adapter( new NeutronModelsDataStoreHelper(dataBroker)); registerAbstractHandlerService(context, new Class[] { NeutronL3Adapter.class, GatewayMacResolverListener.class }, AbstractEvent.HandlerType.NEUTRON_L3_ADAPTER, neutronL3Adapter); // TODO Why is DistributedArpService registered as an event handler without being an AbstractHandlerService? Dictionary<String, Object> distributedArpServiceProperties = new Hashtable<>(); distributedArpServiceProperties.put(Constants.EVENT_HANDLER_TYPE_PROPERTY, AbstractEvent.HandlerType.DISTRIBUTED_ARP_SERVICE); final DistributedArpService distributedArpService = new DistributedArpService(); registerService(context, new String[] { DistributedArpService.class.getName() }, distributedArpServiceProperties, distributedArpService); final VLANProvider vlanProvider = new VLANProvider(); registerService(context, new String[] { VLANProvider.class.getName() }, null, vlanProvider); OpenstackRouter openstackRouter = new OpenstackRouter(); registerService(context, new String[] { MultiTenantAwareRouter.class.getName() }, null, openstackRouter); Southbound southbound = new SouthboundImpl(dataBroker); registerService(context, new String[] { Southbound.class.getName() }, null, southbound); HostConfigService hostConfigService = new HostConfigService(dataBroker); registerService(context, new String[] { HostConfigService.class.getName() }, null, hostConfigService); NodeCacheManagerImpl nodeCacheManager = new NodeCacheManagerImpl(); registerAbstractHandlerService(context, new Class[] { NodeCacheManager.class }, AbstractEvent.HandlerType.NODE, nodeCacheManager); OvsdbInventoryServiceImpl ovsdbInventoryService = new OvsdbInventoryServiceImpl(dataBroker); registerService(context, new String[] { OvsdbInventoryService.class.getName() }, null, ovsdbInventoryService); // Call .setDependencies() starting with the last service registered for (int i = servicesAndRegistrations.size() - 1; i >= 0; i--) { Pair<Object, ServiceRegistration> serviceAndRegistration = servicesAndRegistrations.get(i); Object service = serviceAndRegistration.getLeft(); ServiceRegistration<?> serviceRegistration = serviceAndRegistration.getRight(); LOG.info("Setting dependencies on service {}/{}, {}", i, servicesAndRegistrations.size(), service.getClass()); if (service instanceof ConfigInterface) { ((ConfigInterface) service) .setDependencies(serviceRegistration != null ? serviceRegistration.getReference() : null); LOG.info("Dependencies set"); } else { LOG.warn("Service isn't a ConfigInterface"); } } // TODO check if services are already available and setDependencies // addingService may not be called if the service is already available when the ServiceTracker // is started trackService(context, INeutronNetworkCRUD.class, tenantNetworkManager, networkHandler, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler, neutronL3Adapter, distributedArpService, vlanProvider, southboundHandler); trackService(context, INeutronSubnetCRUD.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler, securityServices, neutronL3Adapter); trackService(context, INeutronPortCRUD.class, tenantNetworkManager, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler, securityServices, neutronL3Adapter, distributedArpService, portHandler, vlanProvider); trackService(context, INeutronFloatingIPCRUD.class, neutronL3Adapter); trackService(context, INeutronLoadBalancerCRUD.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler); trackService(context, INeutronLoadBalancerPoolCRUD.class, lBaaSHandler, lBaaSPoolMemberHandler); trackService(context, LoadBalancerProvider.class, lBaaSHandler, lBaaSPoolHandler, lBaaSPoolMemberHandler); trackService(context, L2ForwardingProvider.class, southboundHandler); trackService(context, ArpProvider.class, neutronL3Adapter, distributedArpService); trackService(context, VLANProvider.class, neutronL3Adapter, vlanProvider); trackService(context, InboundNatProvider.class, neutronL3Adapter); trackService(context, OutboundNatProvider.class, neutronL3Adapter); trackService(context, VlanResponderProvider.class, vlanProvider); trackService(context, RoutingProvider.class, neutronL3Adapter); trackService(context, L3ForwardingProvider.class, neutronL3Adapter); trackService(context, GatewayMacResolver.class, neutronL3Adapter); trackService(context, IngressAclProvider.class, securityServices); trackService(context, EgressAclProvider.class, securityServices); trackService(context, IcmpEchoProvider.class, neutronL3Adapter); // We no longer need to track the services, avoid keeping references around servicesAndRegistrations.clear(); }
From source file:org.millr.slick.impl.services.OsgiServiceImpl.java
public boolean setProperties(final String pid, final Map<String, Object> properties) { try {// ww w . j ava 2s . co m Configuration conf = configAdmin.getConfiguration(pid); @SuppressWarnings("unchecked") Dictionary<String, Object> props = conf.getProperties(); if (props == null) { props = new Hashtable<String, Object>(); } for (Map.Entry<String, Object> entry : properties.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); props.put(key, value != null ? value : StringUtils.EMPTY); } conf.update(props); } catch (IOException e) { LOGGER.error("Could not set property", e); return false; } return true; }
From source file:org.opennaas.extensions.pdu.capability.AbstractNotQueueingCapability.java
/** * Register the capability like a web service through DOSGi * /*from w w w . j a va 2 s.c o m*/ * @param name * @param resourceId * @return * @throws CapabilityException */ protected ServiceRegistration registerService(BundleContext bundleContext, String capabilityName, String resourceType, String resourceName, String ifaceName, Dictionary<String, String> props) throws CapabilityException { try { ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(bundleContext); String url = configurationAdmin.getProperty("org.opennaas", "ws.rest.url"); if (props != null) { // Rest props.put("service.exported.interfaces", "*"); props.put("service.exported.configs", "org.apache.cxf.rs"); props.put("service.exported.intents", "HTTP"); props.put("org.apache.cxf.rs.httpservice.context", url + "/" + resourceType + "/" + resourceName + "/" + capabilityName); props.put("org.apache.cxf.rs.address", "/"); props.put("org.apache.cxf.httpservice.requirefilter", "true"); } log.info("Registering ws: \n " + "in url: " + props.get("org.apache.cxf.rs.address") + "\n" + "in context: " + props.get("org.apache.cxf.rs.httpservice.context")); registration = bundleContext.registerService(ifaceName, this, props); } catch (IOException e) { throw new CapabilityException(e); } return registration; }
From source file:org.sakaiproject.nakamura.user.servlet.CreateSakaiGroupServlet.java
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(justification = "If there is an exception, the user is certainly not admin", value = { "REC_CATCH_EXCEPTION" }) protected void handleOperation(SlingHttpServletRequest request, HtmlResponse response, List<Modification> changes) throws RepositoryException { // KERN-432 dont allow anon users to access create group. if (SecurityConstants.ANONYMOUS_ID.equals(request.getRemoteUser())) { response.setStatus(403, "AccessDenied"); return;/* w w w .j ava 2 s .c o m*/ } // check that the submitted parameter values have valid values. final String principalName = request.getParameter(SlingPostConstants.RP_NODE_NAME); if (principalName == null) { throw new RepositoryException("Group name was not submitted"); } NameSanitizer san = new NameSanitizer(principalName, false); san.validate(); // check for allow create Group boolean allowCreateGroup = false; User currentUser = null; try { Session currentSession = request.getResourceResolver().adaptTo(Session.class); UserManager um = AccessControlUtil.getUserManager(currentSession); currentUser = (User) um.getAuthorizable(currentSession.getUserID()); if (currentUser.isAdmin()) { LOGGER.debug("User is an admin "); allowCreateGroup = true; } else { LOGGER.debug("Checking for membership of one of {} ", Arrays.toString(authorizedGroups)); PrincipalManager principalManager = AccessControlUtil.getPrincipalManager(currentSession); PrincipalIterator pi = principalManager .getGroupMembership(principalManager.getPrincipal(currentSession.getUserID())); Set<String> groups = new HashSet<String>(); for (; pi.hasNext();) { groups.add(pi.nextPrincipal().getName()); } for (String groupName : authorizedGroups) { if (groups.contains(groupName)) { allowCreateGroup = true; break; } // TODO: move this nasty hack into the PrincipalManager dynamic groups need to // be in the principal manager for this to work. if ("authenticated".equals(groupName) && !SecurityConstants.ADMIN_ID.equals(currentUser.getID())) { allowCreateGroup = true; break; } // just check via the user manager for dynamic resolution. Group group = (Group) um.getAuthorizable(groupName); LOGGER.debug("Checking for group {} {} ", groupName, group); if (group != null && group.isMember(currentUser)) { allowCreateGroup = true; LOGGER.debug("User is a member of {} {} ", groupName, group); break; } } } } catch (Exception ex) { LOGGER.warn("Failed to determin if the user is an admin, assuming not. Cause: " + ex.getMessage()); allowCreateGroup = false; } if (!allowCreateGroup) { LOGGER.debug("User is not allowed to create groups "); response.setStatus(HttpServletResponse.SC_FORBIDDEN, "User is not allowed to create groups"); return; } Session session = getSession(); try { UserManager userManager = AccessControlUtil.getUserManager(session); Authorizable authorizable = userManager.getAuthorizable(principalName); if (authorizable != null) { // principal already exists! response.setStatus(400, "A principal already exists with the requested name: " + principalName); return; } else { Group group = userManager.createGroup(new Principal() { public String getName() { return principalName; } }); String groupPath = AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PREFIX + group.getID(); Map<String, RequestProperty> reqProperties = collectContent(request, response, groupPath); response.setPath(groupPath); response.setLocation(externalizePath(request, groupPath)); response.setParentLocation( externalizePath(request, AuthorizableResourceProvider.SYSTEM_USER_MANAGER_GROUP_PATH)); changes.add(Modification.onCreated(groupPath)); // It is not allowed to touch the rep:group-managers property directly. String key = SYSTEM_USER_MANAGER_GROUP_PREFIX + principalName + "/"; reqProperties.remove(key + PROP_GROUP_MANAGERS); reqProperties.remove(key + PROP_GROUP_VIEWERS); // write content from form writeContent(session, group, reqProperties, changes); // update the group memberships, although this uses session from the request, it // only // does so for finding authorizables, so its ok that we are using an admin session // here. updateGroupMembership(request, group, changes); // TODO We should probably let the client decide whether the // current user belongs in the managers list or not. updateOwnership(request, group, new String[] { currentUser.getID() }, changes); try { postProcessorService.process(group, session, ModificationType.CREATE, request); } catch (RepositoryException e) { LOGGER.info("Failed to create Group {}", e.getMessage()); response.setStatus(HttpServletResponse.SC_CONFLICT, e.getMessage()); return; } catch (Exception e) { LOGGER.warn(e.getMessage(), e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return; } // Launch an OSGi event for creating a group. try { Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put(UserConstants.EVENT_PROP_USERID, principalName); EventUtils.sendOsgiEvent(properties, UserConstants.TOPIC_GROUP_CREATED, eventAdmin); } catch (Exception e) { // Trap all exception so we don't disrupt the normal behaviour. LOGGER.error("Failed to launch an OSGi event for creating a user.", e); } } } catch (RepositoryException re) { LOGGER.info("Failed to create Group {}", re.getMessage()); LOGGER.debug("Failed to create Group Cause {}", re, re.getMessage()); response.setStatus(HttpServletResponse.SC_CONFLICT, re.getMessage()); return; } finally { ungetSession(session); } }
From source file:org.opennaas.itests.roadm.alarms.MonitoringCapabilityTest.java
private void generateRawSocketEvent(String transportId, String message) { Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(MESSAGE_PROPERTY_NAME, message); properties.put(TRANSPORT_ID_PROPERTY_NAME, transportId); long creationTime = new Date().getTime(); properties.put(ARRIVAL_TIME_PROPERTY_NAME, creationTime); Event event = new Event(MSG_RCVD_EVENT_TOPIC, properties); eventManager.publishEvent(event);/*from w ww.j ava 2s . co m*/ log.debug("RawSocketTransport Event generated! " + message + " at " + creationTime); }
From source file:org.opennaas.extensions.queuemanager.QueueManager.java
@Override public void initialize() throws CapabilityException { Dictionary<String, String> props = new Hashtable<String, String>(); props.put(ResourceDescriptorConstants.CAPABILITY, "queue"); props.put(ResourceDescriptorConstants.CAPABILITY_NAME, resourceId); // registration = Activator.getContext().registerService( // IQueueManagerCapability.class.getName(), this, props); registerService(Activator.getContext(), CAPABILITY_TYPE, getResourceType(), getResourceName(), IQueueManagerCapability.class.getName(), props); super.initialize(); }
From source file:org.opennaas.core.protocols.sessionmanager.ProtocolSessionManager.java
public void registerAsOSGiService() throws ProtocolException { registration = null;// ww w . java 2 s .co m if (Activator.getBundleContext() != null) { Dictionary<String, String> props = new Hashtable<String, String>(); props.put("resourceId", resourceID); props = addWSRegistrationProperties(props); registration = Activator.getBundleContext().registerService(IProtocolSessionManager.class.getName(), this, props); } }
From source file:io.fabric8.karaf.core.properties.PlaceholderResolverImpl.java
@Override public boolean replaceAll(Dictionary<String, Object> dictionary) { int replacedCount = 0; Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement(); final Object val = dictionary.get(key); if (val instanceof String) { StringBuilder sb = Support.acquireStringBuilder((String) val); if (substitutor.replaceIn(sb)) { replacedCount++;/*from w w w . j a v a 2 s. c o m*/ dictionary.put(key, sb.toString()); } } } return replacedCount > 0; }