List of usage examples for javax.naming NamingException NamingException
public NamingException()
From source file:de.escidoc.core.admin.common.util.spring.RemoteJndiLocator.java
/** * Business interface is required for casting. If the interface does not * exist an exception is thrown.//from w w w. j a va 2 s. c o m * * @throws NamingException * From the lookup */ public void afterPropertiesSet() throws NamingException { try { setInitialContextJndiProperties(); } catch (WebserverSystemException e) { NamingException ex = new NamingException(); ex.setRootCause(e); throw ex; } super.afterPropertiesSet(); }
From source file:net.sourceforge.vulcan.jabber.JdbcScreenNameMapperTest.java
public void testHandlesNamingException() throws Exception { namingException = new NamingException(); assertEquals(Collections.emptyMap(), mapper.lookupByAuthor(makeAuthorList("Sam", "Tara"))); }
From source file:com.enioka.jqm.tools.JndiContext.java
@Override public Object lookup(String name) throws NamingException { if (name == null) { throw new IllegalArgumentException("name cannot be null"); }/* www . j a va 2 s . co m*/ jqmlogger.trace("Looking up a JNDI element named " + name); // Special delegated cases if (name.startsWith("rmi:")) { try { return this.r.lookup(name.split("/")[3]); } catch (Exception e) { NamingException e1 = new NamingException(); e1.setRootCause(e); throw e1; } } if (name.endsWith("serverName")) { return JqmEngine.latestNodeStartedName; } // If in cache... if (singletons.containsKey(name)) { jqmlogger.trace("JNDI element named " + name + " found in cache."); return singletons.get(name); } // Retrieve the resource description from the database or the XML file JndiResourceDescriptor d = ResourceParser.getDescriptor(name); jqmlogger.trace("JNDI element named " + name + " not found in cache. Will be created. Singleton status: " + d.isSingleton()); // Singleton handling is synchronized to avoid double creation if (d.isSingleton()) { synchronized (singletons) { if (singletons.containsKey(name)) { return singletons.get(name); } // We use the current thread loader to find the resource and resource factory class - ext is inside that CL. // This is done only for payload CL - engine only need ext, not its own CL (as its own CL does NOT include ext). Object res = null; try { ResourceFactory rf = new ResourceFactory(Thread.currentThread() .getContextClassLoader() instanceof com.enioka.jqm.tools.JarClassLoader ? Thread.currentThread().getContextClassLoader() : extResources); res = rf.getObjectInstance(d, null, this, new Hashtable<String, Object>()); } catch (Exception e) { jqmlogger.warn("Could not instanciate singleton JNDI object resource " + name, e); NamingException ex = new NamingException(e.getMessage()); ex.initCause(e); throw ex; } // Cache result if (res.getClass().getClassLoader() instanceof JarClassLoader) { jqmlogger.warn( "A JNDI resource was defined as singleton but was loaded by a payload class loader - it won't be cached to avoid class loader leaks"); } else { singletons.put(name, res); // Pool JMX registration (only if cached - avoids leaks) if ("org.apache.tomcat.jdbc.pool.DataSourceFactory".equals(d.getFactoryClassName()) && (d.get("jmxEnabled") == null ? true : Boolean.parseBoolean((String) d.get("jmxEnabled").getContent()))) { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName jmxname = new ObjectName("com.enioka.jqm:type=JdbcPool,name=" + name); mbs.registerMBean(res.getClass().getMethod("getPool").invoke(res).getClass() .getMethod("getJmxPool") .invoke(res.getClass().getMethod("getPool").invoke(res)), jmxname); jmxNames.add(jmxname); } catch (Exception e) { jqmlogger.warn("Could not register JMX MBean for resource.", e); } } } // Done return res; } } // Non singleton try { // We use the current thread loader to find the resource and resource factory class - ext is inside that CL. // This is done only for payload CL - engine only need ext, not its own CL (as its own CL does NOT include ext). ResourceFactory rf = new ResourceFactory( Thread.currentThread().getContextClassLoader() instanceof com.enioka.jqm.tools.JarClassLoader ? Thread.currentThread().getContextClassLoader() : extResources); return rf.getObjectInstance(d, null, this, new Hashtable<String, Object>()); } catch (Exception e) { jqmlogger.warn("Could not instanciate JNDI object resource " + name, e); NamingException ex = new NamingException(e.getMessage()); ex.initCause(e); throw ex; } }
From source file:com.globalsight.everest.usermgr.UserLdapHelper.java
public static void authenticate(String password, String truePassword) throws NamingException { if (encyptMD5Password(password).equals(truePassword) || password.equals(truePassword) || encyptShaPassword(password).equals(truePassword)) { return;/*from w w w. j a va2s . co m*/ } else { throw new NamingException(); } }
From source file:org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper.java
private void doGssapiBind(final InnerRunnable innerRunnable) throws NamingException { File configFile = null;/* w ww . ja v a 2 s. c o m*/ try { Preferences preferences = ConnectionCorePlugin.getDefault().getPluginPreferences(); boolean useKrb5SystemProperties = preferences .getBoolean(ConnectionCoreConstants.PREFERENCE_USE_KRB5_SYSTEM_PROPERTIES); String krb5LoginModule = preferences.getString(ConnectionCoreConstants.PREFERENCE_KRB5_LOGIN_MODULE); if (!useKrb5SystemProperties) { // Kerberos Configuration switch (connection.getConnectionParameter().getKrb5Configuration()) { case DEFAULT: // nothing System.clearProperty("java.security.krb5.conf"); //$NON-NLS-1$ break; case FILE: // use specified krb5.conf System.setProperty("java.security.krb5.conf", connection.getConnectionParameter() //$NON-NLS-1$ .getKrb5ConfigurationFile()); break; case MANUAL: // write manual config parameters to connection specific krb5.conf file String fileName = Utils.getFilenameString(connection.getId()) + ".krb5.conf"; //$NON-NLS-1$ configFile = ConnectionCorePlugin.getDefault().getStateLocation().append(fileName).toFile(); String realm = connection.getConnectionParameter().getKrb5Realm(); String host = connection.getConnectionParameter().getKrb5KdcHost(); int port = connection.getConnectionParameter().getKrb5KdcPort(); StringBuilder sb = new StringBuilder(); sb.append("[libdefaults]").append(ConnectionCoreConstants.LINE_SEPARATOR); //$NON-NLS-1$ sb.append("default_realm = ").append(realm).append(ConnectionCoreConstants.LINE_SEPARATOR); //$NON-NLS-1$ sb.append("[realms]").append(ConnectionCoreConstants.LINE_SEPARATOR); //$NON-NLS-1$ sb.append(realm).append(" = {").append(ConnectionCoreConstants.LINE_SEPARATOR); //$NON-NLS-1$ sb.append("kdc = ").append(host).append(":").append(port).append( //$NON-NLS-1$ //$NON-NLS-2$ ConnectionCoreConstants.LINE_SEPARATOR); sb.append("}").append(ConnectionCoreConstants.LINE_SEPARATOR); //$NON-NLS-1$ try { FileUtils.writeStringToFile(configFile, sb.toString()); } catch (IOException ioe) { NamingException ne = new NamingException(); ne.setRootCause(ioe); throw ne; } System.setProperty("java.security.krb5.conf", configFile.getAbsolutePath()); //$NON-NLS-1$ } // Use our custom configuration so we don't need to mess with external configuration Configuration.setConfiguration(new InnerConfiguration(krb5LoginModule)); } // Gets the TGT, either from native ticket cache or obtain new from KDC LoginContext lc = null; try { lc = new LoginContext(this.getClass().getName(), new InnerCallbackHandler()); lc.login(); } catch (LoginException le) { NamingException ne = new NamingException(); ne.setRootCause(le); throw ne; } // Login to LDAP server, obtains a service ticket from KDC Subject.doAs(lc.getSubject(), (PrivilegedAction<Object>) () -> { try { context.reconnect(context.getConnectControls()); } catch (NamingException ne) { innerRunnable.namingException = ne; } return null; }); } finally { // delete temporary config file if (configFile != null && configFile.exists()) { configFile.delete(); } } }
From source file:org.apache.flume.source.jms.TestJMSSource.java
@Test(expected = FlumeException.class) public void testConfigureWithContextLookupThrowsException() throws Exception { when(initialConext.lookup(anyString())).thenThrow(new NamingException()); source.configure(context);/* w ww .jav a2 s . c o m*/ }
From source file:org.apache.flume.source.jms.TestJMSSource.java
@Test(expected = FlumeException.class) public void testConfigureWithContextCreateThrowsException() throws Exception { when(contextFactory.create(any(Properties.class))).thenThrow(new NamingException()); source.configure(context);// w w w . ja v a 2s. co m }
From source file:org.dmb.trueprice.utils.internal.InitContextListener.java
public static String getEnvEntryValue(String envEntryName) { if (prop == null) { loadProperties();/*w w w . j av a 2 s . co m*/ } String envEntryValue; try { envEntryValue = prop.getProperty(envEntryName); if (envEntryValue == null) { throw new NamingException(); } } catch (NamingException e) { throw new RuntimeException("cannot find env entry " + envEntryName, e); } return envEntryValue; }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Binds a name to an object, along with associated attributes. If attrs is null, the resulting binding will have the attributes associated with obj if obj is a * DirContext, and no attributes otherwise. If attrs is non-null, the resulting binding will have attrs as its attributes; any attributes associated with obj are * ignored.//from w ww . j ava 2 s . c om * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param attrs the attributes to associate with the binding * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if some "mandatory" attributes of the binding are not supplied * @exception NamingException if a naming exception is encountered */ @Override public void bind(String name, Object obj, Attributes attrs) throws NamingException { // Note: No custom attributes allowed VFSItem file = resolveFile(name); if (file != null) throw new NameAlreadyBoundException(smgr.getString("resources.alreadyBound", name)); int lastSlash = name.lastIndexOf('/'); if (lastSlash == -1) throw new NamingException(); String parent = name.substring(0, lastSlash); VFSItem folder = resolveFile(parent); if (folder == null || (!(folder instanceof VFSContainer))) throw new NamingException(smgr.getString("resources.bindFailed", name)); String newName = name.substring(lastSlash + 1); VFSLeaf childLeaf = ((VFSContainer) folder).createChildLeaf(newName); if (childLeaf == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); copyVFS(childLeaf, name, obj, attrs); VFSSecurityCallback callback = folder.getLocalSecurityCallback(); if (callback != null && callback.getSubscriptionContext() != null) { SubscriptionContext subContext = callback.getSubscriptionContext(); NotificationsManager.getInstance().markPublisherNews(subContext, null); } if (childLeaf instanceof MetaTagged) { MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo(); if (infos != null && infos.getAuthorIdentity() == null) { infos.setAuthor(userSession.getIdentity().getName()); infos.clearThumbnails(); infos.write(); } } // used by move operations if (obj instanceof VFSResource) { VFSResource vfsResource = (VFSResource) obj; if (vfsResource.vfsItem instanceof Versionable && ((Versionable) vfsResource.vfsItem).getVersions().isVersioned()) { Versionable currentVersion = (Versionable) vfsResource.vfsItem; VersionsManager.getInstance().move(currentVersion, childLeaf.getParentContainer()); } } }
From source file:org.olat.core.util.servlets.VFSDirContext.java
/** * Creates and binds a new context, along with associated attributes. This method creates a new subcontext with the given name, binds it in the target context (that * named by all but terminal atomic component of the name), and associates the supplied attributes with the newly created object. All intermediate and target contexts * must already exist. If attrs is null, this method is equivalent to Context.createSubcontext(). * // w w w .j a v a2 s . co m * @param name the name of the context to create; may not be empty * @param attrs the attributes to associate with the newly created context * @return the newly created context * @exception NameAlreadyBoundException if the name is already bound * @exception InvalidAttributesException if attrs does not contain all the mandatory attributes required for creation * @exception NamingException if a naming exception is encountered */ @Override public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { VFSItem file = resolveFile(name); if (file != null) throw new NameAlreadyBoundException(smgr.getString("resources.alreadyBound", name)); int lastSlash = name.lastIndexOf('/'); if (lastSlash == -1) throw new NamingException(); String parent = name.substring(0, lastSlash); VFSItem folder = resolveFile(parent); if (folder == null || (!(folder instanceof VFSContainer))) throw new NamingException(smgr.getString("resources.bindFailed", name)); String newName = name.substring(lastSlash + 1); VFSItem childContainer = ((VFSContainer) folder).createChildContainer(newName); if (childContainer == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); return (DirContext) lookup(name); }