List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:org.pentaho.di.trans.steps.mailvalidator.MailValidation.java
private static ArrayList<String> getMX(String hostName) throws NamingException { // Perform a DNS lookup for MX records in the domain Hashtable<String, String> env = new Hashtable<String, String>(); env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory"); DirContext ictx = new InitialDirContext(env); Attributes attrs = ictx.getAttributes(hostName, new String[] { "MX" }); Attribute attr = attrs.get("MX"); // if we don't have an MX record, try the machine itself if ((attr == null) || (attr.size() == 0)) { attrs = ictx.getAttributes(hostName, new String[] { "A" }); attr = attrs.get("A"); if (attr == null) { throw new NamingException(BaseMessages.getString(PKG, "MailValidator.NoMatchName", hostName)); }/*from w w w.j a v a 2 s .c o m*/ } // Huzzah! we have machines to try. Return them as an array list // NOTE: We SHOULD take the preference into account to be absolutely // correct. This is left as an exercise for anyone who cares. ArrayList<String> res = new ArrayList<String>(); NamingEnumeration<?> en = attr.getAll(); while (en.hasMore()) { String x = (String) en.next(); String[] f = x.split(" "); if (f[1].endsWith(".")) { f[1] = f[1].substring(0, (f[1].length() - 1)); } res.add(f[1]); } return res; }
From source file:org.pepstock.jem.annotations.SetFields.java
private static void checkIfIsRightObject(String name, boolean isDD) throws NamingException { InitialContext ic = ContextUtils.getContext(); NamingEnumeration<NameClassPair> list = ic.list(name); boolean isDataDescription = false; while (list.hasMore()) { NameClassPair pair = list.next(); // checks if is datastream // only datastreams are changed if (pair instanceof DataStreamNameClassPair) { isDataDescription = true;//from w w w .j a va 2 s . c om } } if (isDD && !isDataDescription) { throw new NamingException(name + " is not a data description"); } if (!isDD && isDataDescription) { throw new NamingException(name + " is not a data source"); } }
From source file:org.rhq.enterprise.server.core.CustomJaasDeploymentService.java
private void validateLdapOptions(Map<String, String> options) throws NamingException { Properties env = new Properties(); String factory = options.get(Context.INITIAL_CONTEXT_FACTORY); if (factory == null) { throw new NamingException("No initial context factory"); }/*ww w. ja v a 2s . c o m*/ String url = options.get(Context.PROVIDER_URL); if (url == null) { throw new NamingException("Naming provider url not set"); } String protocol = options.get(Context.SECURITY_PROTOCOL); if ("ssl".equals(protocol)) { String ldapSocketFactory = env.getProperty("java.naming.ldap.factory.socket"); if (ldapSocketFactory == null) { env.put("java.naming.ldap.factory.socket", UntrustedSSLSocketFactory.class.getName()); } env.put(Context.SECURITY_PROTOCOL, "ssl"); } env.setProperty(Context.INITIAL_CONTEXT_FACTORY, factory); env.setProperty(Context.PROVIDER_URL, url); // Load any information we may need to bind String bindDN = options.get("BindDN"); String bindPW = options.get("BindPW"); if ((bindDN != null) && (bindDN.length() != 0) && (bindPW != null) && (bindPW.length() != 0)) { env.setProperty(Context.SECURITY_PRINCIPAL, bindDN); env.setProperty(Context.SECURITY_CREDENTIALS, bindPW); env.setProperty(Context.SECURITY_AUTHENTICATION, "simple"); } log.debug("Validating LDAP properties. Initializing context..."); new InitialLdapContext(env, null).close(); return; }
From source file:org.rhq.enterprise.server.naming.AccessCheckingInitialContextFactoryBuilder.java
private static InitialContextFactory getJbossDefaultInitialContextFactory() throws NamingException { try {/*from www .j a v a 2 s .co m*/ Class<?> cls = Class.forName("org.jboss.as.naming.InitialContextFactory"); return (InitialContextFactory) cls.newInstance(); } catch (Exception e) { NamingException ne = new NamingException( "Failed to obtain the default initial context factory from JBoss AS."); ne.initCause(e); throw ne; } }
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 w w w.ja v a 2 s .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:org.rhq.jndi.AccessCheckingInitialContextFactoryBuilder.java
/** * Create a InitialContext factory. If the environment does not override the factory class it will use the * default context factory./*from w w w . ja v a2 s. 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) { if (LOG.isDebugEnabled()) { LOG.debug("No " + Context.INITIAL_CONTEXT_FACTORY + " set. Using the default factory."); } return DEFAULT_FACTORY; } final ClassLoader classLoader = getContextClassLoader(); try { final Class<?> factoryClass = Class.forName(factoryClassName, true, classLoader); InitialContextFactory configuredFactory = (InitialContextFactory) factoryClass.newInstance(); return createSecureWrapper(configuredFactory, environment); } catch (Exception e) { throw new NamingException("Failed instantiate InitialContextFactory " + factoryClassName + " from classloader " + classLoader); } }
From source file:org.sonar.plugins.ldap.LdapContextFactory.java
private InitialDirContext createInitialDirContext(String principal, String credentials, boolean pooling) throws NamingException { final InitialLdapContext ctx; if (startTLS) { // Note that pooling is not enabled for such connections, because "Stop TLS" is not performed. Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, factory); env.put(Context.PROVIDER_URL, providerUrl); env.put(Context.REFERRAL, DEFAULT_REFERRAL); // At this point env should not contain properties SECURITY_AUTHENTICATION, SECURITY_PRINCIPAL and SECURITY_CREDENTIALS to avoid "bind" operation prior to StartTLS: ctx = new InitialLdapContext(env, null); // http://docs.oracle.com/javase/jndi/tutorial/ldap/ext/starttls.html StartTlsResponse tls = (StartTlsResponse) ctx.extendedOperation(new StartTlsRequest()); try {/*from www . j a va 2s . com*/ tls.negotiate(); } catch (IOException e) { NamingException ex = new NamingException("StartTLS failed"); ex.initCause(e); throw ex; } // Explicitly initiate "bind" operation: ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, authentication); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, principal); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, credentials); ctx.reconnect(null); } else { ctx = new InitialLdapContext(getEnvironment(principal, credentials, pooling), null); } return ctx; }
From source file:org.sonar.plugins.ldap.LdapContextFactory.java
private InitialDirContext createInitialDirContextUsingGssapi(String principal, String credentials) throws NamingException { Configuration.setConfiguration(new Krb5LoginConfiguration()); InitialDirContext initialDirContext; try {/*from ww w .j ava 2 s . c o m*/ LoginContext lc = new LoginContext(getClass().getName(), new CallbackHandlerImpl(principal, credentials)); lc.login(); initialDirContext = Subject.doAs(lc.getSubject(), new PrivilegedExceptionAction<InitialDirContext>() { @Override public InitialDirContext run() throws NamingException { Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, factory); env.put(Context.PROVIDER_URL, providerUrl); env.put(Context.REFERRAL, DEFAULT_REFERRAL); return new InitialLdapContext(env, null); } }); } catch (LoginException | PrivilegedActionException e) { NamingException namingException = new NamingException(e.getMessage()); namingException.initCause(e); throw namingException; } return initialDirContext; }
From source file:org.sonar.server.database.JndiDatabaseConnector.java
private void createJNDISubContexts(Context ctx, String jndiBinding) throws NamingException { Name name = new CompositeName(jndiBinding); for (int i = 0; i < name.size() - 1; i++) { String namingContext = name.get(i); try {//from w w w . ja v a 2 s .c o m Object obj = ctx.lookup(namingContext); if (!(obj instanceof Context)) { throw new NamingException(namingContext + " is not a JNDI Context"); } } catch (NameNotFoundException ex) { ctx = ctx.createSubcontext(namingContext); } } }
From source file:org.springframework.ldap.pool.DelegatingContext.java
/** * @throws NamingException If the delegate is null, {@link #close()} has been called. *///from ww w .j av a 2 s . c om protected void assertOpen() throws NamingException { if (this.delegateContext == null) { throw new NamingException("Context is closed."); } }