List of usage examples for javax.naming Context INITIAL_CONTEXT_FACTORY
String INITIAL_CONTEXT_FACTORY
To view the source code for javax.naming Context INITIAL_CONTEXT_FACTORY.
Click Source Link
From source file:hudson.security.LDAPSecurityRealm.java
/** * Infer the root DN.// w w w.j a v a 2 s . c o m * * @return null if not found. */ private String inferRootDN(String server) { try { Hashtable<String, String> props = new Hashtable<String, String>(); if (managerDN != null) { props.put(Context.SECURITY_PRINCIPAL, managerDN); props.put(Context.SECURITY_CREDENTIALS, getManagerPassword()); } props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); props.put(Context.PROVIDER_URL, getServerUrl() + '/'); DirContext ctx = new InitialDirContext(props); Attributes atts = ctx.getAttributes(""); Attribute a = atts.get("defaultNamingContext"); if (a != null) // this entry is available on Active Directory. See http://msdn2.microsoft.com/en-us/library/ms684291(VS.85).aspx return a.toString(); a = atts.get("namingcontexts"); if (a == null) { LOGGER.warning("namingcontexts attribute not found in root DSE of " + server); return null; } return a.get().toString(); } catch (NamingException e) { LOGGER.log(Level.WARNING, "Failed to connect to LDAP to infer Root DN for " + server, e); return null; } }
From source file:org.apache.hadoop.security.LdapGroupsMapping.java
DirContext getDirContext() throws NamingException { if (ctx == null) { // Set up the initial environment for LDAP connectivity Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, com.sun.jndi.ldap.LdapCtxFactory.class.getName()); env.put(Context.PROVIDER_URL, ldapUrl); env.put(Context.SECURITY_AUTHENTICATION, "simple"); // Set up SSL security, if necessary if (useSsl) { env.put(Context.SECURITY_PROTOCOL, "ssl"); System.setProperty("javax.net.ssl.keyStore", keystore); System.setProperty("javax.net.ssl.keyStorePassword", keystorePass); }/*from ww w . j av a2 s. c o m*/ env.put(Context.SECURITY_PRINCIPAL, bindUser); env.put(Context.SECURITY_CREDENTIALS, bindPassword); env.put("com.sun.jndi.ldap.connect.timeout", conf.get(CONNECTION_TIMEOUT, String.valueOf(CONNECTION_TIMEOUT_DEFAULT))); env.put("com.sun.jndi.ldap.read.timeout", conf.get(READ_TIMEOUT, String.valueOf(READ_TIMEOUT_DEFAULT))); ctx = new InitialDirContext(env); } return ctx; }
From source file:org.apache.directory.server.operations.bind.MiscBindIT.java
/** * Test case for <a href="http://issues.apache.org/jira/browse/DIREVE-284" where users in * mixed case partitions were not able to authenticate properly. This test case creates * a new partition under dc=aPache,dc=org, it then creates the example user in the JIRA * issue and attempts to authenticate as that user. * * @throws Exception if the user cannot authenticate or test fails *///from ww w .j ava2 s . co m @Test public void testUserAuthOnMixedCaseSuffix() throws Exception { getLdapServer().getDirectoryService().setAllowAnonymousAccess(true); Hashtable<String, Object> env = new Hashtable<String, Object>(); env.put(Context.PROVIDER_URL, Network.ldapLoopbackUrl(getLdapServer().getPort()) + "/dc=aPache,dc=org"); env.put("java.naming.ldap.version", "3"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); InitialDirContext ctx = new InitialDirContext(env); Attributes attrs = ctx.getAttributes(""); assertTrue(attrs.get("dc").get().equals("aPache")); Attributes user = new BasicAttributes("cn", "Kate Bush", true); Attribute oc = new BasicAttribute("objectClass"); oc.add("top"); oc.add("person"); oc.add("organizationalPerson"); oc.add("inetOrgPerson"); user.put(oc); user.put("sn", "Bush"); user.put("userPassword", "Aerial"); ctx.createSubcontext("cn=Kate Bush", user); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_CREDENTIALS, "Aerial"); env.put(Context.SECURITY_PRINCIPAL, "cn=Kate Bush,dc=aPache,dc=org"); InitialDirContext userCtx = new InitialDirContext(env); assertNotNull(userCtx); ctx.destroySubcontext("cn=Kate Bush"); }
From source file:com.googlecode.fascinator.authentication.custom.ldap.CustomLdapAuthenticationHandler.java
private boolean bindSearchX(String username, String password, Hashtable<String, String> env, boolean bind) throws AuthenticationException, NamingException { env.put(Context.SECURITY_PRINCIPAL, ldapSecurityPrincipal); env.put(Context.SECURITY_CREDENTIALS, ldapSecurityCredentials); DirContext ctx = null;//from ww w . jav a2 s .c om try { ctx = new InitialDirContext(env); } catch (NamingException ne) { log.error("Failed to bind as: {}", ldapSecurityPrincipal); } // ensure we have the userPassword attribute at a minimum String[] attributeList = new String[] { "userPassword" }; SearchControls sc = new SearchControls(); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); sc.setReturningAttributes(attributeList); sc.setDerefLinkFlag(true); sc.setReturningObjFlag(false); sc.setTimeLimit(5000); String filter = "(" + filterPrefix + idAttr + "=" + username + filterSuffix + ")"; // Do the search NamingEnumeration<SearchResult> results = ctx.search(baseDn, filter, sc); if (!results.hasMore()) { log.warn("no valid user found."); return false; } SearchResult result = results.next(); log.debug("authenticating user: {}", result.getNameInNamespace()); if (bind) { // setup user context for binding Hashtable<String, String> userEnv = new Hashtable<String, String>(); userEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); userEnv.put(Context.SECURITY_AUTHENTICATION, "simple"); userEnv.put(Context.PROVIDER_URL, baseUrl); userEnv.put(Context.SECURITY_PRINCIPAL, result.getNameInNamespace()); userEnv.put(Context.SECURITY_CREDENTIALS, password); try { new InitialDirContext(userEnv); } catch (NamingException ne) { log.error("failed to authenticate user: " + result.getNameInNamespace()); throw ne; } } else { // get userPassword attribute Attribute up = result.getAttributes().get("userPassword"); if (up == null) { log.error("unable to read userPassword attribute for: {}", result.getNameInNamespace()); return false; } byte[] userPasswordBytes = (byte[]) up.get(); String userPassword = new String(userPasswordBytes); // compare passwords - also handles encodings if (!passwordsMatch(password, userPassword)) { return false; } } return true; }
From source file:com.alfaariss.oa.util.idmapper.jndi.JNDIMapper.java
/** * Reads JNDI connection information from the configuration. * <br>//from www. j a v a2s . c o m * Creates an <code>Hashtable</code> containing the JNDI environment variables. * @param oConfigurationManager The configuration manager * @param eConfig the configuration section * @return <code>DirContext</code> that contains the JNDI connection * @throws OAException if configuration reading fails */ private Hashtable<String, String> readJNDIContext(IConfigurationManager oConfigurationManager, Element eConfig) throws OAException { Hashtable<String, String> htEnvironment = new Hashtable<String, String>(11); try { Element eSecurityPrincipal = oConfigurationManager.getSection(eConfig, "security_principal"); if (eSecurityPrincipal == null) { _logger.error("No 'security_principal' section found in 'resource' configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } String sPrincipal = oConfigurationManager.getParam(eSecurityPrincipal, "dn"); if (sPrincipal == null) { _logger.error("No item 'dn' item found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } String sPassword = oConfigurationManager.getParam(eSecurityPrincipal, "password"); if (sPassword == null) { _logger.error("No 'password' item found in configuration "); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } String sDriver = oConfigurationManager.getParam(eConfig, "driver"); if (sDriver == null) { _logger.error("No 'driver' item found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } String sUrl = oConfigurationManager.getParam(eConfig, "url"); if (sUrl == null) { _logger.error("No valid config item 'url' found in configuration"); throw new OAException(SystemErrors.ERROR_CONFIG_READ); } if (sUrl.length() >= 5 && sUrl.substring(0, 5).equalsIgnoreCase("ldaps")) { // Request SSL transport htEnvironment.put(Context.SECURITY_PROTOCOL, "ssl"); _logger.info("SSL enabled"); } else { _logger.info("SSL disabled"); } htEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, sDriver); htEnvironment.put(Context.SECURITY_AUTHENTICATION, "simple"); htEnvironment.put(Context.SECURITY_PRINCIPAL, sPrincipal); htEnvironment.put(Context.SECURITY_CREDENTIALS, sPassword); htEnvironment.put(Context.PROVIDER_URL, sUrl); } catch (OAException e) { throw e; } catch (Exception e) { _logger.error("Could not create a connection", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } return htEnvironment; }
From source file:org.springframework.ldap.core.support.AbstractContextSource.java
private Hashtable setupAnonymousEnv() { if (pooled) { baseEnv.put(SUN_LDAP_POOLING_FLAG, "true"); log.debug("Using LDAP pooling."); } else {//from w ww.java2 s . c o m baseEnv.remove(SUN_LDAP_POOLING_FLAG); log.debug("Not using LDAP pooling"); } Hashtable env = new Hashtable(baseEnv); env.put(Context.INITIAL_CONTEXT_FACTORY, contextFactory.getName()); env.put(Context.PROVIDER_URL, assembleProviderUrlString(urls)); if (dirObjectFactory != null) { env.put(Context.OBJECT_FACTORIES, dirObjectFactory.getName()); } if (!StringUtils.isBlank(referral)) { env.put(Context.REFERRAL, referral); } if (!DistinguishedName.EMPTY_PATH.equals(base)) { // Save the base path for use in the DefaultDirObjectFactory. env.put(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY, base); } log.debug("Trying provider Urls: " + assembleProviderUrlString(urls)); return env; }
From source file:com.web.server.WebServer.java
/** * This is the start of the all the services in web server * @param args/* ww w.j a va 2s. com*/ * @throws IOException * @throws SAXException */ public static void main(String[] args) throws IOException, SAXException { Hashtable urlClassLoaderMap = new Hashtable(); Hashtable executorServicesMap = new Hashtable(); Hashtable ataMap = new Hashtable<String, ATAConfig>(); Hashtable messagingClassMap = new Hashtable(); ConcurrentHashMap servletMapping = new ConcurrentHashMap(); DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); final ServerConfig serverconfig = (ServerConfig) serverdigester .parse(new InputSource(new FileInputStream("./config/serverconfig.xml"))); DigesterLoader messagingdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/messagingconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester messagingdigester = messagingdigesterLoader.newDigester(); MessagingElem messagingconfig = (MessagingElem) messagingdigester .parse(new InputSource(new FileInputStream("./config/messaging.xml"))); //System.out.println(messagingconfig); ////System.out.println(serverconfig.getDeploydirectory()); PropertyConfigurator.configure("log4j.properties"); /*MemcachedClient cache=new MemcachedClient( new InetSocketAddress("localhost", 1000));*/ // Store a value (async) for one hour //c.set("someKey", 36, new String("arun")); // Retrieve a value. System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); ExecutorService executor = java.util.concurrent.Executors.newCachedThreadPool(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = null; try { name = new ObjectName("com.web.server:type=WarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } WarDeployer warDeployer = new WarDeployer(serverconfig.getDeploydirectory(), serverconfig.getFarmWarDir(), serverconfig.getClustergroup(), urlClassLoaderMap, executorServicesMap, messagingClassMap, servletMapping, messagingconfig, sessionObjects); warDeployer.setPriority(MIN_PRIORITY); try { mbs.registerMBean(warDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //warDeployer.start(); executor.execute(warDeployer); ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getPort()))); serverSocketChannel.configureBlocking(false); final byte[] shutdownBt = new byte[50]; WebServerRequestProcessor webserverRequestProcessor = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 1); webserverRequestProcessor.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //webserverRequestProcessor.start(); executor.execute(webserverRequestProcessor); for (int i = 0; i < 10; i++) { WebServerRequestProcessor webserverRequestProcessor1 = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 2); webserverRequestProcessor1.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverRequestProcessor1); } ServerSocketChannel serverSocketChannelServices = ServerSocketChannel.open(); serverSocketChannelServices .bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getServicesport()))); serverSocketChannelServices.configureBlocking(false); ExecutorServiceThread executorService = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //executorService.start(); executor.execute(executorService); for (int i = 0; i < 10; i++) { ExecutorServiceThread executorService1 = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(executorService1); } WebServerHttpsRequestProcessor webserverHttpsRequestProcessor = new WebServer().new WebServerHttpsRequestProcessor( servletMapping, urlClassLoaderMap, Integer.parseInt(serverconfig.getHttpsport()), serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), serverconfig.getHttpscertificatepath(), serverconfig.getHttpscertificatepasscode(), 1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } webserverHttpsRequestProcessor.setPriority(MAX_PRIORITY); //webserverRequestProcessor.start(); executor.execute(webserverHttpsRequestProcessor); /* for(int i=0;i<2;i++){ webserverHttpsRequestProcessor=new WebServer().new WebServerHttpsRequestProcessor(urlClassLoaderMap,Integer.parseInt(serverconfig.getHttpsport())+(i+1),serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),serverconfig.getHttpscertificatepath(),serverconfig.getHttpscertificatepasscode(),1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverHttpsRequestProcessor); }*/ /*ATAServer ataServer=new ATAServer(serverconfig.getAtaaddress(),serverconfig.getAtaport(),ataMap); try { name = new ObjectName("com.web.services:type=ATAServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataServer.start();*/ /*ATAConfigClient ataClient=new ATAConfigClient(serverconfig.getAtaaddress(),serverconfig.getAtaport(),serverconfig.getServicesport(),executorServicesMap); try { name = new ObjectName("com.web.services:type=ATAConfigClient"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataClient, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataClient.start();*/ MessagingServer messageServer = new MessagingServer(serverconfig.getMessageport(), messagingClassMap); try { name = new ObjectName("com.web.messaging:type=MessagingServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(messageServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //messageServer.start(); executor.execute(messageServer); RandomQueueMessagePicker randomqueuemessagepicker = new RandomQueueMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RandomQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(randomqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //randomqueuemessagepicker.start(); executor.execute(randomqueuemessagepicker); RoundRobinQueueMessagePicker roundrobinqueuemessagepicker = new RoundRobinQueueMessagePicker( messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RoundRobinQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(roundrobinqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //roundrobinqueuemessagepicker.start(); executor.execute(roundrobinqueuemessagepicker); TopicMessagePicker topicpicker = new TopicMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=TopicMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(topicpicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //topicpicker.start(); executor.execute(topicpicker); try { name = new ObjectName("com.web.server:type=SARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } SARDeployer sarDeployer = SARDeployer.newInstance(serverconfig.getDeploydirectory()); try { mbs.registerMBean(sarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(sarDeployer); /*try { mbs.invoke(name, "startDeployer", null, null); } catch (InstanceNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReflectionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (MBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); System.setProperty(Context.PROVIDER_URL, "rmi://localhost:" + serverconfig.getServicesregistryport()); ; Registry registry = LocateRegistry.createRegistry(Integer.parseInt(serverconfig.getServicesregistryport())); /*JarDeployer jarDeployer=new JarDeployer(registry,serverconfig.getServicesdirectory(), serverconfig.getServiceslibdirectory(),serverconfig.getCachedir(),executorServicesMap, urlClassLoaderMap); try { name = new ObjectName("com.web.server:type=JarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(jarDeployer);*/ EARDeployer earDeployer = new EARDeployer(registry, serverconfig.getEarservicesdirectory(), serverconfig.getDeploydirectory(), executorServicesMap, urlClassLoaderMap, serverconfig.getCachedir(), warDeployer); try { name = new ObjectName("com.web.server:type=EARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(earDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //earDeployer.start(); executor.execute(earDeployer); JVMConsole jvmConsole = new JVMConsole(Integer.parseInt(serverconfig.getJvmConsolePort())); try { name = new ObjectName("com.web.server:type=JVMConsole"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jvmConsole, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(jvmConsole); ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); XMLDeploymentScanner xmlDeploymentScanner = new XMLDeploymentScanner(serverconfig.getDeploydirectory(), serverconfig.getServiceslibdirectory()); exec.scheduleAtFixedRate(xmlDeploymentScanner, 0, 1000, TimeUnit.MILLISECONDS); EmbeddedJMS embeddedJMS = null; try { embeddedJMS = new EmbeddedJMS(); embeddedJMS.start(); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } EJBDeployer ejbDeployer = new EJBDeployer(serverconfig.getServicesdirectory(), registry, Integer.parseInt(serverconfig.getServicesregistryport()), embeddedJMS); try { name = new ObjectName("com.web.server:type=EJBDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ejbDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(ejbDeployer); new Thread() { public void run() { try { ServerSocket serverSocket = new ServerSocket(Integer.parseInt(serverconfig.getShutdownport())); while (true) { Socket sock = serverSocket.accept(); InputStream istream = sock.getInputStream(); istream.read(shutdownBt); String shutdownStr = new String(shutdownBt); String[] shutdownToken = shutdownStr.split("\r\n\r\n"); //System.out.println(shutdownStr); if (shutdownToken[0].startsWith("shutdown WebServer")) { synchronized (shutDownObject) { shutDownObject.notifyAll(); } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { System.out.println("IN shutdown Hook"); synchronized (shutDownObject) { shutDownObject.notifyAll(); } } })); try { synchronized (shutDownObject) { shutDownObject.wait(); } executor.shutdownNow(); serverSocketChannel.close(); serverSocketChannelServices.close(); embeddedJMS.stop(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("IN shutdown Hook1"); /*try{ Thread.sleep(10000); } catch(Exception ex){ }*/ //webserverRequestProcessor.stop(); //webserverRequestProcessor1.stop(); /*warDeployer.stop(); executorService.stop(); //ataServer.stop(); //ataClient.stop(); messageServer.stop(); randomqueuemessagepicker.stop(); roundrobinqueuemessagepicker.stop(); topicpicker.stop();*/ /*try { mbs.invoke(new ObjectName("com.web.server:type=SARDeployer"), "destroyDeployer", null, null); } catch (InstanceNotFoundException | MalformedObjectNameException | ReflectionException | MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //earDeployer.stop(); System.exit(0); }
From source file:it.doqui.index.ecmengine.client.engine.EcmEngineDirectDelegateImpl.java
protected EcmEngineMassiveBusinessInterface createMassiveService() throws Throwable { this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] BEGIN "); Properties properties = new Properties(); // Caricamento del file contenenti le properties su cui fare il binding rb = ResourceBundle.getBundle(ECMENGINE_PROPERTIES_FILE); // Caricamento delle proprieta' su cui fare il binding all'oggetto di business delle funzionalita' // implementate per la ricerca. try {// w w w . j a v a2s . com this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] P-Delegata di massive."); this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] context factory vale : " + rb.getString(ECMENGINE_CONTEXT_FACTORY)); properties.put(Context.INITIAL_CONTEXT_FACTORY, rb.getString(ECMENGINE_CONTEXT_FACTORY)); this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] url to connect vale : " + rb.getString(ECMENGINE_URL_TO_CONNECT)); properties.put(Context.PROVIDER_URL, rb.getString(ECMENGINE_URL_TO_CONNECT)); // Controllo che la property cluster partition sia valorizzata per capire se // sto lavorando in una configurazione in cluster oppure no String clusterPartition = rb.getString(ECMENGINE_CLUSTER_PARTITION); this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] clusterPartition vale : " + clusterPartition); if (clusterPartition != null && clusterPartition.length() > 0) { properties.put("jnp.partitionName", clusterPartition); this.log.debug( "[" + getClass().getSimpleName() + "::createMassiveService] disable discovery vale : " + rb.getString(ECMENGINE_DISABLE_DISCOVERY)); properties.put("jnp.disableDiscovery", rb.getString(ECMENGINE_DISABLE_DISCOVERY)); } // Get an initial context InitialContext jndiContext = new InitialContext(properties); log.debug("[" + getClass().getSimpleName() + "::createMassiveService] context istanziato"); // Get a reference to the Bean Object ref = jndiContext.lookup(ECMENGINE_MASSIVE_JNDI_NAME); // Get a reference from this to the Bean's Home interface EcmEngineMassiveHome home = (EcmEngineMassiveHome) PortableRemoteObject.narrow(ref, EcmEngineMassiveHome.class); // Create an Adder object from the Home interface return home.create(); } catch (Throwable e) { this.log.error("[" + getClass().getSimpleName() + "::createMassiveService] " + "Impossibile l'EJB di security: " + e.getMessage()); throw e; } finally { this.log.debug("[" + getClass().getSimpleName() + "::createMassiveService] END "); } }
From source file:org.rhq.enterprise.server.naming.AccessCheckingInitialContextFactoryBuilder.java
/** * Create a InitialContext factory. If the environment does not override the factory class it will use the * default context factory./*from ww w . j a va2s.c om*/ * * @param environment The environment * @return An initial context factory * @throws NamingException If an error occurs loading the factory class. */ public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> environment) throws NamingException { final String factoryClassName = (String) environment.get(Context.INITIAL_CONTEXT_FACTORY); if (factoryClassName == null || factoryClassName.equals(defaultFactoryClassName)) { if (LOG.isDebugEnabled()) { LOG.debug("No " + Context.INITIAL_CONTEXT_FACTORY + " set. Using the default factory."); } return defaultFactory; } final ClassLoader classLoader = getContextClassLoader(); try { final Class<?> factoryClass = Class.forName(factoryClassName, true, classLoader); InitialContextFactory configuredFactory = (InitialContextFactory) factoryClass.newInstance(); return FactoryType.detect(environment, pretendNoFactoryBuilder).wrap(configuredFactory); } catch (Exception e) { NamingException ne = new NamingException("Failed instantiate InitialContextFactory " + factoryClassName + " from classloader " + classLoader); ne.initCause(e); throw ne; } }
From source file:io.apiman.gateway.engine.policies.BasicAuthLDAPTest.java
private DirContext createContext() throws NamingException { // Create a environment container Hashtable<Object, Object> env = new Hashtable<>(); String url = "ldap://" + LDAP_SERVER + ":" + ldapServer.getPort(); // Create a new context pointing to the partition env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system"); env.put(Context.SECURITY_CREDENTIALS, "secret"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); // Let's open a connection on this partition InitialContext initialContext = new InitialContext(env); // We should be able to read it DirContext appRoot = (DirContext) initialContext.lookup(""); Assert.assertNotNull(appRoot);/*from ww w . j a v a 2 s . c o m*/ return appRoot; }